Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm pretty sure I've done this in the past (and that an answer is out there somewhere), but can't remember right now.

I'm looking for a one-liner to search for (and return / echo) matches in both the filename and file.


Probably the easiest would be to run grep and find separately after each other; but I'd prefer a one-liner...

...unless it were possible with a semicolon (?) or other to run these tools sequentially.


I don't think the solution I'm after would involve piping | because, to borrow from set theory, I'm interested in the union of the two sets A and B (A ∪ B), rather than their intersection (A ∩ B).

share|improve this question
    
meta: should this question be migrated to a different SE site, e.g. stackoverflow or superuser ? –  nutty about natty Apr 1 '13 at 11:52

2 Answers 2

Try this in your terminal(CTRL+ALT+T)

find <here your starting string > -type f -exec grep -l <here place the part of file name> {} \;

Description of the above command:

find snow -type f -> find all files starting from snow. find .... -exec -> for each item found, do the following command. Where you normally place the filename in you command, put {} . grep -l "String" something -> returns the filename if string "String" is found in file something.

Credit:dbasupport.com

share|improve this answer
    
To borrow from set theory, I'm interested in the union of the two sets A and B (A ∪ B), rather than their intersection (A ∩ B) -- as I tried to make clear in my question above... –  nutty about natty Apr 1 '13 at 16:00

You're right - you can use semicolon to run list of commands sequentially:

$ find . -name 'test'; grep test *

You can also group it to run as single command: http://www.gnu.org/software/bash/manual/html_node/Command-Grouping.html

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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