views:

843

answers:

3

Hello all,

I have this command that I run everyday via cron:

find /home/get/public_html/videos -daystart -maxdepth 0 
-mtime +1 -type f -name "*.flv" |xargs rm -f

The problem is that it doesn't delete the .flv files in a directory that are 1 or more days old.

How can I correct the above command?

EDIT: Paul - the command "ls -l /home/get/public_html/videos" results in 2000+ files but here is 2 of them that should be deleted:

-rw-r--r--  1 get get   3501188 Jan  4 15:24 f486cf0a2b6bb40e4c50c991785084131231104229.flv
-rw-r--r--  1 get get  10657314 Jan  4 17:51 f5f1490ddaa11a663686f9d06fb37d981231112941.flv
+3  A: 

It's better to use -print0 on find and -0 in xargs in case one file has an uncommon name.

Also, you want to use -maxdepth 1 to actually find something in the specified directory.

-maxdepth 0 means it'll only find in the directories listed in the command line, it won't check the contents of those directories.

Vinko Vrsalovic
Correct -maxdepth 1 is what I need.
Abs
+1  A: 

Do you mean, if you have a directory /home/get/public_html/videos/foo it doesn't delete the files in them? That would be because you have the -maxdepth 0 argument set, which prevents find from descending into subdirectories.

Zach Hirsch
I want the command to search in the directory "videos" and not go into any subfolders.Does that mean I should remove "-maxdepth 1"?
Abs
No, in that case -maxdepth 1 is what you want.
Zach Hirsch
+1  A: 
-maxdepth 1
Georgi Kirilov