Ubuntu – Need to skip lost+found when using find

automationcleanupfilesfolderscheduled

I am new to Ubuntu and I do not have alot of experience with Linux/Unix, so please bear with me while I try to get through this.

I have a camera system that records footage and takes screen shots and stores them in a folder. The problem is that the new files do not overwrite the older files, so the file system fills up and all new files are discarded.

So I installed Scheduled Tasks in the Ubuntu GUI and created a task to run every day. Here is the task:

find /media/dvr/* -type f -mtime 0 -exec rm -rf {} \; 

I have the -mtime set to 0 for testing purposes, it will be set to 7 if I can get this to work.

The problem I have is there is a lost+found folder in the /dvr folder. When it gets to that folder it says I do not have permission to view it and it never finishes its search. I have used sudo to get in and change the ownership and rwx permissions, but that still doesn't help.

Is there a way to accomplish what I want to do by using find? Is there a more efficent way of cleaning out the /dvr/ folder?

Like I said, new to this and trying to get better. Any help would be greatly appreciated!

Best Answer

Just do:

find /media/drv -name lost+found -prune -o -type f -exec echo '{}' ';'

In general it is a very very bad idea to redirect stderr to /dev/null. The whole point of stderr is to show unexpected errors. If you are expecting a certain error then construct your command to avoid it.

Related Question