linux命令大全:pwd(显示当前目录在文件系统内确切位置)

2019-02-0919:07:46服务器及运维Comments4,304 views字数 2060阅读模式

Linux中用 pwd 命令来查看”当前工作目录“的完整路径。简单得说,每当我们在终端进行操作时,都会有一个当前工作目录。
在不太确定当前位置时,就会使用pwd来显示当前目录在文件系统内的确切位置。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9508.html

1.命令格式

pwd [选项]文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9508.html

2.命令功能

查看”当前工作目录“的完整路径文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9508.html

3.常用参数

一般情况下不带任何参数,但如果目录是链接时:
格式:pwd -P 显示出实际路径,而非使用连接(link)路径。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9508.html

4.常用实例

实例1:用 pwd 命令查看默认工作目录的完整路径

pwd
Shell

执行和输出:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9508.html

yiibai@ubuntu:~$ pwd
/home/yiibai
yiibai@ubuntu:~$
Shell

实例2:使用 pwd 命令查看指定文件夹

pwd
Shell

执行和输出:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9508.html

yiibai@ubuntu:~$ cd /usr/local/src/
yiibai@ubuntu:/usr/local/src$ pwd
/usr/local/src
yiibai@ubuntu:/usr/local/src$
Shell

实例3:pwd -P

目录连接链接时,pwd -P 显示出实际路径,而非使用连接(link)路径;pwd显示的是连接路径。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9508.html

pwd -P
Shell

执行和输出:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9508.html

[root@localhost ~]# cd /etc/init.d 
[root@localhost init.d]# pwd
/etc/init.d
[root@localhost init.d]# pwd -P
/etc/rc.d/init.d
[root@localhost init.d]#
Shell

实例4:/bin/pwd

/bin/pwd [选项]
Shell

选项:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9508.html

  • -L 目录连接链接时,输出连接路径
  • -P 输出物理路径

执行和输出:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9508.html

yiibai@ubuntu:/etc/init.d$ /bin/pwd
/etc/init.d
yiibai@ubuntu:/etc/init.d$ /bin/pwd --help
Usage: /bin/pwd [OPTION]...
Print the full filename of the current working directory.

  -L, --logical   use PWD from environment, even if it contains symlinks
  -P, --physical  avoid all symlinks
      --help     display this help and exit
      --version  output version information and exit

NOTE: your shell may have its own version of pwd, which usually supersedes
the version described here.  Please refer to your shell's documentation
for details about the options it supports.

Report pwd bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'pwd invocation'
yiibai@ubuntu:/etc/init.d$ /bin/pwd -P
/etc/init.d
yiibai@ubuntu:/etc/init.d$ /bin/pwd -L
/etc/init.d
yiibai@ubuntu:/etc/init.d$
Shell

实例5:当前目录被删除了,而pwd命令仍然显示那个目录

执行和输出:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9508.html

yiibai@ubuntu:/etc/init.d$ cd /usr/local/src/
yiibai@ubuntu:/usr/local/src$ mkdir beremoved
yiibai@ubuntu:/usr/local/src$ cd beremoved/
yiibai@ubuntu:/usr/local/src/beremoved$ pwd
/usr/local/src/beremoved
yiibai@ubuntu:/usr/local/src/beremoved$ rm ../beremoved/ -rf
yiibai@ubuntu:/usr/local/src/beremoved$ pwd
/usr/local/src/beremoved
yiibai@ubuntu:/usr/local/src/beremoved$ /bin/pwd
/bin/pwd: couldn't find directory entry in ‘..’ with matching i-node
yiibai@ubuntu:/usr/local/src/beremoved$ cd
yiibai@ubuntu:~$ pwd
/home/yiibai
yiibai@ubuntu:~$
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9508.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/yunwei/9508.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定