List files (greater than a size) in directory and subdirectories via cli on linux


To display all files (for example greater than 50k bytes) in a directory and it’s subdirectories, open a linux shell and type:

find . -size +10k -exec ls -lh {} \+

The ‘h’ parameter list the files by human readable size. The ‘{}’ is the file itself; the ‘\+’ could be replaced with ‘\;’.

Moreover, to list all the files sort by size, just pipe the command with ‘sort -n’:

find . -size +10k -exec ls -ls {} \+ | sort -n

To sort by size, but in reverse order, add the ‘r’ parameter:

find . -size +10k -exec ls -ls {} \+ | sort -nr

Piping the command with ‘tail’ you can find the largest file in the directory and its sub directories:

find . -size +10k -exec ls -ls {} \+ | sort -n | tail -1

Note that to sort you can’t use the ‘h’ parameter. To use it, sort files by using ‘S’ parameter to ‘ls’ command :

find . -size +10k -exec ls -lSh {} \+

In this case, to find the largest file use ‘head’ command:

find . -size +10k -exec ls -lSh {} \+ | head -1

Leave a comment

Your email address will not be published. Required fields are marked *