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. The realpath
command can be used to obtain the absolute path of the file, that is, the complete path. The following is an example of using the realpath
command:
realpath 文件名
For example, if we need to view the full path of the file named example.txt
, we can enter the following command:
realpath example.txt
After executing this command, the terminal will output the full path of the example.txt
file, such as /home/user/documents/example.txt
.
readlink
commandAnother commonly used command is readlink
, 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 named link.txt
pointing to the target.txt
file, if we want to get target.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 the target.txt
file.
pwd
command pwd
command is usually used to display the path of the current working directory, but it can be combined with find
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 named example.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 the example.txt
file.
Through the above examples, we understand how to use the realpath
, readlink
and pwd
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!