linuxcd命令介绍和案例使用

韵味老鸟 2024-08-30 13:29:27

linux cd命令介绍和案例使用

cd 命令是 Linux 系统中用于切换当前工作目录的基本命令

cd 命令介绍全称:Change Directory功能:用于改变或切换当前工作目录。适用版本:cd 命令在所有 Linux 发行版中均可使用,包括 Ubuntu、Debian、Fedora、CentOS 等。基本语法bashcd [选项] [目录]选项: -L:强制将符号链接视为实际目录(默认行为)。 -P:使用物理路径,而不是符号链接。 -e:如果指定的目录不存在,则报错并退出。目录参数: 可以是绝对路径或相对路径。 如果省略目录参数,则默认切换到用户的主目录(HOME)。特殊符号~:表示当前用户的主目录。..:表示当前目录的上一级目录。.:表示当前目录。-:切换到上一个工作目录。

命令指引:

root@meng:~# cd --help

cd: cd [-L|[-P [-e]] [-@]] [dir]

Change the shell working directory.

Change the current directory to DIR. The default DIR is the value of the

HOME shell variable.

The variable CDPATH defines the search path for the directory containing

DIR. Alternative directory names in CDPATH are separated by a colon (:).

A null directory name is the same as the current directory. If DIR begins

with a slash (/), then CDPATH is not used.

If the directory is not found, and the shell option `cdable_vars' is set,

the word is assumed to be a variable name. If that variable has a value,

its value is used for DIR.

Options:

-L force symbolic links to be followed: resolve symbolic

links in DIR after processing instances of `..'

-P use the physical directory structure without following

symbolic links: resolve symbolic links in DIR before

processing instances of `..'

-e if the -P option is supplied, and the current working

directory cannot be determined successfully, exit with

a non-zero status

-@ on systems that support it, present a file with extended

attributes as a directory containing the file attributes

The default is to follow symbolic links, as if `-L' were specified.

`..' is processed by removing the immediately previous pathname component

back to a slash or the beginning of DIR.

Exit Status:

Returns 0 if the directory is changed, and if $PWD is set successfully when

-P is used; non-zero otherwise.

命令案例:

root@meng:/var/jenkins_home# pwd

/var/jenkins_home

root@meng:/var/jenkins_home# cd -

/var

root@meng:/var# pwd

/var

root@meng:/var# cd .

root@meng:/var# cd ..

root@meng:/# pwd

/

root@meng:/# cd ~

root@meng:~# pwd

/root

root@meng:~#

0 阅读:0

韵味老鸟

简介:感谢大家的关注