Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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

So basically I have three files, two with permission 744 and one with 601 and I want to list the names of the files that have permission 744 and in addition, it also have to have string "def" anywhere in the lines of the file.

All I got is how to print out if they have permission 744:

find * -perm 744

How do I get it so it can check for string "def"?

Any help is appreciated.

share|improve this question
up vote 5 down vote accepted

Follow your current options with

-exec grep -l def {} +

e.g.,

find * -perm 744 -exec grep -l def {} +

The -l option of grep tells it to just list the names of files where a match occurs, and since that is the only action for find, the output of grep will be all that you see.

share|improve this answer

One possibility:

find * -perm 744 -print0 | xargs -0 grep -l def

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.