How to view the absolute path of a file in Linux

PHPz
Release: 2024-02-24 08:33:23
Original
1117 people have browsed it

How to view the absolute path of a file in Linux

Displaying the full path of a file in Linux is a very common and useful operation. By displaying the full path of the file, we can more easily locate the file's location in the system and perform file management and operations. In Linux systems, you can display the full path of the current working directory by using the "pwd" command, and display the full path of a specified file by using the "realpath" or "readlink" command. Next, we will introduce in detail how to display the full path of a file in Linux, with specific code examples.

Use the pwd command to display the full path of the current working directory

In Linux systems, you can use the "pwd" command to display the full path of the current working directory. The "pwd" command will output the full path of the current directory, allowing users to clearly know their current location. The following is a simple example:

pwd
Copy after login

Run the above command, the system will output the full path of the current working directory, for example:

/home/user/Documents
Copy after login

Use the realpath command to display the full path of the specified file

If you need to display the full path of the specified file, you can use the "realpath" command. The "realpath" command can convert a relative path to an absolute path and output the full path of the file. The following is a sample code:

realpath filename
Copy after login

where "filename" is the file name to which the full path needs to be displayed. Run the above command, and the system will output the full path of the specified file, for example:

/home/user/Documents/filename
Copy after login

Use the readlink command to display the full path of the symbolic link

If the file is a symbolic link, you can use the "readlink" command to display the full path of the symbolic link. The following is a sample code:

readlink symlink
Copy after login

Among them, "symlink" is the symbolic link that needs to display the full path. Run the above command, and the system will output the full path of the symbolic link, for example:

/home/user/Documents/target-file
Copy after login

Summary

Through the above introduction, we understand how to display the full path of the file in the Linux system. The full path of the current working directory can be displayed by using the "pwd" command, and the full path of specified files and symbolic links can be displayed using the "realpath" and "readlink" commands. These commands are very useful for locating file locations, performing file operations and management. Hope the above content can be helpful to you.

The above is the detailed content of How to view the absolute path of a file in Linux. 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!