Home >Operation and Maintenance >Linux Operation and Maintenance >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.
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
Run the above command, the system will output the full path of the current working directory, for example:
/home/user/Documents
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
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
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
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
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!