1846594 Members
2431 Online
110256 Solutions
New Discussion

Re: diff file size

 
haeman
Frequent Advisor

diff file size

I have two directory that want to find their difference , I use the command "diff" could find the difference when the file is not exist , now if I want to also check the size of the file , that mean if tthe size is not the same , then report the error , what can i do ? thx

$ls dir1
-rwxrwxrwx 1 root root 10 Sep 9 11:02 file1

$ls dir2
-rwxrwxrwx 1 root root 20 Sep 9 11:02 file1
3 REPLIES 3
Prashanth Waugh
Esteemed Contributor

Re: diff file size

Hi haeman,

cksum file1
cksum file2

Check the man pages for cksum.

Regards
Prashnat
For success, attitude is equally as important as ability
haeman
Frequent Advisor

Re: diff file size

thx reply ,

cksum seems good , but it only check the file size difference , but I would like to have the alert when the file size is not match and if the file is not exist in either direcotry , can advise the method ? thx
Ollie Rowland
Frequent Advisor

Re: diff file size

Hi,

What about:
find dir1 -type f | sort | while read FILE
do
SIZE=`ls -l $FILE | awk '{print $5}'`
echo $FILE#$SIZE
done > dir1.lst

find dir2 -type f | sort | while read FILE
do
SIZE=`ls -l $FILE | awk '{print $5}'`
echo $FILE#$SIZE
done > dir2.lst

sdiff -s dir1.lst dir2.lst