Linux 基础知识整理(四)

2023-12-13 07:17:36

Linux的常用命令 - cd命令

cd 命令是 Linux 系统中用于切换工作目录的命令,它是“change directory”的缩写。

Linux命令 - cd—LZL在线工具

cd? ? ? ? ?# 进入用户主目录;
cd ~? ? ? # 进入用户主目录;
cd -? ? ? ?# 返回进入此目录之前所在的目录;
cd ..? ? ? # 返回上级目录(若当前目录为“/“,则执行完后还在“/";".."为上级目录的意思);
cd ../..? ?# 返回上两级目录;
cd !$? ? ?# 把上个命令的参数作为cd参数使用。?

利用 help 命令查询 cd 的命令:

[root@icoolkj ~]# help cd
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
        -P      use the physical directory structure without following symbolic
        links
        -e      if the -P option is supplied, and the current working directory
        cannot be determined successfully, exit with a non-zero status
    
    The default is to follow symbolic links, as if `-L' were specified.
    
    Exit Status:
    Returns 0 if the directory is changed, and if $PWD is set successfully when
    -P is used; non-zero otherwise.
[root@icoolkj ~]# 
  • 将当前目录更改为“/usr/local”?

[root@icoolkj ~]# cd /usr/local/
[root@icoolkj local]#?

  • ?使用绝对路径将当前目录更改为“/usr/local/lib”

[root@icoolkj local]# cd /usr/local/lib
[root@icoolkj lib]#

  • 使用相对路径将当前工作目录更改为“/usr/local/lib”

[root@icoolkj local]# cd lib
[root@icoolkj lib]#?

  • 切换回先前工作的目录?

?[root@icoolkj lib]# cd -
/usr/local
[root@icoolkj local]#?

  • 切换到上一级目录

[root@icoolkj lib]# cd ..
[root@icoolkj local]#??

  • ?切换到上上一级目录

[root@icoolkj lib]# cd ../../
[root@icoolkj usr]#?

  • 从当前目录移动到用户的主目录?

[root@icoolkj local]# cd ~
[root@icoolkj ~]# cd /usr/local/
[root@icoolkj local]# cd
[root@icoolkj ~]#?

文章来源:https://blog.csdn.net/qq_29768197/article/details/134837084
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。