Find your bearings in the file tree and travel from folder to folder with pwd, ls and cd.
Open this lesson in KodokonIn a file explorer you can always see where you are: the path shows at the top of the window and the folder contents are spread out in front of you. In a terminal, none of that is visible by default. And yet you are always somewhere: at every moment the shell sits in one specific folder, called the current folder or working directory. Three commands are enough to find your way: one to know where you are, one to see what is there, one to move. The first is pwd, for print working directory. It changes nothing, it simply answers the question "where am I?", and it is the reflex to have the moment you feel lost.
yoann@laptop:~$ pwd
/home/yoannThe second is ls, for list: it shows the contents of the current folder. On its own it gives a compact list of names. With the option -l (for long), it details each line: permissions, owner, size and modification date. With the option -a (for all), it also shows hidden files, meaning the ones whose name starts with a dot. An option goes after the command, preceded by a dash, and options can be combined: ls -la.
yoann@laptop:~$ ls
Desktop Documents Downloads Pictures
yoann@laptop:~$ ls -l
total 16
drwxr-xr-x 2 yoann yoann 4096 Jul 20 09:14 Desktop
drwxr-xr-x 5 yoann yoann 4096 Jul 21 18:02 Documents
drwxr-xr-x 3 yoann yoann 4096 Jul 19 11:47 Pictures
yoann@laptop:~$ ls -a
. .. .bashrc Desktop Documents Downloads PicturesThe third is cd, for change directory: it moves you. You give it the name of the folder to go to. Four shortcuts are worth learning by heart: cd .. goes up one level to the parent folder, cd ~ takes you straight back to your home folder, cd / leads to the root of the machine, and cd on its own does the same as cd ~. Note that a successful cd prints no message at all: in a terminal, silence means everything went fine.
yoann@laptop:~$ cd Documents
yoann@laptop:~/Documents$ pwd
/home/yoann/Documents
yoann@laptop:~/Documents$ cd ..
yoann@laptop:~$ cd ~
yoann@laptop:~$ pwd
/home/yoanncd .. do?cd Documents and the terminal prints nothing at all. What happened?