Solved

File last access date in UNIX (Solaris)

Posted on 2014-04-22
8
915 Views
Last Modified: 2014-04-24
I'm using the stat function in perl to obtain an array of elements that describe the files being examined.  One of the elements in the array is the file's date of last access made by anyone.  However, the act of reading the file's date of last access changes that value to the date/time that the file's date of last access is read, which is the current date and time.  Is there a way to read the file's date of last access without changing it in the process?
0
Comment
Question by:fireblood
8 Comments
 
LVL 21

Assisted Solution

by:robocat
robocat earned 50 total points
ID: 40017078
Why not modify the access time of the file back to the value you just read? Of course assuming you have enough permissions.
0
 
LVL 37

Assisted Solution

by:Gerwin Jansen
Gerwin Jansen earned 150 total points
ID: 40017095
Using stat on a file handle in perl is not changing accessed, modified or changed timestamps. How are you reading the access timestamp of a file?
0
 
LVL 22

Accepted Solution

by:
blu earned 300 total points
ID: 40017171
You must be doing something other than just running stat on the file. I attached a test perl script and here is what I get when I run it:

# ~/stat.pl
Create file and display the access time
-rw-r--r--   1         10 Apr 23 07:01 testfile

Get the atime and display it
Apr 23 07:01:46

Wait a while

Get the atime again and display it
Apr 23 07:01:46

What is the access time now?
-rw-r--r--   1          10 Apr 23 07:01 testfile

Now we really access it then display access time.
-rw-r--r--   1          10 Apr 23 07:02 testfile


As you can see, the access time did not update when run stat on the file.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 22

Expert Comment

by:blu
ID: 40017178
Oops, somehow I missed the file. Here it is. I had to change the extension becase EE doesn't accept files with extension .pl.

stat.sh
0
 
LVL 37

Expert Comment

by:Gerwin Jansen
ID: 40017413
@blu - Works fine in Linux for me as well, did you test Solaris?
0
 
LVL 22

Expert Comment

by:blu
ID: 40017924
My test was on Solaris.
0
 

Author Closing Comment

by:fireblood
ID: 40020431
Thanks to the three of you, the key insight for me here was that I was asking for a workaround to a problem that didn't exist.  My code was accessing the files in a way that I didn't recognize, and when you made it clear that just doing a stat would not change the last access time stamp I went back and then confirmed that you were correct.  Thanks very much to all three.
0
 
LVL 37

Expert Comment

by:Gerwin Jansen
ID: 40020696
You're welcome!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now