File Basics

Use this post as a guide, to learn basic file commands.

List Files

  • Use ls to just list file:
1ls
  • Use long listing (ls -l) to do the same.
  • List a specific file (let's say you have a file called "mydata"):
1ls mydata
  • Long list that file:
1ls -l mydata
  • List a directory that is not the current directory:
1ls /tmp

Create Files (using the touch command)

  • Create a file using the touch command, eg:
1touch myfile
  • Use ls long listing to look at the last update time of the file.
    Then touch the file again and see the result.
    Didn't work?
    Maybe you should have waited a minute.

Create a Directory

  • Try the mkdir command with the following:
  • Create a directory under the current directory
  • Create a directory under /tmp

Remove Files and Directories

  • Remove a file with rm
  • Remove an empty directory with rm
  • Try the same on a non-empty directory
  • DANGER DANGER DANGER...
    Remove a non-empty directory recursively:
1rm -r my-non-empty-dir

Copy files using cp

  • Copy a file with cp
  • Try to copy a directory in the same way
  • How would you solve it?

Move or rename files with mv

  • Rename a file with mv
    (e.g rename myfile to myfile1)
  • Move a file into a directory