Displaying Full File Paths
In the Linux file system, it is often necessary to display the full, absolute path of a file or directory. This can be particularly useful when working with scripts, automation, or when sharing file locations with others.
Using the ls -l
Command
One way to display the full file path is by using the ls -l
command, which provides a detailed listing of files and directories. The full path is displayed as part of the output, as shown in the example below:
$ ls -l /home/username/Documents
total 8
-rw-r--r-- 1 username username 0 Apr 24 12:34 file1.txt
-rw-r--r-- 1 username username 0 Apr 24 12:34 file2.pdf
drwxr-xr-x 2 username username 4096 Apr 24 12:34 folder1
In this example, the full path to each file and directory is displayed, starting from the root directory (/
).
Using the pwd
Command
Another way to display the full file path is by using the pwd
(Print Working Directory) command. This command prints the absolute path of the current working directory, which can be useful when you need to know the current location in the file system.
$ pwd
/home/username/Documents
Using the realpath
Command
The realpath
command can also be used to display the full, absolute path of a file or directory. This command resolves any symbolic links or relative paths and returns the canonical, absolute path.
$ realpath file1.txt
/home/username/Documents/file1.txt
Understanding how to display full file paths is essential for effectively navigating and managing the Linux file system, especially when working with scripts, automation, or when communicating file locations to others.