Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 08-10-2007, 10:56 PM   #1
Senior Member
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 210Reputation: 210Reputation: 210
regex in ls vs. grep

I got used to using regular expressions with (e)grep, but am still unclear what is going with ls at this point. How does ls handle regexs?

for example,
ls | grep "^D"
returns Desktop as expected, whereas
neither ls "^D", nor ls ^D

..does ls only do wildcard?

Last edited by jhwilliams; 08-10-2007 at 11:01 PM.
Old 08-10-2007, 11:10 PM   #2
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
It isn't ls that's the culprit; ls does no expansion at all, even of (for example) D*. It's bash which does the expansion, and then passes the list off to the ls command.

To demonstrate this, use the echo command instead of the ls command; you'll get the same result.

bash doesn't use conventional regular expressions at all. To find out what it uses instead, do this at the command line:

man bash
and then skip down to

Pathname Expansion
Hope this helps.
Old 08-10-2007, 11:14 PM   #3
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 13,843

Rep: Reputation: 1453Reputation: 1453Reputation: 1453Reputation: 1453Reputation: 1453Reputation: 1453Reputation: 1453Reputation: 1453Reputation: 1453Reputation: 1453
And to add to that, maybe you're thinking of "find -type f ..." That'll allow regex as well.
Check the manpages.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting name and address from html page using grep and regex swiftguy121 Linux - Software 2 03-19-2007 01:41 AM
grep output on stdout and grep output to file don't match xnomad Linux - General 3 01-13-2007 05:56 AM
egrep/grep regex question buldir Programming 7 05-08-2006 08:17 PM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 12:38 PM
grep (possibly regex) question. mwtheobald Linux - Newbie 1 08-17-2002 04:05 PM

All times are GMT -5. The time now is 04:07 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration