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, 09:56 PM   #1
Senior Member
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 209Reputation: 209Reputation: 209
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 10:01 PM.
Old 08-10-2007, 10: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, 10:14 PM   #3
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 13,349

Rep: Reputation: 1303Reputation: 1303Reputation: 1303Reputation: 1303Reputation: 1303Reputation: 1303Reputation: 1303Reputation: 1303Reputation: 1303Reputation: 1303
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 12:41 AM
grep output on stdout and grep output to file don't match xnomad Linux - General 3 01-13-2007 04:56 AM
egrep/grep regex question buldir Programming 7 05-08-2006 07:17 PM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 11:38 AM
grep (possibly regex) question. mwtheobald Linux - Newbie 1 08-17-2002 03:05 PM

All times are GMT -5. The time now is 12:16 PM.

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