Server Fault is a question and answer site for system and network administrators. 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 have a find command that looks for files that was modified recently and outputs the date

find /path/on/server -mtime -1 -name '*.js' -exec ls -l {} \;

I would like it to exclude any deeply nested folder that matches a certain pattern e.g. there are a number of folders that have a "statistics" directory and ".svn" directories. So i'd like to be able to say if the file that was modified yesterday is in a folder named statistics ignore it. Or perhaps not search for files in those folders at all.

share|improve this question
up vote 1 down vote accepted

You can use the -path and -prune command line parameters to do this

find /path/on/server -mtime -1 -o -path '*.svn' -prune -o -path '*statistics' \ 
-prune -o -exec ls -l {} \;

This has the advantage of not searching the directories that you want excluding.

Also note that your ls -l may not be doing what you expect as it will list the entire contents of directories that are passed to it so you will get some files listed multiple times.

From the comments ls -ld would be better.

share|improve this answer
Good note on ls, but you should include the alternatives such as ls -ld and simply -ls to find. Both should work since the question is tagged Linux. – jordanm Jul 6 '12 at 21:22
@jordanm: I didn't think it necessary as I haver previously supplied the OP with a better solution – Iain Jul 6 '12 at 21:38
I tried this and it listed all the files (it didn't restrict the find to the modified time of 1 day ago) – user40570 Jul 9 '12 at 21:56

Use the negate modifier !. For example like this find /path/on/server -mtime -1 -name '*.js' -o -name '!.svn' -o -name '!statistics' -exec ls -l {} \;.

The clue here is -o (meaning simply OR) and ''s around the exclamation mark as the shell (bash or similar) use exclamation marks for special commands.

share|improve this answer

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.