Visit The New, Modern Unix Linux Community


On Solaris, without stat, how to check how old a file is?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers On Solaris, without stat, how to check how old a file is?
# 1  
On Solaris, without stat, how to check how old a file is?

Hi,

How do I check how old a file is? That is, is it 1 day old, 1 year old, generated x hours ago?

Currently, I receive a supposed to be daily report and in the last few times, it has not been recent, that is instead of the one generated for the day, it is one that was created yesterday or older.

I want to write a script to be able to check how old a file is or when it was generated. I am doing the check at the moment using ls -l and comparing the date to today's date. Alternatively, as a workaround I am telling the user to put a date timestamp on the file and I check that timestamp in the file.

Any advice will be much appreciated. Thanks.
# 2  
Like your other question about ls, check out the options of the find command.

Though keep in mind, there is no time stamp stored for the creation of a file.
There is only mtime (modification), ctime (change), atime (access).

Detailed info about this is here:
mtime, ctime, and atime
# 3  
Modern filesystems (eg, ZFS) do indeed record file creation date/time.

What Solaris filesystem type are you talking about?

Read this thread from this forum:

https://www.unix.com/solaris/248099-s...imestamps.html

Particularly read the superb post by jlliagre.

Hope that helps.

Last edited by hicksd8; 07-18-2014 at 11:00 AM..
This User Gave Thanks to hicksd8 For This Post:
# 4  
Normally you take the mtime.
After
Code:
touch -t timestamp reffile

you can compare with
Code:
find ... -newer reffile

or
Code:
test `ls -t yourfile reffile | head -1` = reffile

--
Or you use stat() in perl.
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #350
Difficulty: Medium
AWK was originally written in 1975 and distributed with Version 6 Unix.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to check duplicate entries in file ? (Solaris-9)

Hi, There are duplicate entries in file, but uniq will not see because first field is different. How will I catch all lines, which are having duplicate IPs ? bash-2.05# cat db.file | grep 172.30.133.11 dsrq-ctrl1-prod A 172.30.133.11 e911q-db1-nxge0 A 172.30.133.11... (4 Replies)
Discussion started by: solaris_1977
4 Replies

2. Solaris

/bin/find: stat() error <File> : No such file or directory

Hi, I am getting below error in Solaris 10 SPARC when trying to issue a search on /var/tmp partition Below is the query /bin/find /var/tmp/ -type f -atime +1 Below is the result /bin/find: stat() error <File> : No such file or directory (28 Replies)
Discussion started by: prash358
28 Replies

3. Shell Programming and Scripting

Cp: cannot stat No such file or directory

Hi Please review this script and let me know what i need to do. This is my script #!/bin/bash #SCRIPT: forms.sh #PURPOSE: Process a file line by line with redirected while-read loop. #PURPOSE: and copy the forms to the follder foldername=sample_dir mkdir -p $foldername while read... (5 Replies)
Discussion started by: Rami Reddy
5 Replies

4. Shell Programming and Scripting

Please. Check Script Keep Stat CPU.

:wall: My Script. :D. I. want monitor cpu every 10 minute. This my Script. while true; do date ; top >> cpu.csv ; sleep 600; echo " "; echo " "; echo " "; doneYou think it Work? if not work. please suggest. Thank you :o (3 Replies)
Discussion started by: ooilinlove
3 Replies

5. Shell Programming and Scripting

using File::stat

Hello everyone, I need some help on a perl script. The script is to open a dir and print out the date of last modification on all files. I'm been trying this code but it doesn't work. use File::stat; open (D,"$ARGV") or die "Can't open\n"; while (defined ($file = readdir D)) { next... (3 Replies)
Discussion started by: new bie
3 Replies

6. Solaris

How to check file size in solaris?

Hi All I m having a file , path is /usr/Image/test how i can get size of the "test" file? is there any command for that? (3 Replies)
Discussion started by: sunray
3 Replies

7. SuSE

cp: cannot stat no such file or directory

#!/bin/ksh cp /etc/apache2/vhosts.d/orginal/test-yast2_vhost.conf-bk /etc/apache2/vhosts.d/test-yast2_vhost.conf /usr/sbin/rcapache2 graceful when i ran this script I'm getting following error. cp: cannot stat /etc/apache2/vhosts.d/orginal/test-yast2_vhost.conf-bk no such file or directory... (1 Reply)
Discussion started by: s_linux
1 Replies

8. Shell Programming and Scripting

cp: cannot stat: No such file or directory

Hi there, I need some help with cp files from one directory into several others. The code is as follows: SUB=`ls src_directory | wc -l` OUT_LOOP=$(($SUB / $MK_NUMS)) IN_LOOP=$(($SUB % $MK_NUMS)) COUNT=$MK_NUMS while ] do mkdir dst_directory$COUNT ls -1 src_directory |... (4 Replies)
Discussion started by: Krush187
4 Replies

9. Solaris

stat: Available on Solaris?

JoeyG's note in the following thread got me thinking about using stat more often in file operations. I've only ever used it within perl - didn't even realize there was a commandline version of it.... (3 Replies)
Discussion started by: Smiling Dragon
3 Replies

10. Solaris

How to check the file existence using shell scripting in Solaris-10

Hi, I have a script which will check the fiel existence, the lines are as below if !(test -d ./data) then mkdir data fi In the first line error occurs as below generatelicense.sh: syntax error at line 2: `!' unexpected Where as this script works fine in linux OS. How to solve... (2 Replies)
Discussion started by: krevathi1912
2 Replies

Featured Tech Videos