Linux常用命令-pwd

命令

pwd

描述

Print the name of the current working directory
显示当前工作目录

用法

1
pwd [-LP]

选项

1
2
3
Options:
-L 显示当前工作目录,默认选项
-P 显示物理目录,如果是软链接则显示源目录

两个默认系统变量
$PWD 当前工作目录,同pwd命令
$OLDPWD 上一次的工作目录
cd - 可以使用该命令来切换以上两个目录

注意

示例

1
2
3
4
5
6
7
8
9
10
11
12
$ ll
drwxr-xr-x 2 root root 6 Dec 17 23:13 d1/
lrwxrwxrwx 1 root root 2 Dec 17 23:13 d2 -> d1/
$ cd d1
$ pwd
/root/d1
$ cd ../d2
$ pwd
/root/d2
# 显示软链接的源目录路径
$ pwd -P
/root/d1