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:
This home
directory has a special key, the ~
. It can be used as a substitute for the above.
Viewing Directory Contents¶
To see what is in the directory you're currently in, use the ls
command:
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
.
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.