Ubuntu – How to list all files and folders beyond a specified size limit

command linedisk-usage

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?

Best Answer

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

#!/bin/bash

folder="$1"
limit="$2"

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

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