Recently I’ve needed to do some string searches for occurrences on my local file system. I can tell you by far the easiest thing I’ve found to get up and running quickly is `ack` with a combination of other tools:
First off let’s start with a simple string search:
ack -io "my( | )simple( | )string( | )search" --ignore-dir={example,directories,to,ignore}
This does a couple things.
- -i means to ignore case, -o means output the line and occurrence of the string
- Everyhing in quotes is the regex (normal regex)
- ignore a list of directories (if it was a single directory don’t use curly braces.
The only wierdness is my regex which just looks for regular white spaces and nonbreaking characters as well. Ignore my regex and you get the basic structure:
ack -io "search string" --ignore-dir={ignore,these/directories}
If you want to see the entire line with the occurence you would just remove the -o value:
ack -i "search string" --ignore-dir={ignore,these/directories}
And that’s it! So simple you can’t afford not to try it out. If you’re on a mac, installation is simple:
brew install ack
Just chanced upon this utility through your blog. Great find. Many thanks for sharing.
Unix utilities never cease to amaze me.