Visit the LQ Articles and Editorials section
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-05-2007, 05:16 AM   #1
LQ Newbie
Registered: May 2006
Distribution: Arch 64
Posts: 27

Rep: Reputation: 0
Question 'find' command changes directory access time

Hello all,

I'm writing a small script to traverse a set of directories and delete all files older than X days (including directories).

# find and delete all files/dirs older than 8 days
find . -mtime +8 -print0 | xargs -0 -r rm -rf

This should be simple and mostly works - however if there is a directory that is newer than the number of days I'm checking for its atime becomes the current date (files within that directory remain timestamped with their original dates).

Why does the 'find' command do this ? and is there a way around it?


Old 10-05-2007, 10:05 AM   #2
Registered: Dec 2005
Distribution: RedHat, Ubuntu
Posts: 101

Rep: Reputation: 15
That's the *file system* works. When a program reads the directory's inode to determine the directory contents, the file system updates the atime (access time) property on the inode. It doesn't matter if the program doing the access is 'ls' or 'find' or whatever.

You could make your script remove only *files* which are over the age limit as a first pass, then go back and prune directories which are empty.
Old 10-05-2007, 11:56 AM   #3
Amigo developer
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,811

Rep: Reputation: 493Reputation: 493Reputation: 493Reputation: 493Reputation: 493
You could also remount the filesystem where the directories are using the noatime option while doing the operation.
Old 10-05-2007, 12:57 PM   #4
LQ Newbie
Registered: May 2006
Distribution: Arch 64
Posts: 27

Original Poster
Rep: Reputation: 0
Ok -

I did some more testing and found that atime is only changed if a file is deleted from within a directory - newer files within that directory are left alone (dates untouched). So it seems directory atime only changes if something happens i.e deletion within that directory.

I may now check for empty dirs and delete them as an insurance, but wanted to keep things as simple as possible.




cleanup, delete, deletion, find, purge, scripting, xargs

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Does the kernel cache directory info? ('find' command runs quicker after first use) sixerjman Linux - Kernel 2 10-26-2006 01:31 AM
Command to find similar file names in a directory Ottoguy Linux - Newbie 4 02-02-2006 06:42 AM
Samba access by Windows users locking out directory access with Konqueror harry_fine SUSE / openSUSE 1 12-18-2004 06:33 AM
find command with time linuxtesting2 Linux - Newbie 1 09-22-2004 01:31 PM
linux command error message bash: /usr/bin/find: No such file or directory sundaram123 Linux - General 8 04-02-2002 08:18 AM

All times are GMT -5. The time now is 07:22 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration