2. Moving around the file system¶
ls¶
Let’s move on to something useful… ls will list the contents of the directory you’re currently in. Find out what command line switches it supports. Our favourites are -a -l -t -r -h -S -1
and -o
.
Several switches can be combined behind one -
like this:
$ ls -lrt
The argument --color
is a very
useful thing to have enabled by default (see aliases, later.)
pwd¶
Use pwd to find out which directory you’re currently looking at. On UNIX systems, the full path to a file starts from the root directory /, followed by the nested directories up to the one the file lives in. Paths will work with any command whenever a filename is expected.
cd¶
Moving between directories is done with cd followed by a directory name. Some names are special:
- ~ is your home directory
- . is the current directory
- .. is the parent directory (one step closer to /)
You can use these anywhere inside a path, but they’re of course most useful at the beginning of the path.
Now move around your file system. Keep track of where you are with pwd and use ls to see what files are here.
Another shortcut, cd -
, takes you back to the previous directory you were in. Why is this not the same as cd ..
?
What happens when you type cd
without an argument?
mkdir¶
You can create new directories with mkdir followed by the name of the directory to create. The following exercises are best done in a new directory, so we will create one in your home directory and cmd{cd} into it:
$ cd ~
$ mkdir NewDirectoryThatWillBeUsedForTheExercises
$ cd NewDirectoryThatWillBeUsedForTheExercises
Other names are fine, too, of course. This is a good time to explore tab completion — try typing some starting characters of a command or file you know to exist, then press the tab key (maybe twice). bash will fill in the rest of the name if possible.