Computing.Net > Forums > Unix > Compare 2 files inode modification

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Compare 2 files inode modification

Reply to Message Icon

Name: gptavares
Date: December 19, 2003 at 12:20:51 Pacific
OS: UnixWare 7.1.1
CPU/Ram: 320 RAM
Comment:

I need to compare too files in two different directories if the one on DIR1 is newer then the one of DIR2 then I need to move it to DIR2. E.I check if /dir1/file1 is newer the /dir2/file2 if yes then move /dir1/file1 to /dir2/file2 else remove /dir1/file1.

This is what I've tried so far but is not working very well.

if [ /dir1/file1 -nt /dir2/file2]
then
mv /dir1/file1 /dir2
else
rm -f /dir1/file1
fi

Please someone help!!!

Thanks!



Sponsored Link
Ads by Google

Response Number 1
Name: Dlonra
Date: December 22, 2003 at 05:24:01 Pacific
Reply:

how do you know that file1 and/or file2 exist when you perform the compare?



0

Response Number 2
Name: gptavares
Date: December 22, 2003 at 06:31:24 Pacific
Reply:

I realy don't check if file1 or file2 exist, in this case they will always be there. My only concern is that file file1 does not overlay file2 if it's older.


0

Response Number 3
Name: shailesh.bhide
Date: December 23, 2003 at 00:48:51 Pacific
Reply:

Do this,

if [ /dir1/file1 -nt /dir2/file2]
then
mv -f /dir1/file1 /dir2/file2
else
rm -f /dir1/file1
fi


Regards
Shailesh


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


passing awk variables to ... Installing Unix



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Compare 2 files inode modification

Comparing 2 files www.computing.net/answers/unix/comparing-2-files/7690.html

Compare 2 files if it's same r not www.computing.net/answers/unix/compare-2-files-if-its-same-r-not/8196.html

Comparing 2 files columnwise www.computing.net/answers/unix/comparing-2-files-columnwise/8340.html