[TriLUG] `find -delete` not deleting

Joseph Mack NA3T via TriLUG trilug at trilug.org
Tue Sep 6 12:11:54 EDT 2016


I store photos every 5 mins from my house webcams. After a week, I scrub them 
with the following crontab entry.

32 0 * * * find $top_dir -mtime +7 -delete > /dev/null 2>&1

Here's what the directories look like after a week, listed with the latest files 
at the bottom.

top_dir$ ls -alFrt
total 48
drwxr-xr-x 26 jmack users 4096 Aug 29 00:00 20160828/
drwxr-xr-x 26 jmack users 4096 Aug 30 00:00 20160829/
drwxr-xr-x 23 jmack users 4096 Aug 31 00:00 20160830/
drwxr-xr-x 26 jmack users 4096 Sep  1 00:00 20160831/
drwxr-xr-x 26 jmack users 4096 Sep  2 00:00 20160901/
drwxr-xr-x 26 jmack users 4096 Sep  3 00:00 20160902/
drwxr-xr-x 26 jmack users 4096 Sep  4 00:00 20160903/
drwxr-xr-x  2 jmack users 4096 Sep  4 00:32 20160827/
drwxr-xr-x 12 jmack users 4096 Sep  4 09:40 20160904/
drwxr-xr-x 22 jmack users 4096 Sep  5 19:50 20160905/
drwxr-xr-x 12 jmack users 4096 Sep  5 19:50 ../
drwxr-xr-x 12 jmack users 4096 Sep  5 19:51 ./

Notice that the directory from a week ago, 20160827 has yesterday's date on it 
and has the time of the cronjob (00:32) that was run on it. That directory (ie 
20160827) is now empty, as it should be.

$ls -alFrt 20160827
total 8
drwxr-xr-x  2 jmack users 4096 Sep  4 00:32 ./
drwxr-xr-x 12 jmack users 4096 Sep  5 19:51 ../

The other directories are still full, as it should be, eg today's directory.

top_dir$ ls -alFrt 20160905
total 172
-rw-r--r--  1 jmack users 78821 Sep  5 00:10 index.html
drwxr-xr-x  2 jmack users  4096 Sep  5 00:55 00/
drwxr-xr-x  2 jmack users  4096 Sep  5 01:55 01/
drwxr-xr-x  2 jmack users  4096 Sep  5 02:55 02/
drwxr-xr-x  2 jmack users  4096 Sep  5 03:55 03/
drwxr-xr-x  2 jmack users  4096 Sep  5 04:55 04/
drwxr-xr-x  2 jmack users  4096 Sep  5 05:55 05/
drwxr-xr-x  2 jmack users  4096 Sep  5 06:55 06/
drwxr-xr-x  2 jmack users  4096 Sep  5 07:55 07/
drwxr-xr-x  2 jmack users  4096 Sep  5 08:55 08/
drwxr-xr-x  2 jmack users  4096 Sep  5 09:55 09/
drwxr-xr-x  2 jmack users  4096 Sep  5 10:55 10/
drwxr-xr-x  2 jmack users  4096 Sep  5 11:55 11/
drwxr-xr-x  2 jmack users  4096 Sep  5 12:55 12/
drwxr-xr-x  2 jmack users  4096 Sep  5 13:55 13/
drwxr-xr-x  2 jmack users  4096 Sep  5 14:55 14/
drwxr-xr-x  2 jmack users  4096 Sep  5 15:55 15/
drwxr-xr-x  2 jmack users  4096 Sep  5 16:55 16/
drwxr-xr-x  2 jmack users  4096 Sep  5 17:55 17/
drwxr-xr-x  2 jmack users  4096 Sep  5 18:55 18/
drwxr-xr-x  2 jmack users  4096 Sep  5 19:50 19/
drwxr-xr-x 22 jmack users  4096 Sep  5 19:50 ./
drwxr-xr-x 12 jmack users  4096 Sep  5 19:51 ../

However I want the directory 20160827 deleted, but it isn't.

What seems to have happening is that while the delete was running, it changed 
the date of the directory from a week ago, to the date of the cronjob. The 
directory (here 20160827) then is not old any more and is not deleted till a 
week later.

I can't figure out if maxdepth or mindepth will fix my problem.

Any idea on how to have the directory deleted too?

Thanks Joe

-- 
Joseph Mack NA3T EME(B,D), FM05lw North Carolina
jmack (at) austintek (dot) com - azimuthal equidistant
map generator at http://www.wm7d.net/azproj.shtml
Homepage http://www.austintek.com/ It's GNU/Linux!


More information about the TriLUG mailing list