Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

File last access date in UNIX (Solaris)

Posted on 2014-04-22
8
Medium Priority
?
997 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 22

Assisted Solution

by:robocat
robocat earned 150 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 38

Assisted Solution

by:Gerwin Jansen, EE MVE
Gerwin Jansen, EE MVE earned 450 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 900 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 38

Expert Comment

by:Gerwin Jansen, EE MVE
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 38

Expert Comment

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

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

719 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