3

I'm using this command to go through all files, directories and subdirectories to change any mentions of oldurl.com to newurl.org:

find . -type f -name '*.php' -exec sed -i 's|oldurl.com|newurl.org|g' {} +

It works fine, however, I need to exclude three sub-directories from ANY CHANGES: /cache, /archive and /etc as changing the urls with the above command in these paths breaks other scripts.

Haven't had much luck finding an answer... Is it even possible?

Many thanks for any suggestions/help.

nooblag
  • 339
  • 1
  • 5
  • 13
  • 1
    possible duplicate of [exclude directory from find . command](http://stackoverflow.com/questions/4210042/exclude-directory-from-find-command) – Ansgar Wiechers Aug 04 '13 at 19:16

1 Answers1

7

Use finds -not Option:

find . -type f -name '*.php' -not \( -path './etc/*' -o -path './cache/*' -o -path './archive/*'  \) -exec sed -i 's|oldurl.com|newurl.org|g' {} \;
marderh
  • 1,236
  • 7
  • 12