Linux文件目录操作命令-pwd命令

一、pwd命令

Linux中用 pwd 命令来查看”当前工作目录“的完整路径。简单得说,每当我们在终端进行操作时,都会有一个当前工作目录。
在不太确定当前位置时,就会使用pwd来显示当前目录在文件系统内的确切位置。

1.命令格式

pwd [选项]

2.命令功能

查看”当前工作目录“的完整路径

3.常用参数

一般情况下不带任何参数,但如果目录是链接时:
格式:pwd -P 显示出实际路径,而非使用连接(link)路径。

4.常用实例

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

pwd

执行和输出:

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

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

pwd

执行和输出:

tianyuanmengniu@ubuntu:~$ cd /usr/local/src/
tianyuanmengniu@ubuntu:/usr/local/src$ pwd
/usr/local/src
tianyuanmengniu@ubuntu:/usr/local/src$

实例3:pwd -P

目录连接链接时,pwd -P 显示出实际路径,而非使用连接(link)路径;pwd显示的是连接路径。

pwd -P

执行和输出:

[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]#

实例4:/bin/pwd

/bin/pwd [选项]

选项:

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

执行和输出:

tianyuanmengniu@ubuntu:/etc/init.d$ /bin/pwd
/etc/init.d
tianyuanmengniu@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'
tianyuanmengniu@ubuntu:/etc/init.d$ /bin/pwd -P
/etc/init.d
tianyuanmengniu@ubuntu:/etc/init.d$ /bin/pwd -L
/etc/init.d
tianyuanmengniu@ubuntu:/etc/init.d$

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

执行和输出:

tianyuanmengniu@ubuntu:/etc/init.d$ cd /usr/local/src/
tianyuanmengniu@ubuntu:/usr/local/src$ mkdir beremoved
tianyuanmengniu@ubuntu:/usr/local/src$ cd beremoved/
tianyuanmengniu@ubuntu:/usr/local/src/beremoved$ pwd
/usr/local/src/beremoved
tianyuanmengniu@ubuntu:/usr/local/src/beremoved$ rm ../beremoved/ -rf
tianyuanmengniu@ubuntu:/usr/local/src/beremoved$ pwd
/usr/local/src/beremoved
tianyuanmengniu@ubuntu:/usr/local/src/beremoved$ /bin/pwd
/bin/pwd: couldn't find directory entry in ‘..’ with matching i-node
tianyuanmengniu@ubuntu:/usr/local/src/beremoved$ cd
tianyuanmengniu@ubuntu:~$ pwd
/home/yiibai
tianyuanmengniu@ubuntu:~$

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值