I made a post on a similar topic just a few hours ago. ls
is not usually the recommended tool for such things.
Using the same looping technique as I posted before, this would be safer, if a bit longer.
for file in *; do
[[ ! -f $file ]] && continue
size=$( stat -c "%s" $file )
if (( size > lsize )); then
echo "Largest file: $biggest [$lsize bytes]"
Replace the echo
at the end with rm
and you're set.