Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

I need to find file from ls - l by using grep and certain regexp.

In particular I need greep to see certain file ending, like let's say .txt but only using regex.

So it should be something like

ls -l | grep '^.+\.txt$'

But that doesn't seem to work for me.

share|improve this question
Is there a reason you are not using ls -l *.txt? Also note that with the eoln match ($), this will not pick up symlinks. With extended regexp (as Matt mentions), you might want to use '^.+\.txt\>' $ ls -l *.txt lrwxrwxrwx 1 arcege arcege 8 2011-04-07 09:04 file.txt -> realfile $ ls -l | grep -E '^.+\.txt$' $ ls -l | grep -E '^.+\.txt\>' lrwxrwxrwx 1 arcege arcege 8 2011-04-07 09:04 file.txt -> realfile – Arcege Apr 7 '11 at 13:06
up vote 4 down vote accepted

You need to specify the -E flag for grep:

-E, --extended-regexp
    Interpret  PATTERN  as  an extended regular expression (ERE, see
    below).  (-E is specified by POSIX.)
share|improve this answer
Hm.. Damn inattentiveness, I tried it but didn't specify the correct path :D – Denys S. Apr 7 '11 at 10:21

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.