Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I need to find all .pem files on my system. Would the following do this?

sudo find / -type f -name *.pem

If not, how would I write a find command to find every file of the sort?

share|improve this question
add comment

5 Answers 5

up vote 14 down vote accepted

You're on the right track -- you just need to quote the pattern so that it gets interpreted by find and not by your shell:

sudo find / -type f -name '*.pem'
share|improve this answer
    
You beat me to it. :) –  EEAA May 24 '12 at 20:35
2  
/me holsters the pistols ;-) –  mgorven May 24 '12 at 20:36
    
Thanks, very clear explanation –  David542 May 24 '12 at 20:42
add comment

Using find / will normally be very slow. Using locate is much faster but somewhat imprecise because it doesn't support anything more complex than substring matching. A directory called .pembroke will be found and returned by locate along with every file inside it.

A combination of locate and grep, however, has speed and precision. Conveniently, it also does not require sudo.

locate .pem | grep "\.pem$"

The downside? The database locate uses is normally only updated once per day so any recent changes (additions, deletions, name changes, etc.) will not be found.

share|improve this answer
    
locate is much faster than find –  B14D3 May 24 '12 at 22:23
add comment

Almost!

sudo find / -type f -name \*.pem

or

sudo find / -type f -name "*.pem"

otherwise the shell will interpret the * instead of find.

share|improve this answer
    
\* is a bit depended on the shell and the flavor of Unix. (Will work as intended on most systems though.) The quoted version will always work as far as I know. –  Tonny May 24 '12 at 21:52
    
That's funny. Had to write \\* to escape the escape. Very appropriate in this case. –  Tonny May 24 '12 at 21:54
add comment

...or if mlocate runs on your computer and you don't need the most actual data use locate command

locate *.pam

It's faster becouse it finds files in previously created database; not on whole system.

share|improve this answer
add comment
sudo find / | grep .pam

Think that should work.

share|improve this answer
add comment

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.