Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the largest file in a directory and its subdirectories?

We're just starting a UNIX class and are learning a variety of Bash commands. Our assignment involves performing various commands on a directory that has a number of folders under it as well.

I know how to list and count all the regular files from the root folder using:

find . -type l | wc -l 

But I'd like to know where to go from there in order to find the largest file in the whole directory. I've seen somethings regarding a du command, but we haven't learned that, so in the repertoire of things we've learned I assume we need to somehow connect it to the ls -t command.

And pardon me if my 'lingo' isn't correct, I'm still getting used to it!

like image 657
Rekson Avatar asked Sep 20 '12 23:09

Rekson


People also ask

How do I find the largest file in the current directory and subdirectories in Windows?

Click on “Size” then select the appropriate file size you want to look for. You can search for sizes between 0 KB up to 4 GB or more. After search results appear, right-click on any empty space in the File Explorer and select Sort by → Size → Decreasing. Doing this will place the largest files on top of the list.


1 Answers

Quote from this link-

If you want to find and print the top 10 largest files names (not directories) in a particular directory and its sub directories

$ find . -type f -printf '%s %p\n'|sort -nr|head

To restrict the search to the present directory use "-maxdepth 1" with find.

$ find . -maxdepth 1 -printf '%s %p\n'|sort -nr|head

And to print the top 10 largest "files and directories":

$ du -a . | sort -nr | head

** Use "head -n X" instead of the only "head" above to print the top X largest files (in all the above examples)

like image 54
tamsler Avatar answered Sep 19 '22 19:09

tamsler