Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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!

share|improve this question
add comment

3 Answers

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
share|improve this answer
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
1  
I think it is probably better to use -not option on find than to delete the lost+found directory, it will just get recreated when fsck runs anyway. See serverfault.com/questions/6753/… –  Richard Holloway Jan 20 '12 at 14:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.