Skip to content

Instantly share code, notes, and snippets.

@mrl22
Last active August 9, 2023 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrl22/0e46b54cd53f72a47b553cfe4c9acd37 to your computer and use it in GitHub Desktop.
Save mrl22/0e46b54cd53f72a47b553cfe4c9acd37 to your computer and use it in GitHub Desktop.
Display output of repquota in human friendly output, in order of used space. TESTED ON UBUNTU 22.04
#!/bin/bash
# Run repquota and filter the output to get user and space usage information
repquota_output=$(repquota -a | grep ' -- ' | grep -vE 'man |_apt |systemd-|pollinate |syslog |tss |landscape |fwupd-')
# Sort the output by block usage (column 3) in reverse numeric order
sorted_output=$(echo "$repquota_output" | awk '/^[a-zA-Z0-9]/ {print $1 " " $3}' | sort -k2,2nr)
# Function to convert kilobytes to human-readable format
kilobytes_to_human() {
local -r kilobytes="${1:-0}"
if ((kilobytes < 1024)); then
echo "${kilobytes}KB"
elif ((kilobytes < 1024**2)); then
echo "$(bc <<< "scale=2; $kilobytes / 1024")MB"
else
echo "$(bc <<< "scale=2; $kilobytes / 1024^2")GB"
fi
}
# Display the sorted output with human-readable space usage
echo "User Space Used"
echo "----------------------------"
echo "$sorted_output" | while read -r line; do
username=$(echo "$line" | awk '{print $1}')
space_used_kb=$(echo "$line" | awk '{print $2}')
space_human=$(kilobytes_to_human "$space_used_kb")
printf "%-16s %s\n" "$username" "$space_human"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment