Moving Around with cd

cd: change directory

cd moves you into another directory. Watch how the prompt changes to show where you are:

cd Documents
pwd
ls

In 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 ../..
pwd

In 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
pwd

In 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 /
ls

In 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
CommandGoes to
cd folderfolder, 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: cd only works with directories. cd todo.txt fails with Not a directory. To look inside a file you'll use cat (module 4).

Tip: Use Tab with cd. Type cd Doc and press Tab.

HOME LEARN COMMUNITY DASHBOARD
Practice terminal Starting…