linux怎么运行pwd命令,Linux pwd 命令及参数

刚才看kafka-manager,无意间看到pwd -P命令了

addJava "-Duser.dir=$(cd "${app_home}/.."; pwd -P)"

不知道有参数-P,于是乎,查看了下资料:

下面为在centos6.6 desktop下面执行

查看pwd命令的帮助信息

[root@aleiye init.d]# man pwd

NAME

pwd - print name of current/working directory

SYNOPSIS

pwd [OPTION]...

DESCRIPTION

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.

AUTHOR

Written by Jim Meyering.

REPORTING BUGS

Report pwd bugs to bug-coreutils@gnu.org

GNU coreutils home page: 

General help using GNU software: 

Report pwd translation bugs to 

COPYRIGHT

Copyright © 2010 Free Software Foundation, Inc.  License GPLv3+: GNU GPL version 3 or later .

This is free software: you are free to change and redistribute it.  There is NO WARRANTY, to the extent permitted by law.

SEE ALSO

getcwd(3)

The full documentation for pwd is maintained as a Texinfo manual.  If the info and pwd programs are properly installed at your site, the command

info coreutils 'pwd invocation'

should give you access to the complete manual.

2.显示当前目录所在路径 pwd

[root@aleiye init.d]# cd /etc/init.d/

[root@aleiye init.d]# pwd

/etc/init.d

3.显示当前目录的物理路径 pwd –P

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

/etc/rc.d/init.d

4.显示当前目录的连接路径:pwd -L

[root@aleiye init.d]# pwd -L

/etc/init.d

5.切换到home目录,重新执行

[root@aleiye init.d]# cd

[root@aleiye ~]# pwd

/root

[root@aleiye ~]# pwd -L

/root

[root@aleiye ~]# pwd -P

/root

6.通过切换目录,可知-L、-P和无参的区别

[root@aleiye ~]# cd /etc/init.d/

[root@aleiye init.d]# pwd

/etc/init.d

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

/etc/rc.d/init.d

[root@aleiye init.d]# pwd

/etc/init.d

[root@aleiye init.d]# cd /etc/rc.d/init.d/

[root@aleiye init.d]# pwd

/etc/rc.d/init.d

[root@aleiye init.d]# pwd -L

/etc/rc.d/init.d

[root@aleiye init.d]# cd /etc/init.d/

[root@aleiye init.d]# pwd -L

/etc/init.d

7.打印所有含有可执行pwd的路径

[root@aleiye init.d]# type -a pwd

pwd is a shell builtin

pwd is /bin/pwd

8.打印pwd版本信息

[root@aleiye init.d]# /bin/pwd --version

pwd (GNU coreutils) 8.4

Copyright (C) 2010 Free Software Foundation, Inc.

许可证:GPLv3+:GNU 通用公共许可证第3 版或更新版本。

本软件是自由软件:您可以自由修改和重新发布它。

在法律范围内没有其他保证。

由Jim Meyering 编写。

[root@aleiye init.d]# pwd --version

-bash: pwd: --: invalid option

pwd: usage: pwd [-LP]

注意: ‘pwd’ 通常不带选项运行,且没有任何参数

重要: 你可能注意到我们刚才运行的都是 “/bin/pwd” 而不是 “pwd”。

这有什么区别呢?直接使用“pwd”意味着使用shell内置的pwd。你的shell可能有不同版本的pwd。具体请参考手册。当你使用的是/bin/pwd时,我们调用的是二进制版本的命令。虽然二进制的版本有更多的选项,但是它们两者都能打印当前的目录。pwd没有参数--version,/bin/pwd有参数--version。

通过下面命令可用查看是否有软链接

[root@aleiye ~]# ll /etc/init.d

lrwxrwxrwx. 1 root root 11 7月  29 19:06 /etc/init.d -> rc.d/init.d

注意:用下面命令不行:

[root@aleiye ~]# ll /etc/init.d/

总用量 352

-rwxr-xr-x. 1 root root  1288 10月 16 2014 abrt-ccpp

-rwxr-xr-x. 1 root root  1628 10月 16 2014 abrtd

-rwxr-xr-x. 1 root root  1642 10月 16 2014 abrt-oops

-rwxr-xr-x. 1 root root  1725 8月  19 2010 acpid

...(忽略剩余部分)

[root@aleiye ~]# ls /etc/init.d/

abrt-ccpp  autofs            cups       htcacheclean  killall       netconsole      ntpd         quota_nld    rpcidmapd   smartd          sysstat

abrtd      blk-availability  dnsmasq    httpd         lvm2-lvmetad  netfs           ntpdate      rdisc        rpcsvcgssd  snmpd           udev-post

abrt-oops  bluetooth         firstboot  ip6tables     lvm2-monitor  network         oddjobd      restorecond  rsyslog     snmptrapd       wdaemon

acpid      certmonger        functions  iptables      mdmonitor     NetworkManager  portreserve  rngd         sandbox     spice-vdagentd  winbind

atd        cpuspeed          haldaemon  irqbalance    messagebus    nfs             postfix      rpcbind      saslauthd   sshd            wpa_supplicant

auditd     crond             halt       kdump         mysqld        nfslock         psacct       rpcgssd      single      sssd            ypbind

[root@aleiye ~]# ls /etc/init.d

abrt-ccpp  autofs            cups       htcacheclean  killall       netconsole      ntpd         quota_nld    rpcidmapd   smartd          sysstat

abrtd      blk-availability  dnsmasq    httpd         lvm2-lvmetad  netfs           ntpdate      rdisc        rpcsvcgssd  snmpd           udev-post

abrt-oops  bluetooth         firstboot  ip6tables     lvm2-monitor  network         oddjobd      restorecond  rsyslog     snmptrapd       wdaemon

acpid      certmonger        functions  iptables      mdmonitor     NetworkManager  portreserve  rngd         sandbox     spice-vdagentd  winbind

atd        cpuspeed          haldaemon  irqbalance    messagebus    nfs             postfix      rpcbind      saslauthd   sshd            wpa_supplicant

auditd     crond             halt       kdump         mysqld        nfslock         psacct       rpcgssd      single      sssd            ypbind

总结:可知当目录有软链接时,参数才有实际存在价值。为了鲁棒性,还是尽量加参数-P吧

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值