LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 12: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, 01: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, 03:31 PM   #3
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
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 03:35 PM.
 
  


Reply



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 07:31 PM
can ogg-files be created during recording? Li... Linux - Software 2 08-25-2004 03:52 PM
If I delete files are new ones created?? BajaNick Linux - Software 1 07-06-2004 11:07 PM
Permission for files created in NT for Linux use strik3r Linux - General 1 02-25-2004 04:05 AM
how are /dev files created? jkobrien Linux - Hardware 3 10-17-2003 06:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:49 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
Open Source Consulting | Domain Registration