Finding large files in linux

Posted by & filed under Linux.

Here’s a bash script to do it:

# if nothing is passed to the script, show usage and exit
[[ -n "$1" ]] || { echo “Usage: findlarge [PATHNAME]“; exit 0 ; }
# simple using find, $1 is the first variable passed to the script
find $1 -type f -size +100000k -exec ls -lh {} \; | awk ‘{ print $9 “: ” $5 }’

Save the file (ex: and then make it executable with the following command:

chmod a+x

Now run the script and send any output to a new file (largefiles.txt):

./ / > largefiles.txt &

Also compare these extra notes:

Find reports errors when it searches directories for which it has no permissions. To discard these errors, redirect stderr to /dev/null:

find / -type f -size +20000k -exec ls -lh {} \; 2> /dev/null | awk '{ print $NF ": " $5 }'

Ssort (numerically) based on the size (second column):

find / -type f -size +20000k -exec ls -lh {} \; 2> /dev/null | awk '{ print $NF ": " $5 }' | sort -nrk 2,2

Also here’s some other misc bits:

find / -mtime -7 -size 10M

Find files modified in the last seven day of size 10MB and over.


Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>