Home  >  Article  >  Operation and Maintenance  >  Linux command: show full path of file

Linux command: show full path of file

WBOY
WBOYOriginal
2024-02-21 09:18:04915browse

Linux command: show full path of file

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.

1. Use the 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.

2. Use the readlink command

Another 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.

3. Use the 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.

Conclusion

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn