Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Csh: how can I find out file1 is newer than file2

126 views
Skip to first unread message

Hung-Fa Sun

unread,
Apr 28, 1993, 8:37:33 PM4/28/93
to
The subject says all, hope this is not FAQ, I could not find
it at FAQ contents.

Thanks for help.
--
Frank Hung-Fa Sun
Computer & Comm. Research Lab. /ITRI
Internet: su...@e0sun3.ccl.itri.org.tw
Voice: (886-035)917255, FAX: 820098

D Gordon

unread,
Apr 30, 1993, 8:23:10 AM4/30/93
to
In <1993Apr29.0...@comserv.itri.org.tw> su...@e0sun3.ccl.itri.org.tw (Hung-Fa Sun) writes:
>
>The subject says all, hope this is not FAQ, I could not find
>it at FAQ contents.

Some shell-independent methods:

find file1 -newer file2 -print

prints "file1" if it is newer than file2, otherwise nothing

ls -t file1 file2

lists the files in timestamp order, newest first
(use ls -tr for oldest first)

To use these in shell scripts, you can test their outputs, eg:

Bourne, etc:
if [ -n "`find file1 -newer file2 -print`" ]
then
...
fi

Csh:
if(`find file1 -newer file2 -print` != "") then
...
endif

Hope this helps!
--
===============================================================================
Dave | d...@imp.co.uk | +44 753 516599 | I calculate; you figure; he guesses.
===============================================================================

Alun

unread,
Apr 30, 1993, 11:18:42 AM4/30/93
to
In article <1993Apr29.0...@comserv.itri.org.tw> su...@e0sun3.ccl.itri.org.tw (Hung-Fa Sun) writes:
> The subject says all, hope this is not FAQ, I could not find
> it at FAQ contents.
>
> Thanks for help.

find filename1 -newer filename2 -print

This will print filename1 only it is newer than filename2

-Alun

--
| *I'm as bad as the worst - but thank God(?) I am as good as the best.* |
| --------------------------------------------------------------------------- |
| A.Champion : cham...@uk.ac.cov.cch (Student account) |
| stl...@uk.ac.cov.cch (Student liaison account) |

0 new messages