Operating System - HP-UX
1833522 Members
2978 Online
110061 Solutions
New Discussion

Script to find latest verison of a file in 2 seperate directories

 
Joe Bruno
Occasional Contributor

Script to find latest verison of a file in 2 seperate directories

I'm trying to compare files from 2 different directories. I want a simple script that would produce the file or directory that has the latest timestamp. How can this be done?

Thanks
4 REPLIES 4
Simon Waters_1
Occasional Advisor

Re: Script to find latest verison of a file in 2 seperate directories

Files can be compared with a simple test statement.

if [ file1 -nt file2 ]
then

fi

Never tried to use it on directories.

If what you are trying to do is quite complex, look at the make command. It isn't just for making programs.
CHRIS_ANORUO
Honored Contributor

Re: Script to find latest verison of a file in 2 seperate directories

Try this command: "find . -name filename -atime -n"

Read online manual for find.

Cheers!
When We Seek To Discover The Best In Others, We Somehow Bring Out The Best In Ourselves.
Paul Bouchie
Occasional Advisor

Re: Script to find latest verison of a file in 2 seperate directories

Create a file with the desired time stamp ( time_stamp ):

# touch -t 200006070000 time_stamp

then:

# find . -newer time_stamp -print
42
Scott D. Allen
Regular Advisor

Re: Script to find latest verison of a file in 2 seperate directories

the test is [ file1 -nt file2 ]

try this script

fcomp:

#!/usr/bin/ksh
if [ $# -ne 2 ]
then
echo "Error: Usage: fcomp file1 file2"
file1=$1
file2=$2

if [ $file1 -nt $file2 ]
then
echo "$file1 is newer than $file2"
fi
"Sometimes the devil you know is better than the devil you don't know."