pryley
7/14/2015 - 10:12 AM

Get size

Get size

#!/bin/bash

THEPATH=${1%/}
THESIZE=$2

if [ -z $THEPATH ];
  then THEPATH="/"
fi

[[ -n "$2" ]] || { echo -en "\n usage: getsize [path] [size (the min size in Mb)]\n example: getsize ~/Downloads 13\n\n"; exit 0 ; }

function show_indicator {
  i=1
  echo -en "\n"
  sleep 0.5
  echo -n " Searching"
  while true
  do
    sleep $i
    echo -ne "."
    sleep $i
    echo -ne "."
    sleep $i
    echo -ne "."
    sleep $i
    echo -ne "\b \b"
    sleep $i
    echo -ne "\b \b"
    sleep $i
    echo -ne "\b \b"
  done  
}

function stop_indicator {
  exec 2> /dev/null
  kill $1
}

show_indicator &
pid=$!

trap "stop_indicator $pid; echo -ne '\b\b\b\b\b\b\b\b\b\b\b\b\b\b              \b\b\b\b\b\b\b\b\b\b\b\b\b\b'; rm ~/.getsize; exit" INT TERM EXIT

find $THEPATH -path '/dev' -prune -o -type f -size +${THESIZE}M -print0 | xargs -0 ls -Shlr | awk '{ printf( "%5s : %s\n", $5, substr($0, index($0,$9)) ) }' > ~/.getsize 2>&1
stop_indicator $pid
echo -ne "\b\b\b\b\b\b\b\b\b\b\b\b\b"

if [ -s ~/.getsize ];
  then echo -ne '\n' >> ~/.getsize;
fi

cat ~/.getsize
rm ~/.getsize