

Disk usage/free space script
source link: https://kuttler.eu/code/disk-usagefree-space-script/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Disk usage/free space script
I like to monitor disk usage from the command line using the df utility. However, the output can get overwhelming sometimes depending on the system. This is a tiny bash script I use as a df wrapper that does filtering, sorting and uses colors. It takes an argument nc to disable colors.
#!/bin/bash
__diskfree () {
local COLOR_HI
local COLOR_MD
local COLOR_LO
local COLOR_NC
DF="df -h --output=source,target,fstype,pcent,size,avail -x tmpfs -x devtmpfs -x squashfs -x overlay"
SORT="sort -k 4,4 --numeric-sort --reverse"
if [[ ${1} != "nc" ]]; then
COLOR_HI="\e[0;31m"
COLOR_MD="\e[0;33m"
COLOR_LO="\e[0;32m"
COLOR_NC='\e[0m'
fi
echo -ne "$COLOR_HI"
$DF | grep -E "100%|9[0-9]%" | $SORT
echo -ne "$COLOR_MD"
$DF | grep -E "[78][0-9]%" | $SORT
echo -ne "$COLOR_LO"
$DF | grep -E "[^1][ 0123456][0-9]%" | $SORT
echo -ne "$COLOR_NC"
}
__diskfree $1
Published on Dec. 2, 2020, last update Dec. 5, 2020.
You can follow the discussion with the comment feed for this post.
Recommend
-
12
How to Free Disk Space on MacBook used for Development Updated Jan 5, 2021 2 comments 3 minute read
-
8
duf – Disk Usage/Free Utility for Linux, BSD, macOS & Windows Author: Vivek Gite Last updated: January 16, 2021
-
9
-
6
Introduction If you've ever had to deal with a Linux server that was out of disk space at some point you know that it's important not to run into the same situation again. In most cases, the server can run out of disk space d...
-
7
100% Disk Usage in Windows 10? 17 Tips and Tricks to Fix This Issue By Christian Cawley U...
-
7
How to install ncdu on Linux 🐧 nixCraft → Open Source → How to install ncdu on Linu...
-
3
Improve Article Shell Script to Check Disk Space UsageLast Updated : 20 Apr, 2021Disk usage is a report generated by the Linux system about different disks available or created...
-
12
Analyze Disk usage in Linux with ncduAre you having a hard time trying to audit disk utilization on your Linux system?. I know most Linux sysadmins are accustomed to using du command to check files consuming more disk space or to...
-
4
To make sure your instances are running smoothly we’ve now added the ability to set alarms, based on CPU, Memory usage, and Disk space. These tools can, if enabled, address performance issues promptly and automatically. The alarm trigger whe...
-
14
Session Temporary Tablespaces and Disk Space Usage in MySQL Back to the Blog
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK