Finding the largest files and directories

This nifty command allows you to built up a list of the largest files and directories:

FS='/';clear;date;df -h $FS; echo "Largest Directories:"; du -hcx –max-depth=2 $FS 2>/dev/null | grep [0-9]G | sort -grk 1 | head -15 ;echo "Largest Files:"; nice -n 19 find $FS -mount -type f -print0 2>/dev/null| xargs -0 du -k | sort -rnk1| head -n20 |awk '{printf "%8d MB\t%s\n",($1/1024),$NF}'

You’ll need to adjust it, depending on which directory you wish to look within. For example, if you’re looking for a list of the largest files and folders in the /home directory, you’d use:

FS='/home';clear;date;df -h $FS; echo "Largest Directories:"; du -hcx –max-depth=2 $FS 2>/dev/null | grep [0-9]G | sort -grk 1 | head -15 ;echo "Largest Files:"; nice -n 19 find $FS -mount -type f -print0 2>/dev/null| xargs -0 du -k | sort -rnk1| head -n20 |awk '{printf "%8d MB\t%s\n",($1/1024),$NF}'
  • 2 Users Found This Useful
Was this answer helpful?

Related Articles

You may be familiar with ClamAV and Maldet (aka Linux Malware Detect). They're widely known as two excellent choices for identifying malware. What you may not realize, however, is that they can be...

Read More ...

On cPanel servers, you may come across the process /usr/local/cpanel/bin/mysqluserstore/usr/local/cpanel/bin/mysqluserstore creates and updates the /var/cpanel/databases/users.db and...

Read More ...

If your server is running cPanel/WHM, simply execute the below commands via SSH (as root):wget http://www.litespeedtech.com/packages/cpanel/lsws_whm_plugin_install.shsh...

Read More ...

If you're like us, you'll want your server's timezone to match your local time to make log management easier. Fortunately, this is easy to do! This guide works perfectly on servers running CentOS...

Read More ...

Speedtest.net, typically used on desktop PCs is also available for Linux systems. Here’s what you need to do: wget -O speedtest-cli...

Read More ...