Solved

How to display the last time files were accessed.

Posted on 2004-10-12
4
1,481 Views
Last Modified: 2013-12-27
I need a way to show the last time (date) each .sqr file was accessed on a solaris 9 server.  It seems there is a difference between the last time modified, and last time accessed.  What I need to know, if possible, is if a file was read or modified, or both  (We have a group of developers that have tons of .sqr files, some that are very old, and are not in use any more.   I need to identify files that no one has even read in the last year).  

I tried using:

find /  -name *.sqr -atime -365

but that seems to show only files that were accessed on a specified date, instead of listing the access time of every .sqr file.

Ultimately, these .sqr files need to be grouped by user, and then listed by the last time it was read or modified
 
Please let me know if I need to provide any other information.

Thanks for your help!
Juliann  

0
Comment
Question by:juli_ann
  • 2
4 Comments
 
LVL 20

Expert Comment

by:tfewster
ID: 12293520
"last access time" depends on the process that accesses the file updating the inode with the timestamp;  To be honest, I don't know what system utilities do and don't do that, so it's not very reliable :-(

find /  -name *.sqr -atime -365   should list all files accessed within the last year;  To display the actual access time, use `ls -lu` or `ls -tu`

0
 

Assisted Solution

by:colinbo
colinbo earned 125 total points
ID: 12293572
How about:
find /  -name *.sqr -exec ls -alu {} \;

This will unfortunately list all .sqr files, but will list them in order of time last accessed. You could redirect the output to a text file then sort it or grep from it manually from there. HTH

- CB
0
 
LVL 4

Assisted Solution

by:Otetelisanu
Otetelisanu earned 125 total points
ID: 12294827
find . ! -newer . -exec ls -l {} \; |tail -1

The find command has a -newer expression which compares the found files against a reference file. It returns files with a modification time newer than the reference file. To find older files, preceed the -newer expression with the negation operator !.

If you do not have a file to use with an appropriate timestamp, you can create a file with this recipe: Create/modify a UNIX file with an arbitrary timestamp.
0
 
LVL 20

Accepted Solution

by:
tfewster earned 250 total points
ID: 12296407
find /  -type f -name "*.sqr" -atime +365 -exec ls -ldu {} \;

-type f  excludes directories - `find` updates the access time on a directory when it reads it. However, the -name "*.sqr" probably makes this unnecessary.

-atime +365  only files accessed > 365 days ago

-exec ls -ldu {} \;   lists the details of the file, with the _access_ time instead of the _modification_ time.  The list is not sorted, as the "ls" is done on each file as `find` finds it.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

707 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

17 Experts available now in Live!

Get 1:1 Help Now