Linux命令详解之 pwd

linux 命令详解

本文主要内容来自Linux man 手册

命令名称:

pwd ( Print Working Directory )打印当前/工作目录的名字

命令用法:

pwd [选项] . . .

命令概述:

打印当前工作目录的全名,即打印当前目录的绝对路径。

命令参数:

以下为命令手册的内容,但实际测试结果并非如此

-L , --logical :显示逻辑路径
		从全局运行环境来考虑工作目录的绝对路径,考虑符号链接(软链接)
-P , --physical:显示物理路径
		不考虑符号链接
	 --help
  	 	打印帮助信息 【有些版本shell没有该参数】
     --version
        打印版本信息 【有些版本shell没有该参数】
        
	如果没有指定参数,则默认使用 -P ,即不考虑软链接【与我所测结果正好相反】

示例:

1. pwd 或 pwd -L

当前目录 pwd_test/ 下有一个带软链接的目录 dir1 ,指向上层目录的 dir1,

xiaohui@ubuntu:~/work/pwd_test$ ll
total 8
drwxrwxr-x 2 xiaohui xiaohui 4096 Dec 29 22:54 ./
drwxrwxr-x 6 xiaohui xiaohui 4096 Dec 29 22:54 ../
lrwxrwxrwx 1 xiaohui xiaohui   24 Dec 29 22:54 dir1 -> /home/xiaohui/work/dir1//

进入该目录,直接使用 pwd 或者 用 pwd -L ,结果如下:

xiaohui@ubuntu:~/work/pwd_test$ cd dir1
xiaohui@ubuntu:~/work/pwd_test/dir1$ pwd
/home/xiaohui/work/pwd_test/dir1
xiaohui@ubuntu:~/work/pwd_test/dir1$ pwd -L
/home/xiaohui/work/pwd_test/dir1

我所用的Linux Shell命令 pwd 不指定参数时和使用 pwd -L 相同,都是打印实际的绝对路径,不考虑符号链接。


2 . pwd -P
xiaohui@ubuntu:~/work/pwd_test/dir1$ pwd -P
/home/xiaohui/work/dir1

使用 -P 参数,打印的是符号链接源目录的绝对路径,即考虑软链接。

man手册

以下为 pwd 的参考手册原文:

PWD(1)                            User Commands                            PWD(1)

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

       If no option is specified, -P is assumed.

       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
       GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
       Report pwd translation bugs to <http://translationproject.org/team/>

COPYRIGHT
       Copyright  ©  2016 Free Software Foundation, Inc.  License GPLv3+: GNU GPL
       version 3 or later <http://gnu.org/licenses/gpl.html>.
       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)

       Full documentation at: <http://www.gnu.org/software/coreutils/pwd>
       or available locally via: info '(coreutils) pwd invocation'

GNU coreutils 8.25                February 2017                            PWD(1)


原来,不同版本的 pwd ,其参数的作用也不同。

  • 6
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小辉_Super

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值