@HMW Your code is very like mine although I used:
fileSize=$(stat -c "%s" -- "$f")
This guards against a filename starting with a hyphen character that would otherwise be interpreted as an option to 'stat'.
Also, the output can be made a little prettier by using 'printf' instead of 'echo'.
printf "%-70s %10d\n" "$f" "$fileSize"
Other potential improvements include:
- checking that $1 is actually less than $2
- allowing $1 and $2 to take a suffix such as K,M,G to allow for kilobyte, megabyte and gigabyte to be easily specified
- allowing for recursion into sub-directories
- and, of course grail's comment in post #15
@keefaz - Nice perl one liner! However a robust script needs some error checking.