on Tue, Jul 17, 2001 at 09:14:17PM +0100, bsamuels@datamansys.co.uk scribbled:
Is it possible to compare the sizes of two files from within a Bash script? I don't need to know the actual sizes just which one is the bigger file.
not optimal, but it works and is relatively clear..
file1=/etc/profile file2=/etc/passwd if [ ! -f "$file1" ] then echo "$file1 does not exist" exit else if [ ! -f "$file2" ] then echo "$file1 does not exist" exit fi fi file1size=`wc -c "$file1" | awk '{print $1;}'` file2size=`wc -c "$file2" | awk '{print $1;}'`
if [ "$file1size" -gt "$file2size" ] then echo "$file1 is bigger" else if [ "$file1size" -lt "$file2size" ] then echo "$file1 is smaller" else echo equal sizes fi fi