Last modification date without 'ls'


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Last modification date without 'ls'
# 1  
Old 03-12-2010
Last modification date without 'ls'

Hi, I'm executing a script to check if a file has been modified on a shared folder.
I use this to start another script every time the file has been modified.
To do this I use the 'ls' command to get the last modification date of the file.

My problem is that the computer hosting the shared folder has not the same system time (1 hour less) than the computer on which I'm executing the 'ls' command.
So once the file is modified I only get the year instead of the hour.
I know this is a normal situation as described in the man: "If the modification time of the file is more than 6 months in the past or future, then the year of the last modification is displayed in place of the hour and minute fields."

Then one hour later the 'ls' command give me the hour of the modification because I'm not anymore in the future.
As the 'ls' command returns the hour and not the year, my script considers the time is different and so the file has been modified.
And so my second script is started again (even it's not needed).

Is there a way to force the 'ls' command to always returns the hour? or is there another way to know that a file has been modified?

I'm working on Solaris, HP, AIX and Linux.

Thanks in advance.
# 2  
Old 03-12-2010
This works on any UNIX platform with perl.
https://www.unix.com/shell-programmin...ime-files.html
# 3  
Old 03-12-2010
Please post:

Code:
echo "${TZ}"
date
ls -la /name_of_the_local_directory
ls -la /name_of_the_shared_directory

# 4  
Old 03-12-2010
If you want to find the last modification time of a file, you can use the "stat" function.

Code:
use strict;
use warnings;

my $filename="filename";
  my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks);

  ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($filename);

  system("date -d\@$mtime");

# 5  
Old 03-12-2010
Try:
[May not be available in all *nix flavours]

Code:
stat file | awk -F"[: ]" '/^Modify/ {print $4; }'

# 6  
Old 03-13-2010
Thanks for all the replies, I'll try all this on Monday and let you know.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Subtract a file's modification date with current date

SunOS -s 5.10 Generic_147440-04 sun4u sparc SUNW,SPARC-Enterprise Hi, In a folder, there are files. I have a script which reads the current date and subtract the modification date of each file. How do I achieve this? Regards, Joe (2 Replies)
Discussion started by: roshanbi
2 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

Date Modification

Hello all ! I have a piece of code that generates the date of one day ago: /usr/bin/gdate --date='1 day ago' | awk '{print $2 " " $3}' Nov 3 I want the output to be in the form : Nov 03 What other operation should I do for that ? Help (2 Replies)
Discussion started by: Junaid Subhani
2 Replies

4. UNIX for Dummies Questions & Answers

How do you get the last modification date of a file?

I'm trying to get the date output to be in the form yyyy-mm-dd (e.g. 2013-01-18) !/bin/sh modDate=$(stat -c %y $1) echo $modDate >> $1 When I run this on another file (by typing ./dateScript theFile.txt), I keep getting this message: stat: illegal option -- c What's wrong with my code... (2 Replies)
Discussion started by: Nate18
2 Replies

5. Shell Programming and Scripting

Rename old files with last modification date

Hi everyone, I have files like file1_Mod.txt, file2_Mod.txt. I want to rename the old files with the last modification date. I write the below script to rename with current date, but I donīt know how to use "date -r" to get the last modification date with the same format I have below... (5 Replies)
Discussion started by: cgkmal
5 Replies

6. Solaris

search for date of modification

hi member. i want to know all file in the system which the last date of modification = 14-06-2010 for example what can i do (4 Replies)
Discussion started by: xxmasrawy
4 Replies

7. UNIX for Advanced & Expert Users

Help with sorting files according to modification date

Hi, I was very surprised to not be able to find an answer to this question despite my best efforts in Google and elsewhere. Maybe it's a good thing as it forced me to finally become a member in this great forum that i use frequently. Ok my question: I want to be able to sort files inside a... (3 Replies)
Discussion started by: stavros
3 Replies

8. Solaris

temporary modification of date

Goodmorning, I have a server with solaris 2.6 installed. Is it possible modify system date only temporary that, automatically, after a reboot, I can have again the date after the temporary mofication? I don't want to use "date" command after reboot for tidy up date. I only want to find a... (2 Replies)
Discussion started by: bonovox
2 Replies

9. UNIX for Dummies Questions & Answers

Search by modification date

Hi I'd like to know if is it possible to find files given a certain modification date (say, 01-05-2006, that's 1st of May 2006) I can calculate the days backward: find / -ctime 23 but I wish to search by exact modification day Thanks (5 Replies)
Discussion started by: slink
5 Replies

10. UNIX for Dummies Questions & Answers

command for modification date of a file

Good morning, I would like to find all files of a certain type and display their name as well as their modification date. In order to do this, I would do the following: find ./ -name *.csv | ???????? My question: what to put after the pipe instead of the question marks? Is there a basic... (5 Replies)
Discussion started by: scampsd
5 Replies
Login or Register to Ask a Question