0%

查看目录命令pwd

查看目录命令pwd

pwd命令的作用是查看当前目录,没有参数,输入后回车即可显示当前绝对路径。

官方定义为:

pwd - print name of current/working directory

所以pwdPrint Working Directory第一个字的缩写。

唯二需要了解的参数如下:

  • -L, --logical:打印逻辑路径,与pwd一致
  • -P, --physical:打印物理路径,这里可以从超级链接直达原处

实例展示

此时比如我们进入一个目录,然后在打印出来,如下:

1
2
3
4
$ cd /etc/sysconfig/network-scripts/

$ pwd
/etc/sysconfig/network-scripts

可以看到pwd将输出完全路径

逻辑与物理路径

比如如下:

1
2
3
4
5
6
7
$ pwd
/opt/test

$ ls -l
总用量 1
lrwxrwxrwx 1 root root 14 Jan 15 2012 dir -> source/dir
drwxrwxrwx 1 root root 14 Jan 15 2012 source

可以看到此时的路径在/opt/test/里面有两个目录sourcedir,其中dir链接到source里面的dir。

接下来对比一下-L和-P的区别。

1
2
3
4
5
6
7
8
9
10
$ cd dir

$ pwd
/opt/test/dir

$ pwd -L
/opt/test/dir

$ pwd -P
/opt/test/source/dir

从上面的输出可以发现,-P参数会显示文件最原始的路径;而-L则是逻辑上的路径。

处无为之事,行不言之教;作而弗始,生而弗有,为而弗恃,功成不居!

欢迎关注我的其它发布渠道