Linux command: display the full path of the file
In the Linux system, sometimes we need to view the full path of the file in order to operate or Locate the file location. This article will introduce how to use Linux commands to display the full path of a file, while providing specific code examples.
realpath
command. Therealpath
command can be used to obtain the absolute path of the file, that is, the complete path. The following is an example of using therealpath
command:
realpath 文件名
For example, if we need to view the full path of the file namedexample.txt
, we can enter the following command:
realpath example.txt
After executing this command, the terminal will output the full path of theexample.txt
file, such as/home/user/documents/example.txt
.
readlink
commandAnother commonly used command isreadlink
, which can be used to display the target file pointed to by the symbolic link. path. An example is as follows:
readlink -f 文件名
Suppose we have a symbolic link namedlink.txt
pointing to thetarget.txt
file, if we want to gettarget.txt
For the full path of the file, you can use the following command:
readlink -f link.txt
After executing this command, the terminal will output the full path of thetarget.txt
file.
pwd
commandpwd
command is usually used to display the path of the current working directory, but it can be combined withfind
command can also be used to display the full path of a specified file. The example is as follows:
find `pwd` -name 文件名
Suppose we want to find the file path namedexample.txt
in the current working directory and its subdirectories, we can use the following command:
find `pwd` -name example.txt
Execute After this command, the terminal will output the full path of theexample.txt
file.
Through the above examples, we understand how to use therealpath
,readlink
andpwd
commands in the Linux system to display the full path of the file. These commands can help us easily find the location of files and perform related operations. Hope this article helps you!
The above is the detailed content of Linux command: show full path of file. For more information, please follow other related articles on the PHP Chinese website!