LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-03-2010, 10:38 AM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Rep: Reputation: 76
ls lacks options?


Hi:

Suppose I have file ./My_Lasker_Games.pdf but all I know about the name is the it contains 'Lasker'. Then ls *lasker* won't do any good, because ls has no option for case sensibility. The outcome is that I'm forced to use find.

Wouldn't it be nice that ls had an option --ignore-case? Thanks for reading.

Last edited by stf92; 11-05-2010 at 05:18 PM.
 
Old 11-03-2010, 10:40 AM   #2
pljvaldez
LQ Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Wheezy (x86)
Posts: 6,094

Rep: Reputation: 281Reputation: 281Reputation: 281
ls | grep -i lasker
 
Old 11-03-2010, 10:40 AM   #3
HasC
Member
 
Registered: Oct 2009
Location: South America - Paraguay
Distribution: Debian 5 - Slackware 13.1 - Arch - Some others linuxes/*BSDs through KVM and Xen
Posts: 329

Rep: Reputation: 55
IMHO, it's easier to use something like
Code:
$ ls *lasker* *Lasker*
, without adding any complexity, and potential of bugs
 
Old 11-03-2010, 10:43 AM   #4
HasC
Member
 
Registered: Oct 2009
Location: South America - Paraguay
Distribution: Debian 5 - Slackware 13.1 - Arch - Some others linuxes/*BSDs through KVM and Xen
Posts: 329

Rep: Reputation: 55
Quote:
Originally Posted by pljvaldez View Post
ls | grep -i lasker
Or doing that, a classical example of unix-like principle of synergy
 
Old 11-03-2010, 10:53 AM   #5
udaman
Member
 
Registered: Oct 2010
Location: New England, USA
Distribution: OpenSUSE/Slackware64/RHEL/Mythbuntu
Posts: 189

Rep: Reputation: 39
Simpler still,

Code:
$ ls *?asker*
lasker
 
Old 11-03-2010, 10:55 AM   #6
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Thanks. Anyways, I do not understand people who say ls has a great many options. To the degree that the cdrecord manual says:
BUGS:
Cdrecord has even more options than ls.
[END QUOTE]

ls has no more than 50 options, whereas the options in cdrecord are counted by the hundreds. And a lot linux programs have a much larger quantity of options than ls.
 
Old 11-03-2010, 10:59 AM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Or use shopt -s nocaseglob and shell filename expansion (a * will do):
Code:
c@CW8:/tmp$ shopt -s nocaseglob
c@CW8:/tmp$ ls *lasker
Lasker
 
1 members found this post helpful.
Old 11-03-2010, 11:04 AM   #8
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
That's a good one.
 
Old 11-03-2010, 11:11 AM   #9
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
The * is the most common pattern-matching symbol used in what is called "globbing", but there are other forms as well.

To match any single character, use ?.
Code:
ls ?asker*
And to match a selection or range of characters, use []
Code:
ls [lL]asker*

ls [a-Z]asker*
To exclude a character from a match, use ^ or ! as the first character in [].
Code:
ls [^m]asker*
You can read more about it here:

http://tldp.org/LDP/Bash-Beginners-G...ect_04_03.html

For more complex stuff, you'll need to use a tool like grep and regular expressions. This is covered in the rest of section 4 at the above link.

Finally, there's also an optional selection of extended globbing functions, explained here:
http://www.linuxjournal.com/content/...ended-globbing


Of course, depending on how accurate you need the match to be, you could just leave off the first letter entirely.
Code:
ls *asker*
 
Old 11-03-2010, 11:36 AM   #10
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
By the way, the idea for an "ignore case" option in ls really doesn't seem very applicable to the way it functions. All ls really does is print out any files or directory contents that match the list you feed it. If you look at the options it does have, they're mostly there to control the formatting of the output (including what not to print). The input for ls is already effectively controlled by shell globbing, as already posted.

An example of a really useful new option for ls would be some way to easily exclude directories from the output.
http://www.linuxquestions.org/questi...tories-835962/
 
1 members found this post helpful.
Old 11-03-2010, 11:01 PM   #11
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Thanks David. And a special greeting to catkin for his truly useful post.

Last edited by stf92; 11-05-2010 at 06:24 PM.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
KGhostView lacks find command? stf92 Linux - Software 4 07-18-2010 11:56 AM
mv lacks --recursive option. cp does not. stf92 Linux - Newbie 6 05-17-2009 03:55 AM
Xubuntu Partitioner lacks an option Nazurin Linux - Newbie 1 12-24-2008 01:43 PM
fsck (lacks LARGE_FILE flag) MrLobster Linux - Software 1 01-09-2006 07:04 PM
Mplayer lacks an icon... ?!? Bakambauer Linux - Software 4 04-10-2004 04:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration