0

I want to find all the files in a directory that have not been modified for at least 30 days and end in .xml or .out. This is my attempt to cobble together a couple of references to build the right find syntax:

find . -mtime +30 -type f / (-name "*.xml -o -name "*.out" ) / -print

I'm getting

-bash: syntax error near unexpected token '('

What am I missing in my syntax?

2

You're nearly there! This works:

find . -mtime +30 -type f \( -name \*.xml -o -name \*.out \)

Your / ( becomes \( (an escaped open parenthesis; as you discovered the shell treats ( specially so it needs to be escaped with \); likewise ) / should actually be \). The names need * to match anything ending with the given extension, and that also needs to be escaped, so ".xml" (I added the missing closing quote) becomes either \*.xml or "*.xml".

Finally -print can be dropped since that's find's default action.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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