12

Disk usage/free space script

 4 years ago
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.
neoserver,ios ssh client

Disk usage/free space script

Disk info

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.

Raw
#!/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.

Tagged: Linux, bash.

You can follow the discussion with the comment feed for this post.


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK