Find big files from a terminal

Find in gigs

$ find / -size +1G -exec ls -l {} \;

or

Find in megs

find / -size +100M -exec ls -l {} \;

Here's a nice little script to find big files

#!/bin/bash

dir=$1;
size=$2;

if [[ $dir == "-h" || $dir == "--help" || $dir == "-H" ]]; then
    echo "Usage: findBigFiles <directory>";
    echo "       findBigFiles <directory> -s";
    echo "       findBigFiles -s";
    echo "       findBigFiles";
    echo "";
    echo " -s Include file size in report.";
    echo "";
    echo "If no directory or option is included, the current directory will";
    echo "be used.";
    echo "";
    echo "If only -s is used, the current directory will be scanned.";
    exit 0;
fi

if [[ $dir != "" && $size == "-s" ]]; then
    size="-s";
else
    size="";
fi

if [[ $dir == "-s" ]]; then
    size="-s";
    dir=".";
else
    size="";
fi

if [[ "${dir}" == "" ]]; then
    dir=".";
fi

function findBigFiles {
    dir=$1;
    if [[ -e $dir ]]; then
        cd $dir;
        ls | while read file; do
            if [[ -e "$file" ]]; then
                num=`find "$file" -type f | wc -l`;
                if [[ $size == "-s" ]]; then
                    echo "${num} `du -sh "${file}"` `pwd`/${file}";
                else
                    echo "${num} `pwd`/${file}";
                fi
            fi
        done
        num=`ls | wc -l`;
        echo "${num} `pwd`";
    fi
}

findBigFiles $dir | sort -g > /tmp/findBigFiles.log;

echo "Have a look at /tmp/findBigFiles.log";

Also See

UNIX-FindingBigFiles

Page Comments (Click to edit)






[Click to add or edit comments])

Please prepend comments below including a date

Design by N.Design Studio, adapted by solidGone.org (version 1.0.0)
Have a nice day.