Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to run a command similar to this where AVI files older than 7 days will be deleted:

find "/home/user/videos folder/*.avi" -mtime +7 -exec rm -f

But as you can see, the videos folder has a space so I had to put that path in quotes. But, will the asterisk still do its job to find all AVI files, or will Linux now think the asterisk is the actual filename now?

Let's just assume I didn't want to remove the space in the path by renaming the folder.

share|improve this question
up vote 3 down vote accepted

You need to reformat your command a bit for it to work.

Try this:

find "/home/user/videos folder" -name "*.avi" -mtime +7 -exec rm -f {} \;

Or, in GNU find, to achieve the same thing without -exec:

find "/home/user/videos folder" -name "*.avi" -mtime +7 -delete

The first argument to find is the folder to look in - you shouldn't try and put your entire filter in here, just the starting point. Then use -name to tell it what pattern to look for. You can try this without the -exec or -delete first until you are satisified, then you won't do any damage by trying it.

Enclosing an argument in quotes basically stops the shell from messing with it. If you use -name *.avi, then the argument that find will see could be anything, because the shell will parse it (and replace it with the contents of the current directory that end in .avi) before calling find. This is usually bad and will lead to unexpected results. find knows how to parse * itself.

share|improve this answer
You missed the final {} \;. Also, you could use -delete with GNU find, instead of -exec rm {} \;. – enzotib Dec 10 '11 at 15:49
Thank you very much! That has answered my question exactly. This works for me on Ubuntu Server: find "/home/user/videos folder" -name "*.avi" -mtime +7 -exec rm -f {} \; – nLinked Dec 10 '11 at 16:02

Your Answer


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.