to write a script to compare the file size in the current directory and previous dir

hi,

i am new to this site.

i want to write a script to compare the file size of the files in the current dir with the files in the previous directory.

the files name will be same, but the filename format will be as xyzddddyymm.txt. the files will arrive with the month end date(i want to compare the monthly files). so can anybody help me to find a solution for this.

Any help would be greatly appreciated!

#!/bin/sh

FILE="xyzddddyymm.txt"

SIZES=( $(stat "--printf=\t%s" "${FILE}" "../${FILE}") )

if [[ "${SIZES[0]}" -gt "${SIZES[1]}" ]]
then
        echo "${FILE} > ../${FILE} by $((SIZES[0]-SIZES[1])) bytes"
elif [[ "${SIZES[1]}" -gt "${SIZES[0]}" ]]
then
        echo "../${FILE} > ${FILE} by $((SIZES[1]-SIZES[0])) bytes"
else
        echo "${FILE} and ../${FILE} are the same size"
fi

Hi Thanks much for your response.

i need one more help.

But i am having 4 files in the current directory and 4 files in the previous dir.

the file names will be same in both the dir, but with different dates. How can i compare all the files in this situation.

can you please help me in this?

try diff:

[user@host ~]$ diff ./dirA ./dirB

or if you want to test file by file:

[user@host ~]$ for F in ./dirA/*; do diff ./dirA/${F} ./dirB/${F}; done

hi,

the file names will be same in both the dir, but with different dates. How can i compare the file size of all the files in tis.

can you please help me in this?

Repeat the above examples four times, with different dates? If that's not it, then a clearer explanation may be needed.