pwd and cd
pwd prints your current folder and cd moves you to another one.
Syntax
cd [directory]
pwdIn Linux everything is organised into folders (called directories). At any moment your shell sits inside one directory, known as the current working directory.
pwd — print working directory
pwd tells you exactly where you are.
cd — change directory
cd moves you to a different directory. A few handy shortcuts:
cd /etc— go to a specific directory.cd ..— go up one level to the parent.cd ~or justcd— go to your home directory.cd -— go back to the directory you were just in.
Example
pwd
# Output: /home/alice
cd /var/log
pwd
# Output: /var/log
cd ..
pwd
# Output: /var
cd # back to home
pwd
# Output: /home/aliceWhen to use it
- A sysadmin scripts a deployment that calls 'pwd' at each stage to log the working directory for audit trails.
- A developer uses 'cd -' to toggle quickly between a source directory and a build output directory.
- A new Linux user runs 'cd ~' to return to their home directory after accidentally navigating deep into /etc.
More examples
Print and navigate directories
Shows 'pwd' reporting the current directory before and after a 'cd' to an absolute path.
pwd
# /home/alice
cd /var/log
pwd
# /var/logNavigate with relative paths
Uses relative paths and the parent-directory shortcut '..' to move without typing full paths.
cd /var/log
cd nginx # go into subdirectory
pwd
# /var/log/nginx
cd .. # go up one level
pwd
# /var/logToggle between two directories
Demonstrates 'cd -' which alternates between the current and previous directory like a back button.
cd ~/projects/api
cd /var/log
cd - # jump back to ~/projects/api
# /home/alice/projects/api
cd - # back to /var/log
# /var/log
Discussion