Operating System - HP-UX
1829683 Members
4723 Online
109992 Solutions
New Discussion

test to compare timestamp on files

 
SOLVED
Go to solution
KapilRaj
Honored Contributor

test to compare timestamp on files

Folks,

Is there any option to "test" command , which will find out , one of the input files is older to the other.

Eg: test (@$$ option which i am not aware) file1 file2

If RC is 1 file2 is older than file1 or else vice-versa

I am stuck in between a script. If any one could help me out.

Please explain to me with an example...

Thanks

kaps
Nothing is impossible
4 REPLIES 4
KapilRaj
Honored Contributor

Re: test to compare timestamp on files

Great !!! It is done

Thanks

kaps
Nothing is impossible
KapilRaj
Honored Contributor

Re: test to compare timestamp on files

no idea how my comments are seen above them ?
Nothing is impossible
Rodney Hills
Honored Contributor
Solution

Re: test to compare timestamp on files

How about-

if [ /file1 -ot /file2 ] ; then
echo "file1 older than file2"
else
echo "file1 not older than file2"
fi

Do a man test to find out more. Their is a "-nt" option available to test for newer.

HTH

-- Rod Hills
There be dragons...
Michael Tully
Honored Contributor

Re: test to compare timestamp on files

From the ksh man page:

File1 -nt File2 - True, if File1 exists and is newer than File2.

File1 -ot File2 - True, if File1 exists and is older than File2.

if [ -nt $file1 ]
then
echo $file1 is younger
else
echo $file1 does not exist
fi



Anyone for a Mutiny ?