12

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?

25

Use the -d switch:

ls -d *ro*

.....

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

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.

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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.