File modification time comparison


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File modification time comparison
# 1  
Old 03-29-2010
Java File modification time comparison

Hi All,

I have two files (given below) each exists under different paths. I want to compare the modification time stamp of file1.txt is lessthan the modification time of file2.txt.

Quote:
-rw-r----- 1 athang staff 166 Feb 15 00:03 file1.txt
-rw-r----- 1 athang staff 306 Feb 15 00:03 file2.txt
Code:
  month1=`ls -l file1.txt | awk '{ print $6}'`
  date1=`ls -file1.txt | awk '{ print $7}'`
  time1=`ls -lfile1.txt | awk '{ print $8}' | cut -f 1 -d ":"`

  month2=`ls -l file2.txt | awk '{ print $6}'`
  date2=`ls -l file2.txt | awk '{ print $7}'`
  time2=`ls -l file2.txt | awk '{ print $8}' | cut -f 1 -d ":"`

i thought of perform the comparision by checking the month1 is lesser than month2, but what i have here is String (in which i dont know anyway to perform lessthan operations). I can use a case statement and assign the 1,2 ... 12, like case $month1; Jan) month1final=1 and case $month2; Jan) month2final=1 .. etc. then now i can do lessthan operation.

Is there any simple solution to compare the modification time of two files. Please provide your thoughts. Let me know if i am not clear.
# 2  
Old 03-29-2010
Could you not use the test -ot and -nt options?

i.e.
Code:
       file1 -nt file2
            True if file1 is newer than file2.
       file1 -ot file2
            True if file1 is older than file2.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Getting files through find command and listing file modification time upto seconds

I have to list the files of particular directory using file filter like find -name abc* something and if multiple file exist I also want time of each file up to seconds. Currently we are getting time up to minutes in AIX is there any way I can get file last modification time up to seconds. (4 Replies)
Discussion started by: Nitesh sahu
4 Replies

2. Programming

File date/time modification and permissions

First, oh great Unix gurus, forgive if this is a stupid question. Unix/Linux is not my main thing but I have been programming in C/C++ for many years. I will do my best to be specific. I have a program in C/C++ that needs to modify the time of a given file. Currently I do this using utime()... (5 Replies)
Discussion started by: Pug
5 Replies

3. Shell Programming and Scripting

How to change modification time of file?

Explain it with proper e.g (4 Replies)
Discussion started by: sidpatil
4 Replies

4. UNIX for Dummies Questions & Answers

Need Modification Time of a file

Hi all, I need the modification time of a file on a particular day say 3 days before. I just don't want the last modification time. I need all the modification times on a particualar day. Is there anyway to do it? Kindly help. Could anyone tell me where the modification time is stored?... (1 Reply)
Discussion started by: vidhyab
1 Replies

5. Shell Programming and Scripting

Date comparison in file to system time

I have a CSV (comma separated vaule) file whose entries resemble Area,\\ntsvsp02\vmcs\download\files\Areas.dat,1,20090303,0,Import Complete,2009-03-02 04:23:00 Product,\\ntsvsp02\vmcs\download\files\items.dat,1,20090303,0,Import Complete,2009-03-02 04:23:00... (3 Replies)
Discussion started by: zainravi
3 Replies

6. Shell Programming and Scripting

ls -e to find out File modification time in secs

Hi All, I would like to know the file modification time till seconds in Unix. So I tried ls -e and it worked fine. This Solaris 5.10 -rw-rw-r-- 1 test admin 22 Sep 12 11:01:37 2008 test_message But I am not able to run the same command in SOlaris 5.6 and also in AIX/HP Is there... (3 Replies)
Discussion started by: rahulkav
3 Replies

7. Shell Programming and Scripting

Displaying the Last Modification Time of a specific file

How can I get and display the last modification time of a file? in scripting or specifically using Batch file I want this info for me to determine whether an image has been edited or not by using the last modification time and compare it to our stored date of modification. can somebody help... (5 Replies)
Discussion started by: jaque18
5 Replies

8. UNIX for Dummies Questions & Answers

How to change the file modification time of a file on nfs mount point

Hi I am accessing a file on nfs mounted device, after completing using of the file, i am tring to restore the access time and modification times of the file. So i got the previous modified time of the file using stat() function and trying to set the date and time for the file, To set these... (6 Replies)
Discussion started by: deepthi.s
6 Replies

9. UNIX for Advanced & Expert Users

File Time Comparison Question

I want a cron job to fire off every 5 minutes or so to verify that a file in a directory is not more than 15 minutes old (from the current time. If the newest file is more than 15 minutes old, I would fire off an email.. The email part is easy, but I'm having trouble figuring the logic... (2 Replies)
Discussion started by: pc9456
2 Replies

10. UNIX for Dummies Questions & Answers

File modification time

Does anyone know how to display the time with seconds of when a file was last modified. I can get hour & minutes but would also like seconds. --Running AIX (1 Reply)
Discussion started by: edog
1 Replies
Login or Register to Ask a Question