FedoraForum.org - Fedora Support Forums and Community
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2010
    Posts
    1

    filename wildcards

    I have three files in the directory, ABC.txt abc.txt ABC.abc.txt. When I do ls [A-Z]*[A-Z].txt, both ABC.txt and ABC.abc.txt show up. what's wrong with it?

  2. #2
    Join Date
    Nov 2005
    Posts
    451

    Re: filename wildcards

    I would like to know the answer to this as well. I can reproduce on F13 and CentOS 5:
    GNU bash, version 4.1.7(1)-release (x86_64-redhat-linux-gnu)
    GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)

    But this works as expected OS X 10.6:
    GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)

    (Edit: Forget I said it works on the Mac. It appeared to work because of HFS+'s weird case sensitivity rules; ABC.txt and abc.txt are the same file.)
    Last edited by icydog; 19th June 2010 at 11:16 PM. Reason: wrong info about OS X

  3. #3
    Join Date
    Jan 2010
    Posts
    7,158

    Re: filename wildcards

    AFAICT, I think you're only looking for the first two letters in the file name.
    ls anything beginning with A-Z. Then, 0 or any number of characters. Then anything from A-Z. Looks to me as if it should both, unless I'm overlooking something.

  4. #4
    Join Date
    Oct 2006
    Posts
    4,758

    Re: filename wildcards

    I don't know much about bash or regular expressions so...

    But once you say [A-Z]* wouldn't that mean match everything that starts with a capital, seems like anything you put after that * wouldn't even matter since it's already matching any character any number of times.

  5. #5
    Join Date
    Nov 2005
    Posts
    451

    Re: filename wildcards

    Quote Originally Posted by Dies
    I don't know much about bash or regular expressions so...

    But once you say [A-Z]* wouldn't that mean match everything that starts with a capital, seems like anything you put after that * wouldn't even matter since it's already matching any character any number of times.
    No, the stuff after the * is not ignored. For example, if you say "ls *.txt" you'd expect the stuff after * to not be ignored. (Trivia: in DOS before NT, the stuff after * on either side of the dot would get ignored, so "dir *a.txt" is the same as "dir *.txt")

    --

    Anyways, I found the answer. Like me, you're probably not using C sorting order. I'm using en_us.UTF-8. So it seems [A-Z] actually means [AbBcC.....zZ] which is every letter except lower case 'a'. How completely unintuitive! I've been doing it wrong all these years.

    http://www.gnu.org/software/bash/man...ttern-Matching

  6. #6
    Join Date
    Jul 2009
    Location
    England, UK
    Posts
    969

    Re: filename wildcards

    Quote Originally Posted by icydog
    Like me, you're probably not using C sorting order. I'm using en_us.UTF-8. So it seems [A-Z] actually means [AbBcC.....zZ] which is every letter except lower case 'a'. How completely unintuitive!
    Agreed!

    If you want the traditional (sensible) sorting order, use
    Code:
    export LC_ALL=C
    before using ls (or grep, or whatever else).

Similar Threads

  1. LAN diskless boot - MAC wildcards possible ?
    By live11 in forum Servers & Networking
    Replies: 2
    Last Post: 10th January 2010, 09:22 PM
  2. cp command with wildcards
    By pshepherd in forum Using Fedora
    Replies: 6
    Last Post: 3rd January 2007, 10:23 AM
  3. mv and wildcards: cannot move `A' to a subdirectory of itself
    By brianafischer in forum Using Fedora
    Replies: 7
    Last Post: 16th March 2006, 07:14 PM
  4. Using Wildcards with Yum - Can Ya? Can I?
    By chris_y2k_r1 in forum Using Fedora
    Replies: 8
    Last Post: 13th March 2006, 03:39 AM
  5. Error 1: Filename must be either an absolute filename or blocklist
    By Conquistador in forum Installation, Upgrades and Live Media
    Replies: 3
    Last Post: 4th January 2006, 06:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •