技术知识库

pwd工具打印当前/当前工作目录的名称(PWD - 当前工作目录,得到它?)。 以下是它的语法:


pwd [OPTION]...


下面是该工具的手册页如何描述它:


Print the full filename of the current working directory.

以下是一些Q&A样式的示例,应该能够让您了解pwd命令的工作原理。


Q1。 pwd命令如何工作?

通常情况下,基本用法非常简单。 您只需运行“pwd”命令而不用任何选项,您将在输出中获得当前工作目录的完整路径。


pwd


这是一个例子:


himanshu@ansh:~$ pwd

/home/himanshu

值得一提的是,大多数shell,包括bash,都已经内建了。 只需执行以下命令:


type -a pwd


你应该得到以下输出。


pwd is a shell builtin

pwd is /bin/pwd

Q2。 pwd和/ bin / pwd有什么区别?

那么,pwd是内置的shell,而/ bin / pwd是Linux发行版附带的工具。 PWD的手册页清楚地说明了这一点:


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.

Q3。 如何使pwd从环境中使用PWD?

这可以使用-L命令行选项完成。 为了测试这个,创建一个到当前目录的符号链接(在我的情况下是/ home / himanshu)。


例如:


ln -s . dir_symlink


然后输入它:


cd dir_symlink


现在,运行以下命令:


/bin/pwd


在我的情况下,得到了以下输出:


/home/himanshu

接下来,执行这个命令


/bin/pwd -L


我得到了以下输出:


/home/himanshu/dir_symlink

Q4。 如何使pwd避免所有的符号链接?

这可以使用-P命令行选项完成。 例如:


/bin/pwd -L


产生以下输出:


/home/himanshu/dir_symlink

但是用-P


/bin/pwd -L -P


输出是:


/home/himanshu

值得一提的是,如果没有指定选项,默认情况下是-P


提交成功!非常感谢您的反馈,我们会继续努力做到更好!

这条文档是否有帮助解决问题?

非常抱歉未能帮助到您。为了给您提供更好的服务,我们很需要您进一步的反馈信息:

在文档使用中是否遇到以下问题: