Recursive file content search

find . -name *.php | xargs grep -i -n 'TERM'

-3
By: crashrox
2009-03-23 14:27:55

These Might Interest You

  • This command will traverse all of the folders and subfolders under current working directory. For every file inside it, it will do a search inside the content of the file for a specific term 'what'. Then it will print a list of the lines that contain that term (and match that pattern). Each matching line will be preceded with the path and name to the file and then the line number iside taht file wehre the pattern was found. Then the actual content of the matching lien will be printed. The output will be piped throug less, so that the user can scroll through it if it goes beyond the limits of the current display window. Show Sample Output


    1
    find . -exec grep -Hn what \{\} \; | less
    ynedelchev · 2014-02-17 09:59:01 0
  • recursively search dir for a a particular file type, search each file for a particular text. Show Sample Output


    1
    find /name/of/dir/ -name '*.txt' | xargs grep 'text I am searching for'
    erickb · 2011-01-05 15:20:40 0
  • Use the following key binding to search ---------------------------------------------------------------- ng : Jump to line number n. Default is the start of the file. nG : Jump to line number n. Default is the end of the file. /pattern : Search for pattern. Regular expressions can be used. [/ = slash] Press / and then Enter to repeat the previous search pattern. Press ESC and then u to undo search highlighting. n : Go to next match (after a successful search). N : Go to previous match. mletter : Mark the current position with letter. 'letter : Return to position letter. [' = single quote] '^ or g : Go to start of file. '$ or G : Go to end of file. s : Save current content (got from another program like grep) in a file. = or Ctrl+g : File information. F : continually read information from file and follow its end. Useful for logs watching. Use Ctrl+c to exit this mode. -option : Toggle command-line option -option. h : Help.


    -4
    less file.ext
    totti · 2011-09-13 10:29:27 3
  • range context (-A -B) search, with exclusion of vcs directories Show Sample Output


    0
    pcregrep -r --exclude_dir='.svn' --include='.*jsp$' -A 2 -B 2 --color "pHtmlHome" .
    hute37 · 2010-12-09 15:26:07 0

What Others Think

find . -name *.php | xargs grep -i -n 'TERM'
wdomburg · 482 weeks and 2 days ago
grep -ri 'REGEX' *.php
juddmaltin · 482 weeks and 2 days ago
@juddmaltin: grep: *.php: No such file or directory Doesn't work broseph, only "*" does.
sudopeople · 482 weeks and 2 days ago
ack -i --type=php 'TERM' ... if you have ack.
bazzargh · 336 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: