Linux diskspace check terminal

Linux disk space check.

linux

When a disk is running out of space on your system, it is nice to have a quick way to check what directories / files are using the most amount of that space in order to try clear things up a bit.

Here is a bash script that can be used for this purpose: 

#!/bin/bash
echo "Which directory do you need to check? (Use / for root directory)"
read FS
echo "How many results would you like to display? (20 is usually enough)"
read NUMRESULTS
time {
resize;\
clear;\
echo -e "\nLargest Files and Directories:\n==============================\n";\
echo -e "Report Generated: `date`\n";\
df -h $FS; \
echo -e "\nLargest Directories:\n====================\n"; \
du -x $FS 2>/dev/null| sort -rnk1| head -n $NUMRESULTS | awk '{printf "%d MB %s\n",\
$1/1024,$2}';\
echo -e "\nLargest Files:\n==============\n";\
nice -n 19 find $FS -mount -type f -ls \
2>/dev/null| sort -rnk7| head -n $NUMRESULTS |awk '{printf "%d MB\t%s\n",\
($7/1024)/1024,$NF}';\
echo -e "\nReport Finished: `date`\n"
}

If there's no disk space available to write the script to or just an easier way to run it, you can execute the following command from the terminal:

source <(curl diskspace.managedcloud.co.za)

Comments

Tags