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

2023年 7月 11日 23.2k 0

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

1.命令格式

pwd [选项]

2.命令功能

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

3.常用参数

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

4.常用实例

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

pwd

Shell

执行和输出:

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

Shell

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

pwd

Shell

执行和输出:

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显示的是连接路径。

pwd -P

Shell

执行和输出:

[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

选项:

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

执行和输出:

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: 
General help using GNU software: 
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命令仍然显示那个目录

执行和输出:

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:~$

相关文章

服务器端口转发,带你了解服务器端口转发
服务器开放端口,服务器开放端口的步骤
产品推荐:7月受欢迎AI容器镜像来了,有Qwen系列大模型镜像
如何使用 WinGet 下载 Microsoft Store 应用
百度搜索:蓝易云 – 熟悉ubuntu apt-get命令详解
百度搜索:蓝易云 – 域名解析成功但ping不通解决方案

发布评论