Commands.page Logo

How to List All Files with Absolute Paths in Ubuntu

Managing files in Ubuntu often requires knowing the exact location of data within the filesystem. This guide demonstrates the specific terminal commands needed to list every file in a directory alongside its full absolute path. You will learn how to use standard tools like find and ls to generate complete path lists efficiently.

Using the Find Command

The most reliable method to list all files with their absolute paths is using the find command. This tool searches directory trees and prints the full path for every file it encounters.

To list all files in the current directory and its subdirectories, open your terminal and run:

find $(pwd) -type f

If you want to search a specific directory instead of the current one, replace $(pwd) with the target path:

find /home/user/documents -type f

The -type f flag ensures that only files are listed, excluding directories from the output.

Using LS with PWD

For a non-recursive list that shows only the items directly inside the current directory, you can combine ls with the PWD environment variable. This prints the absolute path of the current working directory before the filename.

Run the following command:

ls -d $(pwd)/*

This command echoes the full path of the current directory and appends each filename to it. Note that this will list both files and directories within that specific folder.

Using Realpath

If you have a list of relative paths and need to convert them to absolute paths, the realpath command is useful. You can combine it with ls to achieve the desired output.

ls | xargs -I {} realpath {}

This takes the output of ls, passes each filename to realpath, and prints the absolute version. This method works best when you are already inside the target directory.

Summary

For most use cases, the find $(pwd) -type f command is the recommended approach. It is recursive, accurate, and explicitly targets files rather than directories. Use the ls method only when you need a quick view of the immediate contents without searching subfolders.