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 ,其参数的作用也不同。