pwd命令

时间:2023-03-08 16:47:55

【pwd】      打印当前的工作目录             pwd==print work director

命令格式:

pwd [OPTION]...

命令功能:

打印当前工作目录的全路径

命令参数:

-L, --logical               目录连接链接时,输出连接路径

-P, --physical            输出物理路径

命令实例:

实例1:查看当前路径

命令:

pwd

输出:

[root@localhost ~]# pwd

/root

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

命令:pwd -P

输出:

[root@localhost init.d]# pwd

/etc/init.d

[root@localhost init.d]# pwd -P

/etc/rc.d/init.d

[root@localhost init.d]# ll

lrwxrwxrwx.  1 root root     11 Jul  5 09:38 init.d -> rc.d/init.d

实例3:/bin/pwd

输出:

[root@localhost init.d]# /bin/pwd

/etc/rc.d/init.d

[root@localhost init.d]# /bin/pwd -P

/etc/rc.d/init.d

[root@localhost init.d]# /bin/pwd -L

/etc/init.d

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

命令:

pwd /bin/pwd

输出:

[root@localhost hello]# pwd

/nihao/hello

[root@localhost hello]# /bin/pwd

/nihao/hello

[root@localhost hello]# rm -rf ../hello/

[root@localhost hello]# pwd

/nihao/hello

[root@localhost hello]# /bin/pwd

/bin/pwd: couldn't find directory entry in `..' with matching i-node