This article mainly introduces the relevant knowledge of how Linux displays the current path. The editor shows you the operation process through actual cases. The operation method is simple, fast, and practical. I hope this article on how to display the current path in Linux can help you solve question.
In Linux, you can use the pwd command to display the current path. pwd is the abbreviation of Print Working Directory, its function is to display the full path of the current working directory, the syntax is pwd [options]; it is mainly used to view the absolute path of the current directory when the current location is not sure.
Because there are many directories in the Linux file system, when the user executes a Linux command and does not specify the directory where the command or parameter is located, the Linux system will first enter the directory in the current directory (the current working directory) directory) to search for the command or its arguments. Therefore, users often need to determine the current working directory, that is, the current directory, before executing the command.
When a user logs in to the Linux system, his current directory is his home directory. So, how to determine the current directory? You can use the pwd command of the Linux system to display the absolute path of the current directory.
pwd command overview
pwd
is the abbreviation of Print Working Directory
, Its function is to display the full path of the current working directory. It is mainly used to view the absolute path of the current directory through pwd
when the current location is not sure.
pwd command syntax
pwd [options]
parameters :
-L
: --logical
, display the current path, when there is a connection file, directly display the connection file Path, (this method is the default when no parameters are added), refer to example 1.
-p
: --physical
, display the current path, when there is a connection file, do not use the connection path, Directly display the file pointed to by the link file, refer to Example 2. When a multi-layer connection file is included, the file to which the connection file finally points is displayed, refer to Example 3.
--help
: DisplayDisplay help information.
--version
: Display version information.
pwd command example
Example 1: Check the current path
[root@localhost var]# pwd
/var
Example 2: View the current path without using the connection path
[ root@localhost ~]# cd /var/ #Enter the /var directory, there is a mail connection file in this directory, which is convenient for comparison and viewing
[root@localhost var]# ll
total 164
...
drwxr-xr-x 12 root root 4096 Apr 22 19:56 log
lrwxrwxrwx 1 root root 10 Oct 17 2015 mail -> spool/mail
drwxr-xr-x 2 root root 4096 May 11 2011 nis
...
[root@localhost var]# cd mail/ #Enter the mail directory, mail is the connection file.
[root@localhost mail]# pwd #Default, use the connection file, directly display the full path of the connection file.
/var/mail
[root@localhost mail]# pwd -P #Do not use the logical path, the file that the connection file finally points to
/var/spool/mail
Example 3: When multi-layer connection files are connected, display the full path of the file finally pointed to by all connection files
[root@localhost ~]# ll # There is a dir1 directory under the /root directory, and the test connection file points to the dir1 directory
total 12
drwxr-xr-x 2 root root 4096 Apr 24 05:51 dir1
lrwxrwxrwx 1 root root 5 Apr 24 05:54 test -> dir1/
[root@localhost ~]# ll /home/ #/home directoryThere is a test connection file on it, pointing to the /root/test connection file
total 20
drwx------ 16 sgl sgl 4096 Oct 17 2015 sgl
lrwxrwxrwx 1 root root 10 Apr 24 05:55 test -> /root/test
[root@localhost ~]# cd /home/test/ #Enter /home/test through the cd command
[root@localhost test]# pwd #Default, only the full path of the connection file is displayed
/home/test
[root@localhost test]# pwd -P # Display the full path of the file finally pointed to by the connection file. Note that this is not /root/test.
/root/dir1
This is the end of the introduction on how Linux displays the current path, thank you for reading. If you want to know more industry-related knowledge, you can pay attention to the industry information channel of Yisu Cloud. The editor will update different knowledge points for you every day.
Copyright Description:No reproduction without permission。
Knowledge sharing community for developers。
Let more developers benefit from it。
Help developers share knowledge through the Internet。
Follow us