Linux finding largest files in directory recursively – find,sort,head

Linux Find command is used to search and locate the list of files and directories based on conditions you specify that match the arguments.

The procedure to find the largest files in a directory recursively using find command is as follows:

  1. Open the terminal application
  2. Login as the root user using the “sudo -s” command (required if you want to check all files including from another user / root privilege files)
  3. Type the below mentioned command and press enter
    1. “find” command will list out all files in directly recursively
    2. “sort” will sort out the output by file size (High to Low) of find command
    3. “head” will only show top 20 largest file

Command for finding largest files in directory recursively

sudo find / -type f -printf "%s %p \n" | sort -nr | head -20

Sample Output:

user@gtechhub:~$ sudo find /home -type f -printf "%s %p \n" | sort -nr |  head -20
[sudo] password for user:
1277783550 /home/user/file1.zip
952528940 /home/user/file2.zip
76992513 /home/user/temp/scene.mkv
68116480 /home/user/test/phantomjs-2.1.1-linux-x86_64.tar
67932064 /home/user/test/phantomjs-2.1.1-linux-x86_64/bin/phantomjs
65886387 /home/user/test/file3.tar.gz
65886387 /home/user/file4.tar.gz
65886150 /home/user/file5_htdocs.tar.gz
45072792 /home/user/file6.tar
39779568 /home/user/incubator-pagespeed-ngx-1.13.35.1-beta/psol/lib/Release/linux/x64/pagespeed_automatic.a
39745960 /home/user/file7.zip
39666344 /home/user/file8.zip
35915371 /home/user/.cpan/Metadata
19215803 /home/user/file9.zip
18731756 /home/user/file10.zip
17078501 /home/user/file11.zip
15113371 /home/user/file12.zip
14570300 /home/user/file13.zip
14531204 /home/user/file14.zip
13022550 /home/user/file15.zip

You Might Also Like

Leave a Reply

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