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.

And we said we would use the terminal in Jupyter Lab, so let us open a terminal (another one!) and type jupyter lab. If you do not have Jupyter Lab installed, just use your normal terminal and install it after the class. Once Jupyter Lab opens in your browser you can open File -> New -> Terminal.

pwd and ls

When the shell is ready for your input it will display a $ at the beginning of the line, which means that you are a normal user (not an admin) and the terminal is ready. 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

It’s important to know that you can either specify the full path (beginning with your home directory) to the directory you want to navigate to or you can enter the relative path starting from your current directory.

HINT: if you have changed directory and need to come back to where you were before, you can just type:

cd -

This will get you back to the previous directory quickly and without specifying the path.

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 rec01:

mkdir rec01

You now have an empty directory called rec01. 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 rec01

Copyright note: In addition to the copyright shown below, this recitation was developed based on materials from Axel Müller.