Skip to content

Instantly share code, notes, and snippets.

@pryley
Created July 14, 2015 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pryley/eb6e74dce9f38e5598b2 to your computer and use it in GitHub Desktop.
Save pryley/eb6e74dce9f38e5598b2 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment