mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-02-28 01:01:09 +08:00
PUB:20141124 15 pwd (Print Working Directory) Command Examples in Linux
@geekpi
This commit is contained in:
parent
cc40ae47a7
commit
1986af6f30
@ -1,14 +1,14 @@
|
||||
15条Linux下的‘pwd’命令(打印工作目录)示例
|
||||
菜鸟教程:全面学习 pwd 命令
|
||||
================================================================================
|
||||
对于那些使用Linux命令行的人来说,‘**pwd**‘命令是非常有用的,它告诉你你现在在那个目录,从根目录(**/**)开始。特别对于或许会在目录的切换间容易糊涂的Linux新手而言,‘**pwd**‘ 可以拯救他们。
|
||||
对于那些使用Linux命令行的人来说,‘**pwd**‘命令是非常有用的,它告诉你你现在在那个目录,从根目录(**/**)如何到达。特别是对于或许会在目录的切换间容易糊涂的Linux新手而言,‘**pwd**‘ 可以拯救他们。
|
||||
|
||||

|
||||
|
||||
15 pwd 命令示例
|
||||
*15个 pwd 命令示例*
|
||||
|
||||
### 什么是pwd? ###
|
||||
|
||||
‘**pwd**‘ 代表的是‘**Print Working Directory**’(打印当前目录)。如它的名字那样,‘**pwd**’会打印出当前工作目录或仅是目录用户。它会打印出以root (**/**)为起始的完整目录名。这条命令是一条shell内建命令,并且在大多数shell中都可以使用,如bash、Bourne shell,ksh、zsh等等。
|
||||
‘**pwd**‘ 代表的是‘**Print Working Directory**’(打印当前目录)。如它的名字那样,‘**pwd**’会打印出当前工作目录,或简单的来说就是当前用户所位于的目录。它会打印出以根目录 (**/**)为起点的完整目录名(绝对目录)。这条命令是一条shell内建命令,并且在大多数shell中都可以使用,如bash、Bourne shell,ksh、zsh等等。
|
||||
|
||||
#### pwd的基本语法: ####
|
||||
|
||||
@ -25,11 +25,11 @@
|
||||
<td align="LEFT" style="border: 1px solid #000000;"><b><span style="font-size: small;"> 描述</span></b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="19" align="LEFT" style="border: 1px solid #000000;"><span style="font-family: Liberation Serif,Times New Roman; font-size: small;"> -L (logical)</span></td>
|
||||
<td height="19" align="LEFT" style="border: 1px solid #000000;"><span style="font-family: Liberation Serif,Times New Roman; font-size: small;"> -L (即逻辑路径logical )</span></td>
|
||||
<td align="LEFT" style="border: 1px solid #000000;"><span style="font-family: Liberation Serif,Times New Roman; font-size: small;"> 使用环境中的路径,即使包含了符号链接</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="19" align="LEFT" style="border: 1px solid #000000;"><span style="font-family: Liberation Serif,Times New Roman; font-size: small;"> -P (physical)</span></td>
|
||||
<td height="19" align="LEFT" style="border: 1px solid #000000;"><span style="font-family: Liberation Serif,Times New Roman; font-size: small;"> -P (即物理路径physical)</span></td>
|
||||
<td align="LEFT" style="border: 1px solid #000000;"><span style="font-family: Liberation Serif,Times New Roman; font-size: small;"> 避免所有的符号链接</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
@ -56,7 +56,7 @@ pwd的退出状态:
|
||||
<td align="CENTER" style="border: 1px solid #000000;"><span style="font-size: small;">成功</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="19" align="CENTER" style="border: 1px solid #000000;"><span style="font-size: small;">Non-zero</span></td>
|
||||
<td height="19" align="CENTER" style="border: 1px solid #000000;"><span style="font-size: small;">非零值</span></td>
|
||||
<td align="CENTER" style="border: 1px solid #000000;"><span style="font-size: small;">失败</span></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@ -64,7 +64,7 @@ pwd的退出状态:
|
||||
|
||||
本篇的目的是采用例子让你对‘**pwd**‘有更深入的领悟。
|
||||
|
||||
**1.** 打印放钱工作目录.
|
||||
**1.** 打印当前工作目录.
|
||||
|
||||
avi@tecmint:~$ /bin/pwd
|
||||
|
||||
@ -72,7 +72,7 @@ pwd的退出状态:
|
||||
|
||||

|
||||
|
||||
打印工作目录
|
||||
*打印工作目录*
|
||||
|
||||
**2.** 为文件夹创建一个符号链接(比如说在home目录下创建一个**htm**链接指向**/var/www/html**)。进入新创建的目录并打印出含有以及不含符号链接的目录。
|
||||
|
||||
@ -83,9 +83,9 @@ pwd的退出状态:
|
||||
|
||||

|
||||
|
||||
创建符号链接
|
||||
*创建符号链接*
|
||||
|
||||
**3.** 从当前环境中答应目录即使它含有符号链接。
|
||||
**3.** 从当前环境中打印目录即使它含有符号链接。
|
||||
|
||||
avi@tecmint:~$ /bin/pwd -L
|
||||
|
||||
@ -93,7 +93,7 @@ pwd的退出状态:
|
||||
|
||||

|
||||
|
||||
打印工作目录
|
||||
*打印工作目录*
|
||||
|
||||
**4.** 解析符号链接并打印出物理目录。
|
||||
|
||||
@ -103,7 +103,7 @@ pwd的退出状态:
|
||||
|
||||

|
||||
|
||||
打印物理工作目录
|
||||
*打印物理工作目录*
|
||||
|
||||
**5.** 查看一下“**pwd**”和“**pwd -P**”的输出是否一致,也就是说,如果没有跟上选项,“**pwd**”时候会自动采用**-P**选项。
|
||||
|
||||
@ -113,7 +113,7 @@ pwd的退出状态:
|
||||
|
||||

|
||||
|
||||
检查pwd输出
|
||||
*检查pwd输出*
|
||||
|
||||
**结论:** 上面例子4和5的输出很明显(结果相同),当你“**pwd**”后面不带参数时,pwd会使用“**-P**”选项。
|
||||
|
||||
@ -131,7 +131,7 @@ pwd的退出状态:
|
||||
|
||||

|
||||
|
||||
检查pwd命令版本
|
||||
*检查pwd命令版本*
|
||||
|
||||
**注意:** ‘pwd’ 通常不带选项运行,且没有任何参数
|
||||
|
||||
@ -148,9 +148,9 @@ pwd的退出状态:
|
||||
|
||||

|
||||
|
||||
打印可执行文件路径
|
||||
*打印可执行文件路径*
|
||||
|
||||
**8.** 存储“**pwd**”命令的值到变量中(比如说:**a** ),并从中打印i变量的值(对于观察shell脚本很重要)。
|
||||
**8.** 存储“**pwd**”命令的值到变量中(比如说:**a** ),并从中打印变量的值(对于观察shell脚本很重要)。
|
||||
|
||||
avi@tecmint:~$ a=$(pwd)
|
||||
avi@tecmint:~$ echo "Current working directory is : $a"
|
||||
@ -159,19 +159,19 @@ pwd的退出状态:
|
||||
|
||||

|
||||
|
||||
存储pwd的值到变量中。
|
||||
*存储pwd的值到变量中*
|
||||
|
||||
下面的例子中也可以用**printf**来替代。
|
||||
|
||||
**9.** 将工作路径切换到其他地方(比如说 **/home**),并在命令行中显示。通过执行命令(比如说 ‘**ls**‘)来验证一切**OK**。
|
||||
|
||||
avi@tecmint:~$ cd /home
|
||||
avi@tecmint:~$ PS1='$pwd> ' [Notice single quotes in the example]
|
||||
avi@tecmint:~$ PS1='$pwd> ' [注意例子中的单引号]
|
||||
> ls
|
||||
|
||||

|
||||
|
||||
改变当前工作路径
|
||||
*改变当前工作路径*
|
||||
|
||||
**10.** 设置多行显示 (就像下面这样),
|
||||
|
||||
@ -190,7 +190,7 @@ pwd的退出状态:
|
||||
|
||||

|
||||
|
||||
设置多行显示
|
||||
*设置多行显示*
|
||||
|
||||
**11.** 一下子检查当前工作路径以及先前的工作路径。
|
||||
|
||||
@ -200,8 +200,7 @@ pwd的退出状态:
|
||||
|
||||

|
||||
|
||||
Check Present Previous Working Directory
|
||||
检查当前工作路径
|
||||
*检查当前工作路径*
|
||||
|
||||
**12.** pwd文件的绝对路径(以**/**开始)。
|
||||
|
||||
@ -211,7 +210,7 @@ Check Present Previous Working Directory
|
||||
|
||||
/usr/include/pwd.h
|
||||
|
||||
**13.** 打印pwd手册的绝对路径(以**/**开始)。
|
||||
**13.** pwd手册的绝对路径(以**/**开始)。
|
||||
|
||||
/usr/share/man/man1/pwd.1.gz
|
||||
|
||||
@ -241,7 +240,7 @@ Check Present Previous Working Directory
|
||||
}
|
||||
fi
|
||||
|
||||
给予他执行权限并运行。
|
||||
给予执行权限并运行。
|
||||
|
||||
avi@tecmint:~$ chmod 755 pwd.sh
|
||||
avi@tecmint:~$ ./pwd.sh
|
||||
@ -251,7 +250,7 @@ Check Present Previous Working Directory
|
||||
|
||||
#### 总结 ####
|
||||
|
||||
**pwd**是一个最简单且会广泛用到的命令。掌握好pwd是使用Linux终端的基础。就是这些了。我很快会再带来另外有趣的注意,请不要走开继续关注Tecmint。
|
||||
**pwd**是一个最简单且会广泛用到的命令。掌握好pwd是使用Linux终端的基础。就是这些了。我很快会再带来另外有趣的文章,请不要走开继续关注我们。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@ -259,7 +258,7 @@ via: http://www.tecmint.com/pwd-command-examples/
|
||||
|
||||
作者:[Avishek Kumar][a]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
Loading…
Reference in New Issue
Block a user