This is an archived version of the course. Please find the latest version of the course on the main webpage.

Chapter 2: Commands

Basic Commands

face Harry Coppock

Here are some of the fundamental commands you need to know to use shell.

  • pwd prints the working directory (stands for ‘print working directory’). Specifically it prints out the abosolute path to the current working directory.
  • ls lists files and directories in the working directory
  • cd changes the working directory:
    • cd .. moves up one directory
    • cd ~ moves to your home directory
    • cd (without any argument) functions as cd ~
    • cd ../../someDirectory moves up two directories and then into someDirectory

You can cd to absolute pathnames. An absolute path begins with the root directory and follows the tree branches until the destination is reached. To find the absolute path of the working directory simply type pwd.

In contrast, relative pathnames start from the working directory.

When typing a filename into the shell, once you have typed enough characters to uniquely select a single file, press the Tab key and the shell will complete the filename for you. If there are several alternatives, Ctrl+D will list all the matching files and then it will redisplay the partial command line.

If the file name has spaces, you need to escape them with backslash. For example, to move to the directory “~/This Directory”, you can use the following command:

cd ~/This\ Directory

Exercise:

Type the following commands and check them out:

cd /usr/bin
pwd
ls

Exercise:

Change the working directory from /user/bin/ to /user/ using (1) relative paths and (2) using absolute paths.