网站 关键字 标签,管理软件的软件哪个好,潍坊企业宣传片制作公司,北京建设工程造价信息网官网Linux pwd命令介绍
pwd命令#xff08;全称#xff1a;print working directory#xff09;是一个非常简单的Linux命令#xff0c;它的功能就是打印当前工作目录。当你在Linux终端中感到迷失时#xff0c;pwd命令可以帮助你重新定位#xff0c;显示你所在的目录。
Linu…Linux pwd命令介绍
pwd命令全称print working directory是一个非常简单的Linux命令它的功能就是打印当前工作目录。当你在Linux终端中感到迷失时pwd命令可以帮助你重新定位显示你所在的目录。
Linux pwd命令适用的Linux版本
pwd命令在所有主流的Linux发行版中都可以使用包括但不限于Ubuntu、Debian、Fedora、CentOS等。这个命令是内置在bash shell中的所以不需要进行任何安装。
[linuxbashcommandnotfound.cn ~]$ pwdLinux pwd命令的基本语法
pwd命令的基本语法非常简单只需要在终端中输入pwd即可。
pwdLinux pwd命令的常用选项或参数说明
pwd命令的选项非常简单主要有两个
-P避免列出符号链接而是给出绝对路径。-L如果你通过符号链接导航到特定目录它会列出符号链接。
Linux pwd命令的实例
实例1获取工作目录路径
运行没有任何选项的pwd命令会输出当前工作目录的完整路径。
[linuxbashcommandnotfound.cn ~]$ pwd实例2使用-P选项打印物理工作目录
-P选项指示pwd打印物理工作目录并避免列出符号链接。因此该命令打印当前工作目录的绝对路径。
[linuxbashcommandnotfound.cn ~]$ pwd -P实例3使用-L选项打印工作目录路径
-L选项指示pwd打印工作目录路径包括任何符号链接。
[linuxbashcommandnotfound.cn ~]$ pwd -L实例4在子目录中使用pwd命令
当你在子目录中时pwd命令可以帮助你确定你的位置。例如假设你在/home/user/Documents目录中你可以使用pwd命令来确认这一点。
[linuxbashcommandnotfound.cn ~]$ cd /home/user/Documents
[linuxbashcommandnotfound.cn ~]$ pwd
/home/user/Documents实例5在符号链接目录中使用pwd命令
当你在一个通过符号链接访问的目录中时pwd命令的输出会根据你使用的选项而变化。例如假设你有一个指向/home/user/Documents的符号链接/home/user/Docs你可以看到pwd和pwd -P的区别。
[linuxbashcommandnotfound.cn ~]$ cd /home/user/Docs
[linuxbashcommandnotfound.cn ~]$ pwd
/home/user/Docs
[linuxbashcommandnotfound.cn ~]$ pwd -P
/home/user/Documents实例6在脚本中动态获取当前目录
你也可以在shell脚本中动态获取当前目录。例如以下脚本会打印出脚本执行时的当前目录。
[linuxbashcommandnotfound.cn ~]$ echo #!/bin/bash script.sh
[linuxbashcommandnotfound.cn ~]$ echo echo This script is executed in $(pwd) script.sh
[linuxbashcommandnotfound.cn ~]$ bash script.sh
This script is executed in /home/user实例7在Makefile中使用pwd命令
在Makefile中你可以使用pwd命令来获取当前目录。这在需要指定文件路径时非常有用。
[linuxbashcommandnotfound.cn ~]$ echo all: Makefile
[linuxbashcommandnotfound.cn ~]$ echo echo Current directory: $(shell pwd) Makefile
[linuxbashcommandnotfound.cn ~]$ make
Current directory: /home/userLinux pwd命令的注意事项
当你在终端中输入pwd命令时如果返回bash: pwd: command not found那么你可能需要检查你的$PATH环境变量或者尝试使用绝对路径/bin/pwd来运行命令。
Linux pwd相关命令
cd命令用于改变当前目录ls命令用于列出目录内容cp命令复制文件或目录mv命令移动或重命名文件或目录mkdir命令创建新的目录rmdir命令删除空目录touch命令创建新的空文件cat命令用来连接文件并打印到标准输出设备上