LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-06-2008, 09:54 AM   #1
vineet7kumar
Member
 
Registered: Aug 2005
Posts: 75

Rep: Reputation: 15
issue with the command "ls *[0-9A-Z]"


Hi,

I was using a RHEL system.
I wanted to list the files whose filenames ended in a digit or an uppercase alphabet.
So I used the command

Code:
$ ls *[0-9A-Z]
However it also listed all the files ending in all lowercase letters except 'a'(lowercase).

What is the explanation for such a behavior?

Thanks and Regards,
Vineet
 
Old 11-06-2008, 12:47 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Is there any chance that you have directories
ending in a digit or uppercase, and these may
contain other files?


Cheers,
Tink
 
Old 11-07-2008, 11:56 AM   #3
vineet7kumar
Member
 
Registered: Aug 2005
Posts: 75

Original Poster
Rep: Reputation: 15
While I tried this I did not have such a directory but yes it may be possible.
 
Old 11-07-2008, 12:41 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
This appears to work:
ls|grep "[0-9A-Z]\b"

"\b" means word boundary
 
Old 11-07-2008, 12:45 PM   #5
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,078

Rep: Reputation: 195Reputation: 195
I'm assuming your shell is bash.

I suspect A-Z is being expanded to aAbBcD......zZ so A-Z matches the entire alphabet in both upper and lower case. It's not a bug, more a quirk. Try typing:

Code:
$ LC_COLLATE=C
Then run your command again and you'll probably get a different result. If you don't want to list the contents of directories use the -d flag for ls.

Further reading:
http://www.linuxquestions.org/questi...case.-327916/3
http://groups.google.com/group/gnu.b...dde343a54e3c14
 
Old 11-08-2008, 03:22 PM   #6
vineet7kumar
Member
 
Registered: Aug 2005
Posts: 75

Original Poster
Rep: Reputation: 15
But according to the rules [a-z] and [A-Z] are completely different. Moreover as I said file names ending in 'a' are not shown but those ending in 'b-z' are shown. If A-Z is expanded as aAbB...zZ then it should show file names ending with 'a' also.
I know this is not a bug ....but then why does this happen?


Regards,
Vineet
 
Old 11-08-2008, 03:33 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
I cannot reproduce that behaviour; the only valid explanation
for this is my directory-theory. I really can't imagine that they
would have introduced a bug like this in recent versions of
ls and/or bash w/o a major repercussion.



Cheers,
Tink
 
Old 11-08-2008, 03:39 PM   #8
vineet7kumar
Member
 
Registered: Aug 2005
Posts: 75

Original Poster
Rep: Reputation: 15
I guess there might be some issue with my system settings.
I tried setting LC_ALL to 'C' and I was even unable to create files having uppercase characters in their names.
My LANG variable is set to en_IN.
It will be interesting for me to get into this as a newbie
 
Old 11-08-2008, 03:45 PM   #9
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by vineet7kumar View Post
Moreover as I said file names ending in 'a' are not shown but those ending in 'b-z' are shown. If A-Z is expanded as aAbB...zZ then it should show file names ending with 'a' also.
Nope. It is correct because if you have the sequence aAbB...zZ, the interval [A-Z] leaves out the first element of the list.
 
Old 11-08-2008, 03:49 PM   #10
vineet7kumar
Member
 
Registered: Aug 2005
Posts: 75

Original Poster
Rep: Reputation: 15
But why does that happen?
 
Old 11-08-2008, 04:38 PM   #11
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Well, I am not an expert in this fields, but recent linux distributions follow table 1 of the standard ISO 14651 "International string ordering and comparison". The collating sequence is defined following this standard and it affects not only sorting but character ranges in some regular expressions.

Apart language settings and collating sequences, a more simple explanation of this behaviour is given by the Advanced Bash Scripting Guide:
Quote:
As of version 2.05 of Bash, filename globbing no longer distinguishes between
lowercase and uppercase letters in a character range between brackets. For example, ls
[A−M]* would match both File1.txt and file1.txt. To revert to the
customary behavior of bracket matching, set LC_COLLATE to C by an export
LC_COLLATE=C in /etc/profile and/or ~/.bashrc.
 
  


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
Newbie - OSX "command not found" Path issue Pinball2k Other *NIX 11 10-19-2008 05:00 PM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 11:18 PM
How to issue "ls" command start with the largest file size in a folder? fjkum Linux - Newbie 5 07-27-2006 04:28 AM
why must i issue a "pump" command after every boot? mushmaster Linux - General 4 09-12-2004 09:56 PM
My system freezes after I issue the "modprobe ndiswrapper" command. markjc Linux - Wireless Networking 1 08-24-2004 10:47 AM


All times are GMT -5. The time now is 08:38 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration