Linux large file search

April 12, 2018 | 1 Minute Read

In this post, we will see how to list largest files or directories in linux.

du -aBM 2>/dev/null | sort -nr | head -n 50 | more
  1. du arguments:
    -a for “all” files and directories. Leave it off for just directories
    -BM to output the sizes in megabyte (M) block sizes (B)
    2>/dev/null - exclude “permission denied” error messages (thanks @Oli)

  2. sort arguments: -n for “numeric”
    -r for “reverse” (biggest to smallest)

  3. head arguments:
    -n 50 for the just top 50 results.

  4. Leave off more if using a smaller number
    Note: Prefix with sudo to include directories that your account does not have permission to access.

Example showing top 10 biggest files and directories in </b>/var</b> (including grand total).

cd /var
sudo du -aBM 2>/dev/null | sort -nr | head -n 10
7555M   .
6794M   ./lib
5902M   ./lib/mysql
3987M   ./lib/mysql/my_database_dir
1825M   ./lib/mysql/my_database_dir/a_big_table.ibd
997M    ./lib/mysql/my_database_dir/another_big_table.ibd
657M    ./log
629M    ./log/apache2
587M    ./log/apache2/ssl_access.log
273M    ./cache

####Original Posting [AskUbuntu] https://askubuntu.com/questions/36111/whats-a-command-line-way-to-find-large-files-directories-to-remove-and-free-up