LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices

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

Rep: Reputation: 207Reputation: 207Reputation: 207
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.

..does ls only do wildcard?

Last edited by jhwilliams; 08-10-2007 at 10:01 PM.
 
Old 08-10-2007, 10:10 PM   #2
wjevans_7d1@yahoo.co
Member
 
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:

Code:
man bash
and then skip down to

Code:
Pathname Expansion
Hope this helps.
 
Old 08-10-2007, 10:14 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,351

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


Reply


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 01:37 PM.

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