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.
-
Display the current working directory with
pwd
(print working directory):pwd
-
List the contents of a directory:
ls /
ls /usr
ls -l /usr
-
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 (/
). -
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
-
Use a relative path:
cd bin
pwd
The directory
bin
is relative to the current one (in this case/usr
). -
Go to the previous current directory:
cd /var/log
cd -
cd -
-
Go to the home directory:
cd
cd ~
The tilde (
~
) represents the home directory of the current user.