1827595 Members
2743 Online
109966 Solutions
New Discussion

Please Help with script

 
SOLVED
Go to solution
I.Delic
Super Advisor

Please Help with script

I want to make a script.

In this script i want to compare two files.

I want to know which file is older.
Let say :

file_1 and file_2

Thank you in advance

Idriz
3 REPLIES 3
Rodney Hills
Honored Contributor
Solution

Re: Please Help with script

Just do-

if [[ file1 -nt file2 ]] ; then
echo file1 is newer then file2
fi

HTH

-- Rod Hills
There be dragons...
A. Clay Stephenson
Acclaimed Contributor

Re: Please Help with script

The POSIX shell makes this very easy:

if [[ file_1 -ot file_2 ]]
then
echo "file_1 is older than file_2"
fi

There is also a -nt comparison (newer than).
If it ain't broke, I can fix that.
I.Delic
Super Advisor

Re: Please Help with script

thank you