Ubuntu – Listing files in a directory including contents of subfolders with sorting

command linedirectoryfile sorting

I'm looking to list the entire contents of a directory, including the contents of subfolders but sorted by filesize.
Thus far I've managed to get as far as listing and sorting whilst still being recursive with ls -lhSR(the h is nice to have but definitely not essential for me, as long as I can get file sizes).
I am likely overlooking something obvious, or asking the impossible, but any advice here would be greatly appreciated.

Best Answer

You can use find:

find . -type f -printf "%s %P\n" | sort -n

Optional: To convert byte values to human-readable format, add this:

| numfmt --to=iec-i --field=1

Explanation:

 find in current directory (.) all files (-type f) 

 -printf: suppress normal output and print the following:
     %s - size in bytes
     %P - path to file
     \n - new line

 | sort -n: sort the result (-n = numeric)
Related Question