Skip to main content

2. Navigation

The command cd (change directory) is used to move from one directory to another. The command pwd (print working directory) shows the current location. The command ls (list) shows the content of the current working directory.

  1. Display the current working directory with pwd (print working directory):

    pwd
  2. List the contents of a directory:

    ls /
    ls /usr
    ls -l /usr
  3. Change the current working directory:

    cd /usr
    pwd
    ls
    cd /usr/bin
    pwd

    The path /usr/bin is called absolute, since it shows the full path, starting from the root (/).

  4. Go to the directory one level up:

    cd ..
    pwd

    Two dots (..) represent the parent of the current directory.

    By the way, a single dot (.) represents the current directory:

    cd .
    pwd
  5. Use a relative path:

    cd bin
    pwd

    The directory bin is relative to the current one (in this case /usr).

  6. Go to the previous current directory:

    cd /var/log
    cd -
    cd -
  7. Go to the home directory:

    cd
    cd ~

    The tilde (~) represents the home directory of the current user.

Loading asciinema cast...