Thursday, February 10, 2011

Determine Which Directory is Hogging the most Disk Space

  1.  cd into the mount point directory for the given file system 
  2.  Determine space usage for the subdirectories within the mount point directory: 
    •  du -sm * | sort -nr | head 
      •  if the mount point directory contains subdirectories named as dot files, the "*" pattern won't include them 
      •  if there are many subdirectories, you may want to increase the amount of output produced (eg, perhaps "head -20" instead of the default 10 lines) 
  3.  Examine the output from step (2), and look for directories with disproportionately large sizes. For each one, enter the directory and repeat from step (2) until the source of the problem becomes obvious. 
    • ls -lst --block-size=1M lists files in the directory in: 
      • -l long format 
      •  -s with size blocks of Megabits(--block-size=1M) (-S to sort by size) 
      • -t sorts files according to modification time (newest first) 
    See  Using Find to Delete Files  for tricks on how to delete multiple files at once

    Saturday, January 15, 2011

    Using Find to Delete Files

    1.  All files older than 5 days 
      •  find /path/to/files* -mtime +5 -exec rm {} \; 
    2.  Log files (-type f) older than six months in sub directories 
      •  find /path/to/files/ -mtime +180 -type f -maxdepth 2 -exec rm -rf {} \; 
      •  -type f 
        • log files 
      •  -mtype +180 
        • older than six months 
      •  -maxdepth 2 
        • to a directory level of 2