From cf408257c1fa3cf44239e7e032f477a680f64ed4 Mon Sep 17 00:00:00 2001 From: geekpi Date: Sat, 29 Nov 2014 06:15:26 -0500 Subject: [PATCH] translated --- ...ng Directory) Command Examples in Linux.md | 118 +++++++++--------- 1 file changed, 58 insertions(+), 60 deletions(-) rename {sources => translated}/tech/20141124 15 pwd (Print Working Directory) Command Examples in Linux.md (51%) diff --git a/sources/tech/20141124 15 pwd (Print Working Directory) Command Examples in Linux.md b/translated/tech/20141124 15 pwd (Print Working Directory) Command Examples in Linux.md similarity index 51% rename from sources/tech/20141124 15 pwd (Print Working Directory) Command Examples in Linux.md rename to translated/tech/20141124 15 pwd (Print Working Directory) Command Examples in Linux.md index 93e0f4a7ab..2e829d5628 100644 --- a/sources/tech/20141124 15 pwd (Print Working Directory) Command Examples in Linux.md +++ b/translated/tech/20141124 15 pwd (Print Working Directory) Command Examples in Linux.md @@ -1,54 +1,51 @@ -Transalting-----geekpi - - -15 ‘pwd’ (Print Working Directory) Command Examples in Linux +15条Linux下的‘pwd’命令(打印工作目录)示例 ================================================================================ -For those working with Linux command Line, command ‘**pwd**‘ is very helpful, which tells where you are – in which directory, starting from the root (**/**). Specially for Linux newbies, who may get lost amidst of directories in command Line Interface while navigation, command ‘**pwd**‘ comes to rescue. +对于那些使用Linux命令行的人来说,‘**pwd**‘命令是非常有用的,它告诉你你现在在那个目录,从根目录(**/**)开始。特别对于或许会在目录的切换间容易糊涂的Linux新手而言,‘**pwd**‘ 可以拯救他们。 ![15 pwd Command Examples](http://www.tecmint.com/wp-content/uploads/2014/11/pwd-command.png) -15 pwd Command Examples +15 pwd 命令示例 -### What is pwd? ### +### 什么是pwd? ### -‘**pwd**‘ stands for ‘**Print Working Directory**‘. As the name states, command ‘**pwd**‘ prints the current working directory or simply the directory user is, at present. It prints the current directory name with the complete path starting from root (**/**). This command is built in shell command and is available on most of the shell – bash, Bourne shell, ksh,zsh, etc. +‘**pwd**‘ 代表的是‘**Print Working Directory**’(打印当前目录)。如它的名字那样,‘**pwd**’会打印出当前工作目录或仅是目录用户。它会打印出以root (**/**)为起始的完整目录名。这条命令是一条shell内建命令,并且在大多数shell中都可以使用,如bash、Bourne shell,ksh、zsh等等。 -#### Basic syntax of pwd: #### +#### pwd的基本语法: #### # pwd [OPTION] -#### Options used with pwd #### +#### pwd的选项 #### - - + + - + - + - + - +
 Options Description 选项 描述
 -L (logical) Use PWD from environment, even if it contains symbolic links 使用环境中的路径,即使包含了符号链接
 -P (physical) Avoid all symbolic links 避免所有的符号链接
 –help  Display this help and exit 显示帮助并退出
 –version Output version information and exit 输出版本信息并退出
-If both ‘**-L**‘ and ‘**-P**‘ options are used, option ‘**L**‘ is taken into priority. If no option is specified at the prompt, pwd will avoid all symlinks, i.e., take option ‘**-P**‘ into account. +如果同时使用了‘**-L**‘和‘**-P**‘,‘**-L**‘会有更高的优先级。如果没有指定参数,pwd会避开所有的软链接,也就是说会使用‘**-P**‘参数。 -Exit status of command pwd: +pwd的退出状态: @@ -56,18 +53,18 @@ Exit status of command pwd: - + - +
0Success成功
Non-zeroFailure失败
-This article aims at providing you a deep insight of Linux command ‘**pwd**‘ with practical examples. +本篇的目的是采用例子让你对‘**pwd**‘有更深入的领悟。 -**1.** Print your current working directory. +**1.** 打印放钱工作目录. avi@tecmint:~$ /bin/pwd @@ -75,20 +72,20 @@ This article aims at providing you a deep insight of Linux command ‘**pwd**‘ ![Print Working Directory](http://www.tecmint.com/wp-content/uploads/2014/11/pwd.gif) -Print Working Directory +打印工作目录 -**2.** Create a symbolic link of a folder (say **/var/www/html** into your home directory as **htm**). Move to the newly created directory and print working directory with symbolic links and without symbolic links. +**2.** 为文件夹创建一个符号链接(比如说在home目录下创建一个**htm**链接指向**/var/www/html**)。进入新创建的目录并打印出含有以及不含符号链接的目录。 -Create a symbolic link of folder /var/www/html as htm in your home directory and move to it. +在home目录下创建一个htm链接指向/var/www/html,并进入。 avi@tecmint:~$ ln -s /var/www/html/ htm avi@tecmint:~$ cd htm ![Create Symbolic Link](http://www.tecmint.com/wp-content/uploads/2014/11/Create-Symbolic-Link.gif) -Create Symbolic Link +创建符号链接 -**3.** Print working directory from environment even if it contains symlinks. +**3.** 从当前环境中答应目录即使它含有符号链接。 avi@tecmint:~$ /bin/pwd -L @@ -96,9 +93,9 @@ Create Symbolic Link ![Print Current Working Directory](http://www.tecmint.com/wp-content/uploads/2014/11/Print-Working-Directory.gif) -Print Current Working Directory +打印工作目录 -**4.** Print actual physical current working directory by resolving all symbolic links. +**4.** 解析符号链接并打印出物理目录。 avi@tecmint:~$ /bin/pwd -P @@ -106,9 +103,9 @@ Print Current Working Directory ![Print Physical Working Directory](http://www.tecmint.com/wp-content/uploads/2014/11/Print-Physical-Working-Directory.gif) -Print Physical Working Directory +打印物理工作目录 -**5.** Check if the output of command “**pwd**” and “**pwd -P**” are same or not i.e., if no options are given at run-time does “**pwd**” takes option **-P** into account or not, automatically. +**5.** 查看一下“**pwd**”和“**pwd -P**”的输出是否一致,也就是说,如果没有跟上选项,“**pwd**”时候会自动采用**-P**选项。 avi@tecmint:~$ /bin/pwd @@ -116,11 +113,11 @@ Print Physical Working Directory ![Check pwd Output](http://www.tecmint.com/wp-content/uploads/2014/11/Check-pwd-Output.gif) -Check pwd Output +检查pwd输出 -**Result:** It’s clear from the above output of example 4 and 5 (both result are same) thus, when no options are specified with command “**pwd**”, it automatically takes option “**-P**” into account. +**结论:** 上面例子4和5的输出很明显(结果相同),当你“**pwd**”后面不带参数时,pwd会使用“**-P**”选项。 -**6.** Print version of your ‘pwd’ command. +**6.** 打印pwd命令的版本。 avi@tecmint:~$ /bin/pwd --version @@ -134,15 +131,15 @@ Check pwd Output ![Check pwd Version](http://www.tecmint.com/wp-content/uploads/2014/11/Check-pwd-Version.gif) -Check pwd Version +检查pwd命令版本 -**Note:** A ‘pwd’ command is often used without options and never used with arguments. +**注意:** ‘pwd’ 通常不带选项运行,且没有任何参数 -**Important:** You might have noticed that we are executing the above command as “**/bin/pwd**” and not “**pwd**”. +**重要:** 你可能注意到我们刚才运行的都是 “**/bin/pwd**” 而不是 “**pwd**”。 -So what’s the difference? Well “**pwd**” alone means shell built-in pwd. Your shell may have different version of pwd. Please refer manual. When we are using **/bin/pwd**, we are calling the binary version of that command. Both the shell and the binary version of command Prints Current Working Directory, though the binary version have more options. +这有什么区别呢?直接使用“**pwd**”意味着使用shell内置的pwd。你的shell可能有不同版本的pwd。具体请参考手册。当你使用的是**/bin/pwd**时,我们调用的是二进制版本的命令。虽然二进制的版本有更多的选项,但是它们两者都能打印当前的目录。 -**7.** Print all the locations containing executable named pwd. +**7.** 打印所有含有可执行pwd的路径 avi@tecmint:~$ type -a pwd @@ -151,9 +148,9 @@ So what’s the difference? Well “**pwd**” alone means shell built-in pwd. Y ![Print Executable Locations](http://www.tecmint.com/wp-content/uploads/2014/11/Print-Executable-Locations.gif) -Print Executable Locations +打印可执行文件路径 -**8.** Store the value of “**pwd**” command in variable (say **a**), and print its value from the variable (important for shell scripting perspective). +**8.** 存储“**pwd**”命令的值到变量中(比如说:**a** ),并从中打印i变量的值(对于观察shell脚本很重要)。 avi@tecmint:~$ a=$(pwd) avi@tecmint:~$ echo "Current working directory is : $a" @@ -162,11 +159,11 @@ Print Executable Locations ![Store Pwd Value in Variable](http://www.tecmint.com/wp-content/uploads/2014/11/Store-Pwd-Value-in-Variable.gif) -Store Pwd Value in Variable +存储pwd的值到变量中。 -Alternatively, we can use **printf**, in the above example. +下面的例子中也可以用**printf**来替代。 -**9.** Change current working directory to anything (say **/home**) and display it in command line prompt. Execute a command (say ‘**ls**‘) to verify is everything is **OK**. +**9.** 将工作路径切换到其他地方(比如说 **/home**),并在命令行中显示。通过执行命令(比如说 ‘**ls**‘)来验证一切**OK**。 avi@tecmint:~$ cd /home avi@tecmint:~$ PS1='$pwd> ' [Notice single quotes in the example] @@ -174,14 +171,14 @@ Alternatively, we can use **printf**, in the above example. ![Change Current Working Directory](http://www.tecmint.com/wp-content/uploads/2014/11/Change-Current-Working-Directory.gif) -Change Current Working Directory +改变当前工作路径 -**10.** Set multi-line command line prompt (say something like below). +**10.** 设置多行显示 (就像下面这样), /home 123#Hello#! -And then execute a command (say **ls**) to check is everything is **OK**. +接着执行命令(比如说 **ls**)来检验一切**OK**。 avi@tecmint:~$ PS1=' > $PWD @@ -193,9 +190,9 @@ And then execute a command (say **ls**) to check is everything is **OK**. ![Set Multi Commandline Prompt](http://www.tecmint.com/wp-content/uploads/2014/11/Set-Multi-Commandline-Prompt.gif) -Set Multi Commandline Prompt +设置多行显示 -**11.** Check the current working directory and previous working directory in one GO! +**11.** 一下子检查当前工作路径以及先前的工作路径。 avi@tecmint:~$ echo “$PWD $OLDPWD” @@ -204,28 +201,29 @@ Set Multi Commandline Prompt ![Check Present Previous Working Directory](http://www.tecmint.com/wp-content/uploads/2014/11/Check-Present-Previous-Working-Directory.gif) Check Present Previous Working Directory +检查当前工作路径 -**12.** What is the absolute path (starting from **/**) of the pwd binary file. +**12.** pwd文件的绝对路径(以**/**开始)。 /bin/pwd -**13.** What is the absolute path (starting from **/**) of the pwd source file. +**13.** pwd源文件文件的绝对路径(以**/**开始)。 /usr/include/pwd.h -**14.** Print the absolute path (starting from **/**) of the pwd manual pages file. +**13.** 打印pwd手册的绝对路径(以**/**开始)。 /usr/share/man/man1/pwd.1.gz -**15.** Write a shell script analyses current directory (say **tecmint**) in your home directory. If you are under directory **tecmint** it output “**Well! You are in tecmint directory**” and then print “**Good Bye**” else create a directory **tecmint** under your home directory and ask you to cd to it. +**15.** 写一个shell脚本分析home目录下的一个目录(比如**tecmint**)。如果当前目录是**tecmint**就输出“**Well! You are in tecmint directory**”接着输出“**Good Bye**”,不然就在**tecmint**下面创建一个目录并提示你cd进入它。 -Let’s first create a ‘tecmint’ directory, under it create a following shell script file with name ‘pwd.sh’. +让我们首先创建一个‘tecmint’目录,在下面创建一个名为‘pwd.sh’的脚本文件。 avi@tecmint:~$ mkdir tecmint avi@tecmint:~$ cd tecmint avi@tecmint:~$ nano pwd.sh -Next, add the following script to the pwd.sh file. +接下来在pwd.sh中加入下面的脚本。 #!/bin/bash @@ -243,7 +241,7 @@ Next, add the following script to the pwd.sh file. } fi -Give execute permission and run it. +给予他执行权限并运行。 avi@tecmint:~$ chmod 755 pwd.sh avi@tecmint:~$ ./pwd.sh @@ -251,18 +249,18 @@ Give execute permission and run it. Well you are in tecmint directory Good Bye -#### Conclusion #### +#### 总结 #### -**pwd** is one of the simplest yet most popular and most widely used command. A good command over pwd is basic to use Linux terminal. That’s all for now. I’ll be here again with another interesting article soon, till then stay tuned and connected to Tecmint. +**pwd**是一个最简单且会广泛用到的命令。掌握好pwd是使用Linux终端的基础。就是这些了。我很快会再带来另外有趣的注意,请不要走开继续关注Tecmint。 -------------------------------------------------------------------------------- via: http://www.tecmint.com/pwd-command-examples/ 作者:[Avishek Kumar][a] -译者:[译者ID](https://github.com/译者ID) +译者:[geekpi](https://github.com/geekpi) 校对:[校对者ID](https://github.com/校对者ID) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出 -[a]:http://www.tecmint.com/author/avishek/ +[a]:http://www.tecmint.com/author/avishek/ \ No newline at end of file