Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1524
  • Last Modified:

How to display the last time files were accessed.

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
juli_ann
Asked:
juli_ann
  • 2
3 Solutions
 
tfewsterCommented:
"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
 
colinboCommented:
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
 
OtetelisanuCommented:
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
 
tfewsterCommented:
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now