

The first part of the command looks for the word Walden in any files in the current directory, and the second runs another grep command on the results of the first command. You’d use this command: grep Walden * | grep Pond. Say you want to find files containing both Walden and Pondon the same line. Using the pipe ( |), a Unix redirection operator, you can tell grep to search for more than one string. (Note that you can also combine options-for instance, grep -rl Walden searches subfolders and returns only a list of files containing the word Walden. Get started with the helpful options listed here. The grep command has several options that let you fine-tune the way you search for text, as well as the kind of results grep returns. Returns the names of files containing Walden and the number of hits in each file. Search for Walden Pond, and it returns all files that contain either Walden or Pond.įinds Walden in any file in any subfolder of ~/Documents.įinds only live does not find liver, lives, lived, and so on.įinds files containing Walden, but returns only a list of file names. The Finder also lacks grep’s flexibility: while it’s good for searching for a specific word (for example, Walden ), it becomes less useful when you want to find a longer string. (Press Command-F in the Finder, select Content in the Search For Items Whose pop-up menu, and enter a search string in the text field.) But the Finder searches only inside files it has indexed, and it ignores hidden system files unless you expressly choose to search for visible and invisible files and add your System folder to the search. The Finder offers a similar function: the Find By Content search. (You can also use grep within certain text editors.) You can use grep easily from the command line to search for specific text, and you’ll get results in seconds. But the grep command is a time-saver when you’re trying to find what’s inside files. Typing text and Tab to autocomplete it will make it instantly available. The difference between this and the other answer, is you can easily remember it when you want it. Invoke it like: textedit theFiletoEdit.txt. It’s easy to find files with the Finder when you know their names. Direct, easy answer - add an alias to your /.bashprofile like: alias textedit'open -a TextEdit'. Understanding grep is the first step in joining the guild of command-line wizards. With this workhorse of the command line, you can quickly find text hidden in your files. It’s fast, it’s powerful, and its very name suggests that it does something technical: grep.
