In a partition I have several files and folders, and I can list all those file sizes with du like this:

du -h

But how can I list all the files which are beyond a specific disk space size like 5MB?

  • 3
    Use find find /path -type f -size +5M -exec ls -lh {} \; – Terry Wang Dec 27 '12 at 12:23

Here is a straight-forward solution in bash, which analyzes the size of both files and folders:



for item in `find "$folder"`; do
    size=$(du -s "$item" | cut -f1)
    if [ $size -gt $limit ]; then
        echo $item

first param is the target folder to examine
second param is the limit in kilobytes, where 1K=1024 bytes.

  • hi just now i saw this , i will try and let you know . – rɑːdʒɑ Dec 27 '12 at 12:54
  • well I am getting this errors bro . .Moviz/s.sh: 9: [: -gt: unexpected operator du: cannot access `ter': No such file or directory But things were there actually . I think we need more eye here . – rɑːdʒɑ Dec 27 '12 at 15:23
  • @snow sounds weird, I've tested this script on my ~/Musik folder, where there is plenty of files with spaces and may be some other "unusual" characters in path - all okay. How do you run the script? Have you specified folder and limit arguments? I've not made any checks on them to keep it simple. Your are supposed to run it like this: ./findLargeItems.sh ~/Music 10000. Don't forget to quote path or backslash spaces in it: "/home/user/random folder" or /home/user/random\ folder. I guess you know all this, but just in case. – Pavel A Dec 27 '12 at 16:05
find /home/stephenm/ -maxdepth 1 -size +20k -exec du -h {} \;

That should list anything over 20k in /home/stephenm

to recurse into sub directorys drop the -maxdepth 1 option.

  • Yeah it Nice and working . May I get a way with du also please . – rɑːdʒɑ Dec 27 '12 at 12:21
  • @snow I don't think du can do it on its own I maybe wrong I just looked at the manual. – squareborg Dec 27 '12 at 12:25
  • @snow, see a solution with du (I mean where it is used to analyze size) below, though the solution in Stephen's answer is apparently more elegant - I should definitely read over man find again. – Pavel A Dec 27 '12 at 12:51
  • @snow Wait a minute. If I'm right neither this answer nor Terry's comment take the size of folders into account - they are just for files. – Pavel A Dec 27 '12 at 13:01
  • @pavel A Yes as i have seen its working for files & not working for folders . – rɑːdʒɑ Dec 27 '12 at 13:14

Be careful: du does not print the size of a file, it gives you an estimate of file space usage.

You can create a 10 MB file, which uses much less:

dd if=/dev/zero of=file seek=10M count=1 bs=1
stat -c %s file
ls -lh file
du -h file
cat file | wc

An example is a compressed file that uses less space on disk that its size, of like the example above a sparse file.

In the example above, find . -type f -size +5M will output file even if du is much less than 5M.

If you know you do not have newlines in your filenames, you can filter the output of find with:

find . -type f -size +5M | while IFS= read -r file; do
  du=$(du -k "$file")
  size="${du%%$(printf "\t")*}"
  if test $size -gt $((5 * 1024)); then
    echo "$file"

If you can have newlines in your filenames, you could use this GNU extension, but then use something else than echo in the loop:

find . -type f -size +5M -print0 | while IFS= read -r -d '' file; do
  du=$(du -k "$file")
  size="${du%%$(printf "\t")*}"
  if test $size -gt $((5 * 1024)); then
    echo "$file"
  • Good point about the actual and apparent file sizes, though I doubt TS has any. B/w, you can view the apparent file size with du as well: du --apparent <file> in which case the reported size will be the same as with ls. – Pavel A Dec 27 '12 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.