home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 21.4 Why Both /tmp and /usr/tmp? Chapter 21
More About Managing Files
Next: 21.6 A File's Inode Change (not  "Creation"!) Time
 

21.5 What Good Is a File's Last Access Time?

UNIX keeps three times for each file: last modification, last inode change, and last access. Here are some things you can do with the last-access time:

  • Find files that have been forgotten. This information comes from commands like ls -lu ( 16.2 ) and find -atime +180 ( 17.5 ) . (If you use the MH email system, you can find mail messages that haven't been read or scanned in a long time.) You can save disk space by cleaning up unused files; see article 23.19 .

  • Automatically gzip ( 24.7 ) files to save disk space. Some users run a shell script named compresser , which looks for nonexecutable files that haven't been accessed in 90 days. The program runs gzip on these files:

    
    
    -perm -100
     
    
    xargs
     
    
    find 
    
    dir1 dir2
    
     -type f ! -name '*.gz' ! -perm -100 -atime +90 -print | \
        xargs gzip -v

    A system like this could automatically archive files to tape and delete them. It could have a personal "skip" list of files and directories to skip. And so on...

  • Check a directory to see which files are being read by programs, compilers, etc. This "sanity check" can help you debug programs by confirming which files are being accessed.

NOTE: Some UNIX systems, including versions of BSD and SunOS, do not update the access time of executable files (programs) when they're executed. To test yours, use ls -lu on a pure-executable file (not a shell script) before and after you run it.

- JP


Previous: 21.4 Why Both /tmp and /usr/tmp? UNIX Power Tools Next: 21.6 A File's Inode Change (not  "Creation"!) Time
21.4 Why Both /tmp and /usr/tmp? Book Index 21.6 A File's Inode Change (not "Creation"!) Time

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System