Linux command: show full path of file

WBOY
Release: 2024-02-21 09:18:04
Original
837 people have browsed it

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 therealpathcommand. The

realpathcommand can be used to obtain the absolute path of the file, that is, the complete path. The following is an example of using therealpathcommand:

realpath 文件名
Copy after login

For example, if we need to view the full path of the file namedexample.txt, we can enter the following command:

realpath example.txt
Copy after login

After executing this command, the terminal will output the full path of theexample.txtfile, such as/home/user/documents/example.txt.

2. Use thereadlinkcommand

Another 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 文件名
Copy after login

Suppose we have a symbolic link namedlink.txtpointing to thetarget.txtfile, if we want to gettarget.txtFor the full path of the file, you can use the following command:

readlink -f link.txt
Copy after login

After executing this command, the terminal will output the full path of thetarget.txtfile.

3. Use thepwdcommand

pwdcommand is usually used to display the path of the current working directory, but it can be combined withfindcommand can also be used to display the full path of a specified file. The example is as follows:

find `pwd` -name 文件名
Copy after login

Suppose we want to find the file path namedexample.txtin the current working directory and its subdirectories, we can use the following command:

find `pwd` -name example.txt
Copy after login

Execute After this command, the terminal will output the full path of theexample.txtfile.

Conclusion

Through the above examples, we understand how to use therealpath,readlinkandpwdcommands 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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!