cd
The cd
command in Linux is a fundamental command line utility used for navigating the filesystem. It stands for "change directory." By using cd
, you can move around different directories (folders) in the filesystem from the terminal. Here are some key aspects of the cd
command:
Basic Usage: To move into a specific directory, you type
cd
followed by the path to the directory. For example,cd /path/to/directory
will change your current directory to/path/to/directory
.Home Directory: Just typing
cd
without any arguments takes you to your home directory. The home directory is also represented by~
. So,cd ~
has the same effect.Relative and Absolute Paths:
cd
can be used with both relative and absolute paths. An absolute path starts from the root directory (e.g.,/usr/local/bin
), while a relative path starts from the current directory (e.g.,documents/projects
).Parent Directory:
cd ..
moves you up one level to the parent directory of the current directory.Previous Directory:
cd -
switches you to the last directory you were in. This is useful for toggling back and forth between two directories.Tab Completion: When typing a directory path in the terminal, you can use the Tab key for auto-completing the directory names, which saves time and reduces typing errors.
Navigating Spaces in Directory Names: If a directory name contains spaces, you either need to escape the spaces with a backslash (e.g.,
cd My\ Documents
) or enclose the entire path in quotes (e.g.,cd "My Documents"
).Case Sensitivity: Remember that Linux is case-sensitive. So,
Documents
anddocuments
are considered different directories.Symbolic Links: When you change directories into a symbolic link, you are moved into the location that the link points to.
No Command Output: Normally,
cd
doesn’t produce any output. It silently changes the directory and updates the shell's current directory. You can verify the change with thepwd
command.
Last updated