Gentoo Archives: gentoo-user

From: Michael Kjorling <michael@××××××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Bash Pattern Matching Syntax
Date: Sat, 15 Oct 2005 22:43:40
Message-Id: 435184e3.b77855f@vuk.kjorling.com
In Reply to: [gentoo-user] Bash Pattern Matching Syntax by Drew Tomlinson
1 -----BEGIN PGP SIGNED MESSAGE-----
2 Hash: SHA1
3
4 On 2005-10-15 15:25 -0700, drew@××××××××××××××.net wrote:
5 > I want to list the files in a directory that end in ".jpg" irregardless of
6 > case. Thus after reading the bash man page, it seems I should be able to
7 > issue a command something along the lines of "ls [*.[JjPpGg]]" or "ls
8 > *.[JjPpGg]" but neither of these work and return a "No such file or
9 > directory" message. What is the correct syntax for what I'm trying to do?
10
11 ls *.[jJ][pP][gG]
12
13 Each [] group matches a single character, so "ls *.[JjPpGg]" is "list
14 all files that end in a period followed by one of J, j, P, p, G or g".
15 Character ordering is irrelevant.
16
17 Alternatively, you could do:
18
19 ls | grep -i '.jpg$'
20
21 Or:
22
23 find . -maxdepth 1 -iname '*.jpg'
24
25 The find or ls-pipe-grep versions get a LOT cleaner when you have many
26 known characters with unknown case in the file name, but don't work if
27 you need to discriminate based on case for some characters and not by
28 others.
29
30 - --
31 Michael Kjörling, michael@××××××××.com - http://michael.kjorling.com/
32 * ASCII Ribbon Campaign: Against HTML Mail, Proprietary Attachments *
33 * ..... No bird soars too high if he soars with his own wings ..... *
34 -----BEGIN PGP SIGNATURE-----
35 Version: GnuPG v1.4.1 (GNU/Linux)
36
37 iD8DBQFDUYTjdY+HSb3praYRAulaAJ9P1LDLFnmu33HTTHFeXZwAGrAwRACfTmGF
38 8rnOP4hrj6gFZaoaArSqwjo=
39 =LuDd
40 -----END PGP SIGNATURE-----
41 --
42 gentoo-user@g.o mailing list

Replies

Subject Author
Re: [gentoo-user] Bash Pattern Matching Syntax Drew Tomlinson <drew@××××××××××××××.net>