Date interrogation for files created
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'
This gives me the output
03080409:15:24 - (FileA)
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
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
Plenty of websites decribing it, here's one picked from google's search results:
Obviously this won't help you at all if you don't have make installed, in which case I am sorry!
Hope this helps,
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'"
echo "'$1' and '$2' were created at the same time."
where nt means 'newer than' in bash speak.
You should be able to adapt this by replacing the echo statements with appropriate actions.
|All times are GMT -5. The time now is 05:20 PM.|