LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

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

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?


Cheers

Prollocks
 
Old 10-05-2007, 09:05 AM   #2
cconstantine
Member
 
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, 10:56 AM   #3
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,749

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

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.

Cheers

Prollocks
 
  


Reply

Tags
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 12:31 AM
Command to find similar file names in a directory Ottoguy Linux - Newbie 4 02-02-2006 05:42 AM
Samba access by Windows users locking out directory access with Konqueror harry_fine Suse/Novell 1 12-18-2004 05:33 AM
find command with time linuxtesting2 Linux - Newbie 1 09-22-2004 12:31 PM
linux command error message bash: /usr/bin/find: No such file or directory sundaram123 Linux - General 8 04-02-2002 07:18 AM


All times are GMT -5. The time now is 08:23 AM.

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