Agnus Dei (jackal) wrote,
Agnus Dei
jackal

Script for finding large files on your system (linux/unix)

2014 Update: Finally have a version I actually like.

 find . -type f -size +1000k ! -name $'*\n*' -exec wc -c {} \; | sort -rn

And exclude directories /proc and /data01 :

  find / -type f -size +1000k ! -name $'*\n*'  -not \( -path "/proc/*" -o -path "/data01/*" \)  -exec wc -c {} \; | sort -rn > /tmp/large-files.out



-------------------------------------------------------------------------------
OLD - WRONG crap below
-------------------------------------------------------------------------------

MY OLD WAYS from 2010:


$ cat find_large_files 
#!/bin/sh

if [ "$1" == "" ]; then
        echo "usage: find_large_files "
        exit
fi

find $1 -type f -size +10000k -exec ls -lh {} \; | awk '{ print $5 ": " $9 }' |sort -rn








Here's a much better way (because time stamps change from "YYYY-MM-DD" to "MMM DD YYYY" from system to system which would screw up the awk, since it's looking for white space):

find /tmp -type f -size +1000k -exec ls -l --time-style=+%Y%m%d {} \; | awk '{ print $5 ": " $7 }' |sort -rn > /tmp/large-files








2011 Update:
1- Here's how to exclude a directory. In this case "/root":

# find / ! -regex "/root.*" -type f -size +10000k -exec ls -l --time-style=+%Y%m%d {} \; | awk '{ print $5 ": " $7 }' |sort -rn > /tmp/large-files 

2- Here's how to ignore two directories (/u and /proc ):

# find / ! \( -regex "/u.*" -o -regex "/proc*" \) -type f -size +500k -exec ls -l --time-style=+%Y%m%d {} \; | awk '{ print $5 ": " $7 }' |sort -rn > /tmp/large-files

Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

  • 4 comments