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/
952528940 /home/user/
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-
39745960 /home/user/
39666344 /home/user/
35915371 /home/user/.cpan/Metadata
19215803 /home/user/
18731756 /home/user/
17078501 /home/user/
15113371 /home/user/
14570300 /home/user/
14531204 /home/user/
13022550 /home/user/

You Might Also Like

Leave a Reply

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