linux 命令回到初始,【整理】详解Linux中的切换路径命令:cd

Linux中的cd命令

cd==change directory==切换目录

Linux中用cd命令来切换路径

cd命令的语法

cd的语法,可参见:

CLi@PC-CLI-1 ~/develop/docbook

$ help cd

cd: cd [-L|-P] [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

-P use the physical directory structure without following symbolic

links

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

Exit Status:

Returns 0 if the directory is changed; non-zero otherwise.

从其解释中,我们可以知道:

如果没有给cd参数的话,默认就是使用HOME环境变量当参数

即:

如果没有给cd参数的话,则等价于:cd $HOME

而由于:

所以:cd

== cd $HOME

== cd ~

假设当前用户是:CLi

那么又等价于:cd /home/CLi

即:cd

== cd $HOME

== cd ~

== cd /home/CLi

cd加上减号表示切换到前一次的路径/目录

cd,加上减号’-‘作为参数的话,表示:

切换到上一次,前一次,所在的目录。

举例:CLi@PC-CLI-1 ~/develop/docbook

$ pwd

/home/CLi/develop/docbook

CLi@PC-CLI-1 ~/develop/docbook

$ cd tools/

CLi@PC-CLI-1 ~/develop/docbook/tools

$ pwd

/home/CLi/develop/docbook/tools

CLi@PC-CLI-1 ~/develop/docbook/tools

$ cd -

/home/CLi/develop/docbook

如图:

d64d7fac808dd86eb888f7a3b2375ad5.png

总结

cd命令,用好了,也可以提高工作效率。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值