Maneuvering directories (i.e. folders)¶
To get some practice with the command line, we will use an example directory with some files in it. You can download a ZIP file containing the directory here.
pwd and ls¶
Let’s start out by using the pwd
command to figure out what directory we’re in.
pwd
pwd
tells you the path of your current directory. A path for a directory or file is the list of all its parent directories, separated by slashes (/
), up to the root directory signified by the initial /
. You are probably in your home directory.
To list all files and folders in the current directory, we employ the ls
command.
ls
cd: change directory¶
Let’s make sure we are in the home directory:
cd
Use pwd
to check where you are now. Invoking the cd
command without specifying a target directory defaults to the home directory. Another way to specify your home directory is by its shortcut, ~/
. In general, the tilde-slash means “home directory.”
From here, let’s navigate to the ‘command_line_recitation’ directory:
cd command_line_recitation
Note, that depending on where you saved this directory, you may have to do some additional navigation to get to it. For example, anything I download defaults to the Downloads
directory, so I would navigate by
cd Downloads/command_line_recitation
mkdir and rmdir¶
To make a directory, the command is mkdir
, hence the name make directory. followed by the name of the directory you want to create. For example, to make a directory called rec0
:
mkdir rec0
You now have an empty directory called rec0
. You can see it if you list the contents of the directory.
ls
We do not need (nor want) this directory, since this is just for practice, so let’s delete it. To delete an empty directory, the command is rmdir
.
rmdir rec0
Copyright note: In addition to the copyright shown below, this recitation was developed based on materials from Axel Müller.