Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know grep -irn "#page-title" will search all files for matching text but for performance reasons I would like to limit the search ONLY to files that are css files. In Windows PowerShell it’s:

ls *.css -r | select-string "#page-title"

Bonus points, how do I limit this to files that are NOT prefixed with css_

share|improve this question
up vote 6 down vote accepted
find -name "*.css" ! -name "css_*" | xargs grep -H "#page-title"

find is the unix command-line find, with 2 sets of parameters. The first parameter, -name "*.css", tells find to look for files with the CSS extension, the ! -name "css_*" parameter tells find to exclude or ignore files that start with css_. This list of files is then piped to the xargs command, which passes the list as parameters into the grep command, which is told to find "#page-title" from the list, and print the file name, using the -H parameter.

share|improve this answer
Could you provide some explanation about what your code does? – Tom Wijsman Oct 31 '11 at 21:38
@TomWijsman added additional detail per your suggestion. – Roy Rico Oct 31 '11 at 23:01

This should do the trick

grep -r --include="*.css" "#page-title" ./
share|improve this answer
Welcome to Super User. I just upvoted your answer but it could be improved by adding --exclude="css_*". – Anthony Geoghegan Dec 12 '15 at 18:44

I've just uploaded grepcss:

grepcss understands CSS language, so you could do the find command as described above with

| xargs grepcss -s '#page-title'
share|improve this answer

protected by JakeGould Dec 13 '15 at 2:23

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.