Regular Expression usage with ls

Lucas Rezende picture Lucas Rezende · Mar 11, 2013 · Viewed 110.2k times · Source

I am trying to use ER (Extended Regular Expressions) with ls like ls .+\..+.

I am trying to print all files which contains an extension (I know I could have used ls *.*, but I wanted to try using ER).

When I run that code I get this error: ls: .+..+: No such file or directory.

Answer

Chris Seymour picture Chris Seymour · Mar 11, 2013

You are confusing regular expression with shell globbing. If you want to use regular expression to match file names you could do:

$ ls | egrep '.+\..+'