cd: change directory
cd moves you into another directory. Watch how the prompt changes to show where you are:
cd Documents
pwd
lsIn the terminal
student@vulntech:~$ cd Documents student@vulntech:~/Documents$ pwd /home/student/Documents student@vulntech:~/Documents$ ls school work
Going up with ..
.. means the directory above (the parent). cd .. moves one level up:
cd Documents/work
pwd
cd ..
pwd
cd ../..
pwdIn the terminal
student@vulntech:~$ cd Documents/work student@vulntech:~/Documents/work$ pwd /home/student/Documents/work student@vulntech:~/Documents/work$ cd .. student@vulntech:~/Documents$ pwd /home/student/Documents student@vulntech:~/Documents$ cd ../.. student@vulntech:/home$ pwd /home
../.. goes up two levels at once.
Going home
cd on its own, or cd ~, takes you straight home from anywhere:
cd /etc
pwd
cd
pwdIn the terminal
student@vulntech:~$ cd /etc student@vulntech:/etc$ pwd /etc student@vulntech:/etc$ cd student@vulntech:~$ pwd /home/student
Going back
cd - jumps back to the directory you were in before, like a Back button. It prints where it took you:
cd /var/log
cd /tmp
cd -In the terminal
student@vulntech:~$ cd /var/log student@vulntech:/var/log$ cd /tmp student@vulntech:/tmp$ cd - /var/log
Jumping to the root
cd /
lsIn the terminal
student@vulntech:~$ cd / student@vulntech:/$ ls bin dev home media opt root sbin sys usr boot etc lib mnt proc run srv tmp var
| Command | Goes to |
|---|---|
cd folder | folder, inside the working directory |
cd .. | One level up |
cd or cd ~ | Your home directory |
cd - | The previous directory |
cd / | The root of the tree |
Common mistake:
cdonly works with directories.cd todo.txtfails with Not a directory. To look inside a file you'll usecat(module 4).
Tip: Use Tab with
cd. Typecd Docand press Tab.