Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recursive sorted file list (Linux)

Tags:

file

linux

find

I want to recurse through a directory, including in subdirectories and subdirectories of those and so on, printing out only file names (no directories). I would also like to have the results on a new line each and sorted.

Please note that ls -LR or ls -xLR doesn't work as ls formats the result into a sort of table.

How can it be achieved?

like image 690
Jack Avatar asked Oct 23 '25 02:10

Jack


1 Answers

Go to the directory you want to search in, and run:

find . -type f -exec basename {} \; | sort

Sorted by name, just filenames (no paths), and just files (no directories).


Details:

  • find works recursively, by default.
  • -type f will print only files, not directories.
  • -exec basename runs basename on the results (so paths are not printed).
  • sort will sort the results (D'Oh!)
like image 131
jimm-cl Avatar answered Oct 25 '25 07:10

jimm-cl