I'm trying to compare the size of two files in shell script but I'm getting a test: 32: 8: unexpected operator error.
I=`wc -c $i | cut -d' ' -f1`
J=`wc -c $j | cut -d' ' -f1`
if test $I == $J
then
echo $i $j >> $1.pares
fi
I test the values in $I and $J using echo and the values are correct but I cant compare them...
Getting file size using find command The syntax is as follows for the find command: find "/etc/passwd" -printf "%s" find "/etc/passwd" -printf "%s\n" fileName="/etc/hosts" mysize=$(find "$fileName" -printf "%s") printf "File %s size = %d\n" $fileName $mysize echo "${fileName} size is ${mysize} bytes."
The stat is a UNIX command-line utility. Stat takes a file as an argument and returns the detailed information about a file/file system. Note: Here, %s is used to fetch the total size of the file, and -c is used for specifying output format i.e. we want to print the total size of the file only.
Another method we can use to grab the size of a file in a bash script is the wc command. The wc command returns the number of words, size, and the size of a file in bytes.
this works on bash
if((`stat -c%s "$file1"`==`stat -c%s "$file2"`));then
echo "do something"
fi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With