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.

If I type ls *ro* I also get files in subdirectories that match the *ro* pattern.
Is there any option for ls similar to prune?

Ideally a flag, otherwise perhaps an exec?

share|improve this question

2 Answers 2

up vote 10 down vote accepted

Use the -d switch:

ls -d *ro*

.....

share|improve this answer

You could use :

ls | grep ro

To accomplish the task. Pipe the output of ls which outputs only the contents of the current directory to grep and to selectively output the files matching the regex pattern.

share|improve this answer
    
-1 How would the grep know if the pattern match was in the directory or a subdirectory? –  Michael Durrant Jul 24 '12 at 12:59
    
Also it doesn't actually return anything. Try it. –  Michael Durrant Jul 24 '12 at 13:01
1  
By default ls outputs only the contents of the current directory. So passing that output to grep returns only the data that matches the given regex. I tried the given command on my Arch system and it works perfectly. –  darnir Jul 24 '12 at 13:03
    
Since grep takes a regex as input, do not add the asterisks around ro. As I have mentioned, just execute grep ro. This is a crude hack when compared to manatwork's answer, but works perfectly fine. –  darnir Jul 24 '12 at 13:05
    
If you have an absurd number of files, though, the globbing in manatwork's answer may reach the limit of the command line length. This won't. –  Izkata Jul 24 '12 at 14:11

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.