How can I get a recursive full-path listing, one line per file?

Viewed 714190

How can I get ls to spit out a flat list of recursive one-per-line paths?

For example, I just want a flat listing of files with their full paths:

/home/dreftymac/.
/home/dreftymac/foo.txt
/home/dreftymac/bar.txt
/home/dreftymac/stackoverflow
/home/dreftymac/stackoverflow/alpha.txt
/home/dreftymac/stackoverflow/bravo.txt
/home/dreftymac/stackoverflow/charlie.txt

ls -a1 almost does what I need, but I do not want path fragments, I want full paths.

26 Answers

ls -ld $(find .)

if you want to sort your output by modification time:

ls -ltd $(find .)

Recursive list of all files from current location:

ls -l $(find . -type f)

The realpath command prints the resolved path:

realpath *

To include dot files, pipe the output of ls -a to realpath:

ls -a | xargs realpath

To list subdirectories recursively:

ls -aR | xargs realpath

In case you have spaces in file names, man xargs recommends using the -o option to prevent file names from being processed incorrectly, this works best with the output of find -print0 and it starts to look a lot more complex than other answers:

find -print0 |xargs -0 realpath

See also Unix and Linux stackexchange question on how to list all files in a directory with absolute path.

If you have to search on big memory like 100 Gb or more. I suggest to do the command tree that @kerkael posted and not the find or ls.

Then do the command tree with only difference that, I suggest, write the output in the file.

Example:

tree -fi > result.txt

After, do a grep command in file using a pattern like grep -i "*.docx" result.txt so you not lose a time and this way is faster for search file on big memory.

I did these commands on 270GB memory that I get a file txt taken 100MB. Ah, the time that taken for command tree was 14 minutes. enter image description here

Related