Linux cd Command
The Linux cd (short for change directory) command is used to change the current working directory, switching to the specified path.
If the directory name is omitted, it switches to the user's home directory (the directory you are in right after logging in).
In addition, ~ also represents the home directory, . represents the current directory, and .. represents the parent directory of the current location.
Syntax
cd [dirName]
- dirName: the target directory to switch to, which can be a relative or absolute path.
** Switch to an absolute path:** Specify the full directory path to switch to the target directory.
cd /path/to/directory
** Switch to a relative path:** Specify a path relative to the current directory to switch to the target directory.
cd relative/path/to/directory
Example
Switch to the /usr/bin/ directory:
cd /usr/bin
** Switch to the parent directory:** Use .. to represent the parent directory; you can use .. multiple times in a row to move up several levels.
cd ..
cd ../../ // 切换到上上级目录
** Switch to the user's home directory:** Use ~ to represent the current user's home directory; you can use the cd command to switch directly to it.
cd ~
** Switch to the previous directory:** Use cd - to switch to the directory you visited last.
cd -
** Switch to a directory specified by an environment variable:** You can use an environment variable to specify the target directory and use the cd command to switch to it.
cd $VAR_NAME
The examples above are some basic uses of the cd command; they can help you perform directory navigation in Linux.
Use the cd --help command to get more detailed information about cd, including available options and more advanced usage.
Linux Command Reference