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

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
up vote 14 down vote accepted

Use the -d switch:

ls -d *ro*


share|improve this answer
I wrote a script that gets the folder access bits (converted to 755 or 644 notation), date and time modified, and folder name, then sends the information via text message. I needed this to be <140 characters. This helped, thanks. – user208145 Jun 30 '15 at 5:27

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


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.