How can I sort by file size the results of the find command?
I trying to sort the result of this find command:
find ./src -type f -print0
I don't want the size of directories, I need the files relative paths sorted by size only.
The ls command is one of the most basic commands in Linux, and it is used to list the contents of a directory. By default, the ls command sorts files alphabetically, but you can also use it to sort files by size, by date, or by other attributes.
With right-click sort Another way to sort files in a given folder is by right-clicking on the body of the folder. A pop-up will appear. Here, click on “Sort by -> Size.” The files will be sorted accordingly.
Here is how to do using find
command:
find . -type f -exec ls -al {} \; | sort -k 5 -n | sed 's/ \+/\t/g' | cut -f 9
Here is how to do using recursive ls
command:
ls -lSR | sort -k 5 -n
Or, if you want to display only file names:
ls -lSR | sort -k 5 -n | sed 's/ \+/\t/g' | cut -f 9
find -type f -exec du -sm {} \; | sort -nk1
Size in MiB, path is relative.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With