Identify age of the file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Identify age of the file.
# 1  
Old 06-08-2010
Identify age of the file.

Hi all,
I'm using SunOS.
need to find age of the file in terms of seconds. The file
name with its path will be given to the script as input.

Any kinda help will be appreciated.

Thanks in advance
# 2  
Old 06-08-2010
You can get the mtime of a file as unixtime with GNU ls like:

Code:
$ /usr/local/bin/ls -l --time-style=+%s /tmp
total 8
srwxrwxrwx 1 mysql mysql   0 1274881760 mysql.sock
-rw-r--r-- 1 root  root   30 1274881759 ogl_select3820
-rw------- 1 mysql mysql 849 1274881759 sh39510

You can get the current unixtime with perl:

Code:
$ perl -e "print time"
1275980113

The rest is to parse these outputs to find the age of a file in seconds.

GNU ls for Solaris is available from sunfreeware.com in the coreutils package.
# 3  
Old 06-08-2010
thanx hergp,
But i cannot use any tool. i jus need to write a pure script. I'm very new to unix, and i've been told that there are inbuilt functions in Solaris to find Timestamp and then using that i can find out how old is the file.
# 4  
Old 06-08-2010
Solaris ls comes with the -e option which prints the mtime up to the second, but in the format "mmm dd hh:mm:ss yyyy " which makes it harder to parse.

You need to write a shell function or shell script which takes two timestamps, one being the timestamp from ls and one the output of the date command, and then calculate the time difference.
This User Gave Thanks to hergp For This Post:
# 5  
Old 06-08-2010
hi hergp,
I tried browsing man for ls -e, It says no entry for -e...
I understood the logic you gave and will be trying the same, is it possible to extract timestamp of a file in some other fashion..??
# 6  
Old 06-08-2010
The -e switch was not available before Solaris 10.

I don't think there is another Solaris standard command that is capable to give you a files mtime to the second.

If the situation allows perl progamming, then this is probably the best way to go with Solaris preinstalled software to solve this problem.
# 7  
Old 06-08-2010
Code:
$ perl -e "print time"
1275980113

I tried using the above code. And it gives me an error:
Code:
No code specified for -e.

Can some one help me with this..??
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Age of file

Hi All.. Is there any easy way to find out how many days older is file? for ex. fileA 20 days fileB 10 days I am currently on AIX, and there is no STAT command available in this environment. What are my options? Thanks Abhijeet R (1 Reply)
Discussion started by: freakabhi
1 Replies

2. Shell Programming and Scripting

Check age of the file

hi, i am working on a shell script where i have 2 files & i need to check age of those files. one file should be of the same day and other shoudn't be more then 20 days old. how could i acheive this? please help!!!! (10 Replies)
Discussion started by: lovelysethii
10 Replies

3. Shell Programming and Scripting

Compare large file and identify difference in separate file

I have a very large system generated file containing around 500K rows size 100MB like following HOME|ALICE STREET|3||NEW LISTING HOME|NEWPORT STREET|1||NEW LISTING HOME|KING STREET|5||NEW LISTING HOME|WINSOME AVENUE|4||MODIFICATION CAR|TOYOTA|4||NEW LISTING CAR|FORD|4||NEW... (9 Replies)
Discussion started by: jubaier
9 Replies

4. Shell Programming and Scripting

Age of file in storage / disk

Hello all, Below is scripts to find the file following by: 30 days <- How many total file space within 30 days and not quantity 90 days 120 days 1 year From here also I can get data space to put on PIE Chart. Following this scripts can I do some enhance from this scripts like do... (1 Reply)
Discussion started by: sheikh76
1 Replies

5. Shell Programming and Scripting

Determine file age in days?

I am using AIX 6.1 and would like to use a one line command to determine the age of a file in days. I would like to look at a specific file. I would like to use the command to run on a remote server (AIX 6.1) to return the age of a specific file in days. So if the file is 42 days old I would... (2 Replies)
Discussion started by: oldman2
2 Replies

6. Shell Programming and Scripting

Perl Find file age

Hi I can not say that i am new to perl but today i learned something new, i wanted to know age (last time file got modified) of file so i initially thought of using find -mtime command but when i googled it, i found perl solution for the same my $age = -M $ARGV ; print "$ARGV age is... (1 Reply)
Discussion started by: zedex
1 Replies

7. Shell Programming and Scripting

ksh - AIX: get epoch time/age for a file?

Hi, (AIX 5.1) Is there any way to find the epoch timestamp for a file without having to use fancy perl (or similar) scripts? If anyone knows of a way to do this using just ksh commands it would be appreciated. (It also appears I don't have the stat command available). Alternatively is... (3 Replies)
Discussion started by: b0bbins
3 Replies

8. Shell Programming and Scripting

file age

How can I count the age of the file (e.g. in minutes)? (4 Replies)
Discussion started by: jarmo.leppanen
4 Replies

9. Shell Programming and Scripting

Find the age of a file in Minutes

KSH: Please lt me know how to find the age of a file in minutes(Based on last modified time). ie, if the file was modified 15 Minutes ago, the output should be 15 (1 Reply)
Discussion started by: hari_anj
1 Replies

10. UNIX for Dummies Questions & Answers

How to find the File Age and wait for that...

Hi, I want to know my file is 1 hr 30 min old or not, If 1 hr 30 min old I will do some tasks in that file.. other wise I will wait to 1 hr 30 min and then do the tasks.. how to do it in Unix script? any idea? (3 Replies)
Discussion started by: redlotus72
3 Replies
Login or Register to Ask a Question