Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Find all files in /tmp that are ordinary files and print the lines that end with Programming.

For this problem I know how to list all files in /tmp. What I do not know how to do is whether to use grep or find to print lines that end with Programming for these /tmp files.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

You must use find to find the files, and grep to grep them.

find /tmp -maxdepth 1 -type f -exec grep 'Programming$' {} \;
share|improve this answer
1  
Uhm, I think I'm too tired, what makes grep 'Programming$' /tmp/* wrong or unsuited? (Supposing there're not too many files ("Argument list too long" etc)) –  sr_ Mar 15 '12 at 8:14
    
Depending on your shell you may have to escape your {} as well –  tylerl Mar 15 '12 at 9:38
1  
@sr_: The "ordinary files" requirement. –  Ignacio Vazquez-Abrams Mar 15 '12 at 11:14
    
@IgnacioVazquez-Abrams: Ah, I see, /tmp is probably full of non-ordinary files. Thanks. –  sr_ Mar 15 '12 at 11:16

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.