List files over a specific size in current directory and all subdirectories List files over a specific size in current directory and all subdirectories unix unix

List files over a specific size in current directory and all subdirectories


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

the first part of this is identical to @sputnicks answer, and sucesffully finds all files in the directory over 10k (don't confuse k with K), my addition, the second part then executes ls -lh or ls that lists(-l) the files by human readable size(-h). negate the h if you prefer. of course the {} is the file itself, and the \+ is simply an alternative to \;

which in practice \; would repeat or:

ls -l found.file; ls -l found.file.2; ls -l found.file.3

where \+ display it as one statement or:

ls -l found.file found.file.2 found.file.3

more on \; vs + with find

Additionaly, you may want the listing ordered by size. Which is relatively easy to accomplish. I would at the -s option to ls, so ls -ls and then pipe it to sort -n to sort numerically

which would become:

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

or in reverse order add an -r :

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

finally, your title says find biggest file in directory. You can do that by then piping the code to tail

find . -size +10k -exec ls -ls {} \+ | sort -n | tail -1 would find you the largest file in the directory and its sub directories.

note you could also sort files by size by using -S, and negate the need for sort. but to find the largest file you would need to use head so

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

the benefit of doing it with -S and not sort is one, you don't have to type sort -n and two you can also use -h the human readable size option. which is one of my favorite to use, but is not available with older versisions of ls, for example we have an old centOs 4 server at work that doesn't have -h


Try doing this:

find . -size +10k -ls

And if you want to use the binary ls :

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


I realize the assignment is likely long over. For anyone else:

You are overcomplicating.

find . -size +10k