[LiNuX] Datum files vergelijken

Pagina: 1
Acties:

  • Zarc.oh
  • Registratie: November 2000
  • Laatst online: 10-05 18:52

Zarc.oh

heeft een HD van 20 YottaByte

Topicstarter
Ik wil onder linux een actie ondernemen op basis van de datum van 2 files, dus iets dergelijks:
if date(file1) > date(file2) ; then doe blabla
Iemand een idee hoe dit moet? ik ben nu al een paar uur aan het zoeken, maar ik kan dus niets vinden... :(

Zoek wat je niet eerder vond


  • deadinspace
  • Registratie: Juni 2001
  • Laatst online: 16-08 16:08

deadinspace

The what goes where now?

code:
1
2
3
4
5
6
7
8
#! /bin/bash

if [ -n $(find ${1} -anewer ${2} -print) ]
then
      echo ${1} is newer than ${2}
else
      echo ${2} is newer than ${1}
fi

  • odysseus
  • Registratie: Augustus 2000
  • Laatst online: 17:20

odysseus

Debian GNU/Linux Sid

Je kunt ook direct het commando 'newer' gebruiken. Vanuit perl (voor alles te gebruiken :P ) doe je dan iets als:
code:
1
2
3
4
5
6
7
8
9
#!/usr/bin/perl
if (`newer file1 file2`)
{
  print "file1 is newer than file2";
}
else
{
  print "file1 is not newer than file2 (and probably older too!).
}

Leven is het meervoud van lef | In order to make an apple pie from scratch, you must first create the universe.