User Tools

Site Tools


largest_files

Largest files in file system

Quickly check the log file size:

du -sh /var/log
Quickly check the home directory of a user:
du -sh /home/rack


NEW IMPROVED

one-liner (also checked for open (Deleted) files).
Change the “/” in filesystem=“/” to analyse another filesystem

filesystem="/";BREAK="===============================================================";echo -ne "\n $BREAK \n \t Disk Usage for $filesystem $(date +'%F') \n $BREAK \n\n";df -h $filesystem; echo -e '\n\n Volume Group Usage: \n'; vgs $(df -h $filesystem | grep dev | awk '{print $1}'| cut -d\- -f1| cut -d\/ -f4); echo -e '\n'; echo -e "Largest Folders:\n"; du -xSk $filesystem | sort -rn | head -20|awk '{printf "%d MB\t%s\n",($1/1024),$NF}' && echo -e "\n\n"; echo -e "Largest Files:\n"; find $filesystem -mount -type f -ls|sort -rnk7 |head -20|awk '{printf "%d MB\t%s\n",($7/1024)/1024,$NF}';echo -e "\n\n Open Deleted Files:\n"  ;lsof | grep $filesystem | grep deleted| awk '{ if($7 > 1048576) print $7/1048576, "MB ",$9,$1 }' | sort -n -u | tail; echo -e "\n $BREAK"


List Open Deleted Files

Print a list of all the deleted open files in MB:

lsof | awk '/REG/ && !/stat: No such file or directory/ && !/DEL/ {if ($NF=="(deleted)") {x=3;y=1} else {x=2;y=0}; {print $(NF-x) "  " $(NF-y) } }'  | sort -n -u  | awk '{ print $1/1048576, "MB ", $NF }' | tail -5 | head -5 ;


Show a break down of the system usage:

FS='/';NUMRESULTS=20;resize;clear;date;df -h $FS; echo "Largest Directories:";\
du -x $FS 2>/dev/null| sort -rnk1| head -n $NUMRESULTS| awk '{printf "%d MB %s\n",\
$1/1024,$2}';echo "Largest Files:"; 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}'

Excluding a specific directory:

Following shows the largest directories excluding /var/lib/mysql

FS='/';NUMRESULTS=20;resize;clear;date;df -h $FS; echo "Largest Directories:";\
du --exclude /var/lib/mysql -x $FS 2>/dev/null| sort -rnk1| head -n $NUMRESULTS| awk '{printf "%d MB %s\n",\
$1/1024,$2}' 

Other Command:

echo -e "\n\nHi, \n\nDiskoverview for $(hostname)\n\n $(df -h) \n\nHere is the list of the largest files: \n" ; find / -type f -not -path "/proc/*" -not -path "/dev/*" -not -path "/sys/*" -size +512000k -exec du -hs {} \;  ;  echo -e  "\n\nAnd here is the list of the largest folders:\n"; du -h / | grep ^[1-9][0-9][0-9.]*G | sort -rn;



INODES

nice -n 19 find / -type d 2>/dev/null -print0 | while IFS= read -rd '' i; do echo $(ls -a "$i" | wc -l) "$i"; done | sort -n -r | head

largest_files.txt · Last modified: 2024/05/23 07:26 by 127.0.0.1