public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-user] Bash Pattern Matching Syntax
@ 2005-10-15 22:25 Drew Tomlinson
  2005-10-15 22:38 ` Michael Kjorling
  0 siblings, 1 reply; 3+ messages in thread
From: Drew Tomlinson @ 2005-10-15 22:25 UTC (permalink / raw
  To: Gentoo Users

I want to list the files in a directory that end in ".jpg" irregardless 
of case.  Thus after reading the bash man page, it seems I should be 
able to issue a command something along the lines of "ls [*.[JjPpGg]]"  
or "ls *.[JjPpGg]" but neither of these work and return a "No such file 
or directory" message.  What is the correct syntax for what I'm trying 
to do?

Thanks,

Drew

-- 
Visit The Alchemist's Warehouse
Magic Tricks, DVDs, Videos, Books, & More!

http://www.alchemistswarehouse.com

-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [gentoo-user] Bash Pattern Matching Syntax
  2005-10-15 22:25 [gentoo-user] Bash Pattern Matching Syntax Drew Tomlinson
@ 2005-10-15 22:38 ` Michael Kjorling
  2005-10-15 23:02   ` Drew Tomlinson
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Kjorling @ 2005-10-15 22:38 UTC (permalink / raw
  To: gentoo-user

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 2005-10-15 15:25 -0700, drew@mykitchentable.net wrote:
> I want to list the files in a directory that end in ".jpg" irregardless of 
> case.  Thus after reading the bash man page, it seems I should be able to 
> issue a command something along the lines of "ls [*.[JjPpGg]]"  or "ls 
> *.[JjPpGg]" but neither of these work and return a "No such file or 
> directory" message.  What is the correct syntax for what I'm trying to do?

ls *.[jJ][pP][gG]

Each [] group matches a single character, so "ls *.[JjPpGg]" is "list
all files that end in a period followed by one of J, j, P, p, G or g".
Character ordering is irrelevant.

Alternatively, you could do:

ls | grep -i '.jpg$'

Or:

find . -maxdepth 1 -iname '*.jpg'

The find or ls-pipe-grep versions get a LOT cleaner when you have many
known characters with unknown case in the file name, but don't work if
you need to discriminate based on case for some characters and not by
others.

- -- 
Michael Kjörling, michael@kjorling.com - http://michael.kjorling.com/
* ASCII Ribbon Campaign: Against HTML Mail, Proprietary Attachments *
* ..... No bird soars too high if he soars with his own wings ..... *
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDUYTjdY+HSb3praYRAulaAJ9P1LDLFnmu33HTTHFeXZwAGrAwRACfTmGF
8rnOP4hrj6gFZaoaArSqwjo=
=LuDd
-----END PGP SIGNATURE-----
-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [gentoo-user] Bash Pattern Matching Syntax
  2005-10-15 22:38 ` Michael Kjorling
@ 2005-10-15 23:02   ` Drew Tomlinson
  0 siblings, 0 replies; 3+ messages in thread
From: Drew Tomlinson @ 2005-10-15 23:02 UTC (permalink / raw
  To: gentoo-user

On 10/15/2005 3:38 PM Michael Kjorling wrote:

>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>On 2005-10-15 15:25 -0700, drew@mykitchentable.net wrote:
>  
>
>>I want to list the files in a directory that end in ".jpg" irregardless of 
>>case.  Thus after reading the bash man page, it seems I should be able to 
>>issue a command something along the lines of "ls [*.[JjPpGg]]"  or "ls 
>>*.[JjPpGg]" but neither of these work and return a "No such file or 
>>directory" message.  What is the correct syntax for what I'm trying to do?
>>    
>>
>
>ls *.[jJ][pP][gG]
>
>Each [] group matches a single character, so "ls *.[JjPpGg]" is "list
>all files that end in a period followed by one of J, j, P, p, G or g".
>Character ordering is irrelevant.
>
>Alternatively, you could do:
>
>ls | grep -i '.jpg$'
>
>Or:
>
>find . -maxdepth 1 -iname '*.jpg'
>
>The find or ls-pipe-grep versions get a LOT cleaner when you have many
>known characters with unknown case in the file name, but don't work if
>you need to discriminate based on case for some characters and not by
>others.
>

Thank you very much for your explanation.  This works well!!!

Cheers,

Drew

-- 
Visit The Alchemist's Warehouse
Magic Tricks, DVDs, Videos, Books, & More!

http://www.alchemistswarehouse.com

-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-10-15 23:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-15 22:25 [gentoo-user] Bash Pattern Matching Syntax Drew Tomlinson
2005-10-15 22:38 ` Michael Kjorling
2005-10-15 23:02   ` Drew Tomlinson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox