The cd
(change directory) command is used to navigate between directories in a Linux filesystem.
-
Syntax:
cd [directory]
-
Examples:
cd /home/user/documents
- Changes the current directory to
/home/user/documents
.
cd ..
- Moves up one directory level (to the parent directory).
cd ~
- Changes to the home directory of the current user.
cd -
- Switches to the previous directory you were in.
cd /
- Changes to the root directory.
- Changes the current directory to
The cd
command itself doesn’t have options, but it works with special characters:
-
.
(dot):- Refers to the current directory.
cd .
- No change in directory; stays in the current directory.
-
..
(double dot):- Refers to the parent directory.
cd ..
- Moves to the parent directory.
-
~
(tilde):- Represents the home directory of the current user.
cd ~
- Moves to the home directory.
-
-
(dash):- Switches to the previous directory.
cd -
-
No Argument (
cd
):- Running
cd
without any arguments takes you directly to your home directory:
cd
- Running
-
Absolute vs. Relative Path:
-
You can use absolute paths (starting from
/
) or relative paths (starting from the current directory) withcd
.cd /usr/local/bin # Absolute path cd ../bin # Relative path
-