forked from colin/disk-space-report
Add disk-check.sh
This commit is contained in:
commit
04b184dbae
|
@ -0,0 +1,68 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Function to estimate the size of the apt cache
|
||||||
|
estimate_apt_cache_size() {
|
||||||
|
echo "Estimating the size of the apt cache:"
|
||||||
|
sudo du -sh /var/cache/apt
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to estimate the size of old installed packages
|
||||||
|
estimate_old_packages_size() {
|
||||||
|
echo "Estimating the size of old installed packages:"
|
||||||
|
sudo du -sh /var/lib/apt/lists /var/lib/apt/lists/partial
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to estimate the size of journal logs
|
||||||
|
estimate_journal_size() {
|
||||||
|
echo "Estimating the size of journal logs:"
|
||||||
|
sudo journalctl --disk-usage
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to estimate the size of temporary files
|
||||||
|
estimate_tmp_size() {
|
||||||
|
echo "Estimating the size of temporary files:"
|
||||||
|
sudo du -sh /tmp /var/tmp
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to estimate the size of unused Docker volumes
|
||||||
|
estimate_docker_volumes_size() {
|
||||||
|
echo "Estimating the size of unused Docker volumes:"
|
||||||
|
docker volume ls -qf dangling=true | xargs -I {} docker inspect {} -f '{{ .Name }}: {{ .Size }}' | awk '{ sum += $3 } END { print sum/1024/1024 " MB" }'
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to list directories consuming more than a specified size
|
||||||
|
list_large_directories() {
|
||||||
|
local directory=$1
|
||||||
|
local size_limit=$2
|
||||||
|
echo "Directories in $directory consuming more than $size_limit:"
|
||||||
|
sudo du -ah $directory 2>/dev/null | awk -v limit=$size_limit '{
|
||||||
|
size=$1; unit=substr(size, length(size));
|
||||||
|
size_val=substr(size, 1, length(size)-1);
|
||||||
|
if ((unit=="G" && size_val+0 > limit) || (unit=="T" && size_val*1024 > limit)) {
|
||||||
|
print
|
||||||
|
}
|
||||||
|
}'
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
# Estimate storage savings
|
||||||
|
echo "Estimating potential storage savings..."
|
||||||
|
estimate_apt_cache_size
|
||||||
|
estimate_old_packages_size
|
||||||
|
estimate_journal_size
|
||||||
|
estimate_tmp_size
|
||||||
|
estimate_docker_volumes_size
|
||||||
|
|
||||||
|
# List large directories
|
||||||
|
echo "Listing directories consuming more than 5GB and 10GB:"
|
||||||
|
list_large_directories / 5
|
||||||
|
list_large_directories /home 5
|
||||||
|
list_large_directories / 10
|
||||||
|
list_large_directories /home 10
|
||||||
|
|
||||||
|
echo "Storage savings estimation and large directory listing completed."
|
Loading…
Reference in New Issue