3

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!

César
  • 807
Nick
  • 31

3 Answers3

4

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.

Jay
  • 41
2

The find command does not exit on permission problems as far as I know, it may just not be finding any files for a different reason. What I can suggest is to eliminate stderr so that you don't get misleading messages in the output, and to test the command using echo replacing rm -rf, i.e.,

find /media/drv/ -type f -mtime 7 -exec echo {} \; 2> /dev/null

This should list the files that would be removed in your final version with rm -rf. If you really want to skip the lost+found directory (which should not be necessary), use:

find /media/drv/ -type f -mtime 7 -not -wholename "*lost+found*" -exec echo {} \; 2> /dev/null
pablomme
  • 5,870
-2

Setting the permissions correctly should do it. What does ls -ld /media/dvr/lost+found say? Also drop the * at the end of /media/dvr/. You want find to start its search in /media/dvr/, and when you add the *, the shell replaces that string with the name of every file it finds in /media/dvr/.

You also can just delete the lost+found directory.

psusi
  • 38,031