What is cd
?
The cd
command stands for “change directory”. It allows you to navigate through the filesystem in the Linux terminal.
Syntax
-
directory_path
: The target directory you want to switch to.
Step-by-Step Usage
Step 1: Navigate to a Directory
Goes from the current directory to Documents
.
Step 2: Move to Parent Directory (..
)
Moves up one level in the directory tree.
Example:
-
/home/user/Documents
→/home/user
Step 3: Move to Home Directory (~
or just cd
)
or simply:
Takes you to your home directory (/home/yourusername
)
Step 4: Go to Root Directory (/
)
Moves to the root directory (the top of the file system tree)
Step 5: Move to a Full/Absolute Path
Directly jumps to /etc/apache2
, regardless of where you are.
Step 6: Move to a Relative Path
Navigates relative to your current location.
Step 7: Go Back to Previous Directory (-
)
Switches back to the last directory you were in.
Example:
-
From
/home/user
to/etc
, then:-
cd -
→ goes back to/home/user
-
Step 8: Handle Spaces in Directory Names
or
Use quotes or backslash (\
) to escape spaces.
Step 9: Tab Autocomplete
While typing:
Pressing Tab
auto-completes folder names like Documents
.
Summary of Useful cd
Commands
Command | Description |
---|---|
cd | Go to home directory |
cd .. | Go up one level |
cd / | Go to root directory |
cd - | Switch to the previous directory |
cd ~ | Shortcut to home directory |
cd ./folder | Move to subfolder in current directory |
cd ../.. | Move up two levels |
cd /path/to/dir | Move to specific absolute path |
Pro Tips
-
Use
pwd
to print the current directory: -
Combine with
ls
to see contents before navigating:
Example Workflow
Let me know if you'd like this in cheat sheet format, with visual diagrams, or as a script to practice!