语法

cd [-L|[-P [-e]]] [dir]
改变shell当前工作目录。仅对执行命令所在的shell有效。

参数

-L  按符号链接进入目录。

-P   按物理链接进入目录

-e    如果指定-P,且路径不存在,则返回-e后指定的退出码。

说明

cd =change directory

进入主目录。不带参数dir,就默认进入当前用户的主目录。等价命令还有 cd ~ 或 cd $HOME。

进入上一次切换前的工作目录。cd - 或 cd $OLDPWD。如果反复执行,则会在最后两次工作目录间来回切换。

cd的默认行为,等于cd <=> cd -L。如果路径中包含符号连接,则跟着符号链接走。

 CDPATH环境变量

CDPATH环境变量为cd 提供一组备选的当前目录。也就是说,如果你输入的不是/开头的绝对路径,则进入的目录的绝对路径是CDPATH中的目录+你的目录。举例来说,

架设你当前目录是/usr,myhome在你的/home下。

export CDPATH=/root:/home/:/etc

cd myhome

执行以上命令后,bash会依次将CDPATH中的目录+myhome来进入,最终进入到/home/myhome目录下。【CDPATH中多个路径下都有dir怎么办?】

进入你刚创建的目录

mkdir <dir> && cd $_

不论你创建的目录是否你当前工作目录下的,这个命令都能用。

创建只有一个下划线名字的目录

mkdir ./_

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 if the directory is changed, and if $PWD is set successfully when
-P is used; non-zero otherwise.

Linux命令:cd的更多相关文章

  1. 【Linux基础】常用Linux命令: cd, cp, ls, mkdir, mv, rm, su, uname

    常用Linux命令:cd, cp, ls, mkdir, mv, rm, su, uname cd命令:切换当前工作目录至 dirName(目录参数) 其中 dirName 可为绝对路径或相对路径.若 ...

  2. linux命令 --> cd命令

    关于linux的命令这里进行简单的说明一下(简单的说明哦!!) 对于linux和windows基本的操作就是切换目录,因为只有进入目录时,才能看到里面的内容(对于linux这说的不太准确必定还有ls呢 ...

  3. Linux 命令 - cd: 切换工作目录

    命令格式 cd [directory] 实例 a) 将工作目录切换成主目录. cd # 或 cd ~ b) 将工作目录切换成当前工作目录的父目录. cd .. c) 将工作目录切换成上一个的工作目录. ...

  4. 07.19 Linux命令 cd

    情景:在用compass编写sass,cd进入目录后,想退出, 解决: cd.. 回到上一层目录 cd\ 回到根目录 cd 进入具体目录

  5. WinSCP使用与linux命令(小部分命令)

    一.下载一个WinSCP WinSCP是一个Windows环境下使用SSH的开源图形化SFTP客户端.同时支持SCP协议.它的主要功能就是在本地与远程计算机间安全的复制文件..winscp也可以链接其 ...

  6. Linux命令详解之–cd命令

    cd命令是linux实际使用当中另一个非常重要的命令,本文就为大家介绍下Linux中cd命令的用法. 更多Linux命令详情请看:Linux命令速查手册 Linux cd命令用于切换当前工作目录至 d ...

  7. linux 命令随笔 ls cd pwd mkdir rm mv cp cat nl

    Linux 命令练习 ls命令 ls就是list的简写,目的是打印当前目录下的清单 格式 ls[选项][目录名] 常用参数 -a –all 列出目录下的所有文件,包括以 . 开头的隐含文件 -l 除了 ...

  8. 自学Linux Shell3.2-切换目录命令cd

    点击返回 自学Linux命令行与Shell脚本之路 3.2-切换目录命令cd 当登录系统并获得shell命令提示符后,你通常位于自己的主目录中. 使用pwd命令验证: pwd命令以绝对路径的方式显示用 ...

  9. 每天一个linux命令(3):cd命令

    版权声明 更新:2017-04-27博主:LuckyAlan联系:liuwenvip163@163.com声明:吃水不忘挖井人,转载请注明出处! 1 文章介绍 本文介绍了Linux下命令cd. 2 开 ...

随机推荐

  1. thinkPHP 分页样式增加下拉列表

    $linkPage="  <select name='sldd' style='width:40px;height:30px;border:1px red block;' onchan ...

  2. 剑指Offer 21. 栈的压入、弹出序列 (栈)

    题目描述 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否可能为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压 ...

  3. GANs的回顾

    GANs第一篇比较熟悉,不介绍.看看变种. 1) LAPGANs:金字塔,逐步优化生成图片(Deep Generative Image Models using Lapalacian Pyramid ...

  4. Windows下 安装Jenkins 并发布至docker 实战

    网上的教程基本都是Linux系统下安装Jenkins,并且发布到Linux系统下的docker中, 于是打算在全部windows的环境中,完成Jenkins的持续集成功能. 环境: 服务器环境: wi ...

  5. 编写简单的windows桌面计算器程序

    编译环境:VS2017 主文件为: #include "stdafx.h" #include "WindowsProject5.h" #include &quo ...

  6. Linux下设置redis的密码和远程访问

    编辑vi /etc/redis/redis.conf ,有的是vi /etc/redis.conf ,在68行修改:bind 127.0.0.1 ::1 为 bind 0.0.0.0 ::1,这样就可 ...

  7. springMVC---业务处理流程图和最简单的springMvc搭建截图说明

    一.springMVC业务处理流程图: 二.如何搭建springMvc框架 1.建立web工程 2.引入jar包 3.创建web.xml文件 4.创建springMvc-servlet.xml文件 5 ...

  8. listagg乱码问题

    listagg(to_char(ts.tsmc),',') within GROUP (order by  xs.xh) ,先将字段to_char 以后,就可以解决

  9. mysql查询中AND与OR注意事项

    在查询的where条件中,and要优于or 如果要改变优先级, 需要在最小逻辑判断的条件外加括号(),例如: select * from `table_name` where (`type` = 1 ...

  10. 开机自启动 centos 7

    开机自启动,写入必要的命令即可.vim /etc/rc.d/rc.local