Skip to content

Instantly share code, notes, and snippets.

@watson
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save watson/997f6662de7206789371 to your computer and use it in GitHub Desktop.
Save watson/997f6662de7206789371 to your computer and use it in GitHub Desktop.
A stash of useful unix commands that are too hard to remember, but too useful to forget

Find all files excluding a single directory:

find . -path ./exclude-this -prune -o -type f -name '*.js' -print

Notes:

  • The -path ./exclude-this -prune -o part ensures that the path ./exclude-this isn't included
  • The -print part ensures that the base directory of the excluded path isn't outputtet (this isn't needed if combining with -exec)

Search and replace across files using a regular expression:

find . -type f -name '*.js' -exec sed -i '' -e 's/foo/bar/' {} \;

Notes:

  • The -i '' in the sed part of the command ensures existing files are replace without creating a backup. If you want the backup, just use -i without the '' part
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment