Linux Commandline Tips #1: Listing the top 20 largest directories from your current directory

in #linux7 years ago (edited)

Background

For a long time, I've been looking for somewhere to post a small number of bash scripts I've borrowed/hacked from various places online, and Steemit seems to be the most natural place to create a repository of short, but useful scripts that I use on a daily basis.

Today's Script

This script lists the top 20 directories from your current directory downwards, in terms of size.

Why might this be important?

Simple answer: if you manage/own a hard drive or web server (I manage a few VPS servers), then you want a quick way to see which directories have become bloated, and delete unwanted files accordingly.

Webservers can particularly get full, quickly, if there are various backup scripts running.

Here's the Script:

du -h . | sort -nr| grep [0-9]M | head -20

Normally, I'll put this into a file in /usr/local/bin, as follows:

sudo echo "du -h . | sort -nr| grep [0-9]M | head -20" > /usr/local/bin/whatsup

sudo chmod +x  $!

The above commands enable me to use this command:

whatsup

...to list those top 20 offending bloated directories.

So there you go: a simple script to quickly enable me to track down bloated directories, so I can then dive in, and remove backup files that haven't yet been deleted automatically.

Hope that helps!

Dez.

Author BIO

Dez Futak is a serial entrepreneur who helps local businesses & individuals increase their cashflow. For more details, see the Services menu at DezFutak.com

Sort:  

Congratulations @dezfutak! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You got your First payout

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

Upvote this notification to help all Steemit users. Learn why here!

Coin Marketplace

STEEM 0.21
TRX 0.20
JST 0.034
BTC 90550.95
ETH 3108.45
USDT 1.00
SBD 2.92