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

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
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
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
@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


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.