Linux cd Command

Linux 命令大全Linux Command Encyclopedia

The Linux cd command (full English name: change directory) is used to change the current working directory and switch to the specified path.

If the directory name is omitted, it changes to the user's home directory (i.e., the directory you were in when you just logged in).

In addition,~Also means the home directory,.Indicates the current directory,..Indicates the parent directory of the current directory location.

Syntax

cd [dirName]
  • dirName: The target directory to switch to, which can be a relative path or an absolute path.

Switch to an absolute path:Specify the complete 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

Examples

Switch to the /usr/bin/ directory:

cd /usr/bin

Switch to the parent directory:Use..Indicates the parent directory. You can use it multiple times consecutively..To switch to higher-level directories.

cd ..
cd ../../   // 切换到上上级目录

Switch to the user's home directory:Use~Indicates the current user's home directory. You can use the cd command to switch directly to the home directory.

cd ~

Switch to the last visited directory:Usecd -To switch to the last visited directory.

cd -

Switch to the directory specified by an environment variable:You can use an environment variable to specify the target directory, and use thecdCommand to switch to that directory.

cd $VAR_NAME

The examples above are some basic uses of the cd command. They can help you perform directory switching operations in the Linux system.

Use thecd --helpCommand to get more detailed information about the cd command, including available options and more advanced usage.

Linux 命令大全Linux Command Encyclopedia

Other Extensions