Tips Linux Explorers   All Things Linux Forum   Great Linux Links   Hometown    


Today we start a series of 2: Global Expressions and Regular Expressions.
Not really easy to explain but I´ll have a go at it, trying to keep it simple and only mentioning what the basics are. ( We use Global expressions to search files, Regular expressions to search in files )

Global expressions are mostly used in combination with the command ¨ls¨ ( list files ).
I suppose you know that the ¨*¨ sign is a wild-card and can stand for one or more characters. The ¨?¨ is a wild-card for only 1 character. The ¨!¨ excludes the characters that follow.

Here are some examples:

$ ls [a-e]*

This will only list the files that start with a, b, c, d or e. ( Not A or B ! )

$ ls [a-eA-E]*

Will do the same but then also A, B ,C ,D and E

$ ls *[a-e]us

The files that end with: aus, bus, cus, dus and eus

$ ls ?[a-e]re

Will show the files; dare, acre, mere, bare, . . . etc.

$ ls *[!a-b]re

Shows files that end with ¨re¨, but not the ones on ¨are¨ or ¨bre¨

$ ls *.{jpg,png,gif}

List all the files that end with .jpg, .png and .gif

Notice the difference in { } and [ ] !!!

This is as far as I go with Global Expressions, tomorrow we do the Regular Expressions, that is not as straightforward as the Global ones, but as I said before: I will do the ultimate to keep it simple !


-- Jun 23 2003 ( Revised Dec 10 2005 ) --

Tips Linux Explorers   All Things Linux Forum   Great Linux Links   Hometown