Wednesday, September 4, 2013

Bash shell script for finding the largest files or directories.

To find the largest 10 files (linux/bash):

find . -type f -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}

To find the largest 10 directories:

find . -type d -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}

Only difference is -type {d:f}.

1 comment :

  1. i usually just

    find -type f -size +1G -exec ls -sh {} \;

    but here is a good one:

    Sort by date regardless of path

    find . -type f -printf "%-.22T+ %M %n %-8u %-8g %8s %Tx %.8TX %p\n" | sort | cut -f 2- -d ' '

    ReplyDelete