LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 08-03-2004, 01:22 PM   #1
chunky
LQ Newbie
 
Registered: May 2004
Posts: 3

Rep: Reputation: 0
Date interrogation for files created


Hi,

I have a file which is called upon in one of my scripts.
Which is called fileA.

This file calls upon other files in our structure, one of these is fileB.

Is their a command in linux that will let me compare the date stamp of fileA to fileB.

Also if fileB is greater than fileA, then I action my command, if it is less than or equal to fileA, it skips to the next file?

I have manged so far to be able to isolate the file creation date, but now I am a bit stuck as to how to compare them and action my command.

# !bin/tcsh -x
set m=`ls -tr /files/| tail -1`
date +%d%m%y%T --reference='fileA'
date +%d%m%y%T--reference="/files/$m"
This gives me the output
03080409:15:24 - (FileA)
03080415:14:25 -(FileB)

As stated above, is it possible to compare these dates, and action if FileB is > than fileA.

Or is there a more simply way?

Any help much appreciated

Matt.
 
Old 08-03-2004, 02:08 PM   #2
Muzzy
Member
 
Registered: Mar 2004
Location: Denmark
Distribution: Gentoo, Slackware
Posts: 333

Rep: Reputation: 30
Probably not the sort of answer you are looking for but...

Sounds like this is exactly what make does? Perhaps use a makefile? Make defines a set of targets, the files that it depends on, and rules for creating the targets if one or more of the dependencies becomes newer than the target. It is fairly straightforward to write makefiles, syntax is:

target : dependency
[TAB]command

Plenty of websites decribing it, here's one picked from google's search results:

http://www.wlug.org.nz/MakefileHowto

Obviously this won't help you at all if you don't have make installed, in which case I am sorry!

Hope this helps,
Mark.
 
Old 08-03-2004, 04:31 PM   #3
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,805

Rep: Reputation: 324Reputation: 324Reputation: 324Reputation: 324
Here's a sample of code I used in a bash script I had to write for a Linux course. The user is required to enter to enter file names for comparison of several things, among others, the file creation times. $1 is the first filename entered on the command line; $2 is the second.

# which file is newer?
if test $1 -nt $2 ; then
echo "'$1' is newer than '$2'"
elif test $2 -nt $1 ; then
echo "'$2' is newer that '$1'"
else
echo "'$1' and '$2' were created at the same time."
fi

where nt means 'newer than' in bash speak.

You should be able to adapt this by replacing the echo statements with appropriate actions.

Last edited by bigrigdriver; 08-03-2004 at 04:35 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
removing last created files Prasun1 Linux - General 7 09-25-2005 08:31 PM
can ogg-files be created during recording? Li... Linux - Software 2 08-25-2004 04:52 PM
If I delete files are new ones created?? BajaNick Linux - Software 1 07-07-2004 12:07 AM
Permission for files created in NT for Linux use strik3r Linux - General 1 02-25-2004 05:05 AM
how are /dev files created? jkobrien Linux - Hardware 3 10-17-2003 07:42 AM


All times are GMT -5. The time now is 05:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration