Skip to content

Using Directories

Finding Current Directory

First, we need to figure out what directory we are currently in. To do so, use the pwd (present working directory) command:

% pwd
/home/Osiris

This home directory has a special key, the ~. It can be used as a substitute for the above.

% cd /~/Osiris
$ pwd
/home/Osiris

Viewing Directory Contents

To see what is in the directory you're currently in, use the ls command:

% ls
Documents Downloads Music

To get more information, we can add a flag to this command. Add the -l (long) flag. To see more flags, use man ls to read the manual.

% ls -l
total 0
drwx------@  27 Osiris  staff   864 11 May 12:53 Desktop
drwx------@  37 Osiris  staff  1184 12 May 16:55 Documents
drwx------+  12 Osiris  staff   384  6 Oct  2021 Music

We can also look inside a directory by adding an argument to ls.

% ls -l Documents
total 0
-rw-r--r-- 1 Osiris staff   32 Aug 27 11:34  cool-stuff.py

Special Directory Keys

You can also call files relative to home using the ~ key, e.g. ls ~/Downloads.

Three more special keys exist, which are ., .., and -.

The first two allow you to move relative to the current directory; if you were currently in ~/Documents/my_stuff/things/ and trying to access ~/Documents/my_stuff/things/file1.py, you could simply write ./file1.py. Similarly, if the file was in the directory above, i.e. ~/Documents/my_stuff/file2.py, we can write ../file2.py. These are useful when you want to execute scripts. Finally, the - key allows us to navigate back to our previous directory.

% pwd
/home/Osiris/Documents

% cd ../Music

% pwd
/home/Osiris/Music

% cd -

% pwd
/home/Osiris/Documents

Creating Directory

This action is the same as the "New Folder" action when using a file browser in common operating systems.

% mkdir new

% ls
cool-stuff.py new/