← Linux and the Command Line Lesson 4 of 51 · 10 XP

cd and pwd — moving between folders

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

pwd (print working directory) shows where you are now. cd (change directory) moves you:

pwd                # /home/kai
cd /etc            # an absolute path — from the root /
cd projects/igd    # a relative one — from the current folder
cd ..              # one level up
cd ../..           # two levels up
cd                 # home (the same as cd ~)
cd -               # back to the previous folder

The Linux file system is a single tree with the root /. There are no C: and D: drives: everything, including flash drives, is "hung" somewhere in this tree.

path what's there
/home/name users' home folders (~)
/etc system settings
/bin, /usr/bin programs
/tmp temporary files
/var/log logs
/root the administrator's home folder

basename picks out the last part of a path: basename /home/kai/igd → igd.

Task. Create the nested folders a/b/c (mkdir -p a/b/c), go into c and print the name of the current folder with basename "$(pwd)". Then go up two levels and print the name of the current folder again.

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.