User Tools

Site Tools


largest_files

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
largest_files [2015/05/05 11:24] luke7858largest_files [2024/05/23 07:26] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====Largest files in file system==== ====Largest files in file system====
 +Quickly check the log file size:
 +<sxh bash>
 +du -sh /var/log
 +</sxh>
 +Quickly check the home directory of a user:
 +<sxh bash>
 +du -sh /home/rack
 +</sxh>
 +\\
 +----------------------------------------------
 +=== NEW IMPROVED ===
  
 +one-liner (also checked for open (Deleted) files).
 +\\
 +Change the "/" in filesystem="/" to analyse another filesystem
 +<sxh bash>
 +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"
 +</sxh>
 +\\
 +---------------------------------------------------
 +=== List Open Deleted Files ===
 +Print a list of all the deleted open files in MB:
 +<sxh bash>
 +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 ;
 +</sxh>
 +\\
 +------------------------------------------------
 +Show a break down of the system usage:
 <sxh bash> <sxh bash>
 FS='/';NUMRESULTS=20;resize;clear;date;df -h $FS; echo "Largest Directories:";\ FS='/';NUMRESULTS=20;resize;clear;date;df -h $FS; echo "Largest Directories:";\
Line 9: Line 36:
 </sxh> </sxh>
 \\ \\
-Excluding a specific directory: +=== Excluding a specific directory: === 
 +Following shows the largest directories excluding /var/lib/mysql
 <sxh bash>FS='/';NUMRESULTS=20;resize;clear;date;df -h $FS; echo "Largest Directories:";\ <sxh bash>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",\ du --exclude /var/lib/mysql -x $FS 2>/dev/null| sort -rnk1| head -n $NUMRESULTS| awk '{printf "%d MB %s\n",\
 $1/1024,$2}' </sxh> $1/1024,$2}' </sxh>
 +\\
 === Other Command: === === Other Command: ===
  
  
 <sxh bash>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;</sxh> <sxh bash>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;</sxh>
 +\\
 + 
 +\\
 +--------------------------------------------------
 +=== INODES ===
 +
 +<sxh bash>
 +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
 +</sxh>
largest_files.1430825046.txt.gz · Last modified: 2024/05/23 07:26 (external edit)

Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain
Public Domain Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki