Podcast
Questions and Answers
What is the term used to describe the pattern matching feature in the Unix shell?
What is the term used to describe the pattern matching feature in the Unix shell?
What type of names can be matched by GLOB patterns?
What type of names can be matched by GLOB patterns?
What is the purpose of the shell when it encounters a GLOB pattern?
What is the purpose of the shell when it encounters a GLOB pattern?
What is the definition of a meta-character in the shell?
What is the definition of a meta-character in the shell?
Signup and view all the answers
What is the purpose of quoting in the shell?
What is the purpose of quoting in the shell?
Signup and view all the answers
What is a token in the shell?
What is a token in the shell?
Signup and view all the answers
What is the result of the command cp a*..
?
What is the result of the command cp a*..
?
Signup and view all the answers
What is the term used to describe the characters that the shell will try to expand to match existing pathnames in the file system?
What is the term used to describe the characters that the shell will try to expand to match existing pathnames in the file system?
Signup and view all the answers
What is the purpose of the ! or ^ symbol in a GLOB square bracket list?
What is the purpose of the ! or ^ symbol in a GLOB square bracket list?
Signup and view all the answers
What is the effect of using a range of letters in a GLOB square bracket list on a modern Linux machine?
What is the effect of using a range of letters in a GLOB square bracket list on a modern Linux machine?
Signup and view all the answers
What is the purpose of the [.] pattern in a GLOB pattern?
What is the purpose of the [.] pattern in a GLOB pattern?
Signup and view all the answers
What is the difference between the GLOB patterns [aA] and [a][A]?
What is the difference between the GLOB patterns [aA] and [a][A]?
Signup and view all the answers
Why is it recommended to only use ranges of digits in a GLOB square bracket list?
Why is it recommended to only use ranges of digits in a GLOB square bracket list?
Signup and view all the answers
What is the default behavior of GLOB patterns in terms of case sensitivity?
What is the default behavior of GLOB patterns in terms of case sensitivity?
Signup and view all the answers
What is the purpose of using the * character in a GLOB pattern?
What is the purpose of using the * character in a GLOB pattern?
Signup and view all the answers
What is the effect of using the pattern [a] in a GLOB pattern?
What is the effect of using the pattern [a] in a GLOB pattern?
Signup and view all the answers
How can you match both upper-case and lower-case letters in names?
How can you match both upper-case and lower-case letters in names?
Signup and view all the answers
What is the purpose of using [:upper:] in a GLOB pattern?
What is the purpose of using [:upper:] in a GLOB pattern?
Signup and view all the answers
What is the result of running the command 'echo [aA]bc'?
What is the result of running the command 'echo [aA]bc'?
Signup and view all the answers
What is the purpose of using echo or ls command to verify GLOB patterns?
What is the purpose of using echo or ls command to verify GLOB patterns?
Signup and view all the answers
What is the result of running the command 'echo [:alpha:]'?
What is the result of running the command 'echo [:alpha:]'?
Signup and view all the answers
How can you match all files starting with an uppercase letter?
How can you match all files starting with an uppercase letter?
Signup and view all the answers
What is the result of running the command 'echo [abc]'?
What is the result of running the command 'echo [abc]'?
Signup and view all the answers
What is the purpose of using character classes in GLOB patterns?
What is the purpose of using character classes in GLOB patterns?
Signup and view all the answers
What happens to the GLOB pattern before the command is executed?
What happens to the GLOB pattern before the command is executed?
Signup and view all the answers
What is the purpose of quoting in GLOB patterns?
What is the purpose of quoting in GLOB patterns?
Signup and view all the answers
What is the result of running the command find /usr/bin -name *ho*
?
What is the result of running the command find /usr/bin -name *ho*
?
Signup and view all the answers
What is the purpose of piping the output into a pagination program such as less?
What is the purpose of piping the output into a pagination program such as less?
Signup and view all the answers
What is the result of running the command echo "\*"
?
What is the result of running the command echo "\*"
?
Signup and view all the answers
What is the effect of not quoting the GLOB pattern in a command?
What is the effect of not quoting the GLOB pattern in a command?
Signup and view all the answers
What is the purpose of the find
command in the example?
What is the purpose of the find
command in the example?
Signup and view all the answers
What is the effect of preceding a GLOB meta-character with a backslash?
What is the effect of preceding a GLOB meta-character with a backslash?
Signup and view all the answers
What does the command **echo *** never show?
What does the command **echo *** never show?
Signup and view all the answers
What does the pattern *foo match?
What does the pattern *foo match?
Signup and view all the answers
What does the pattern ??? match?
What does the pattern ??? match?
Signup and view all the answers
What does the pattern [abc] match?
What does the pattern [abc] match?
Signup and view all the answers
What does the command echo ? never show?
What does the command echo ? never show?
Signup and view all the answers
What does the pattern *foo* match?
What does the pattern *foo* match?
Signup and view all the answers
What is the difference between the patterns ? and [abc]?
What is the difference between the patterns ? and [abc]?
Signup and view all the answers
What does the pattern ???* match?
What does the pattern ???* match?
Signup and view all the answers
Study Notes
GLOB Patterns
- GLOB patterns are used for pathname-matching (wildcard) in the shell.
- The shell will try to expand GLOB patterns into existing pathnames in the file system.
- GLOB patterns cannot generate any names that do not exist; they must always match existing names.
Square Brackets [ ]
- The square brackets [ ] are used to match a single character from a list of characters.
- The [ ] pattern always matches exactly one character, regardless of how many characters are listed within.
- [aA] is one list that matches only one-character name, either a or A.
- [a][A] is made of two lists that match aA.
- Having a GLOB square bracket list with only one character in it, e.g., [a], is not usually useful; instead, use the equivalent and much simpler *abc.
Inverting Selecting in [ ]
- You can have a [ ] select any character that isn't listed by adding an ! or ^ immediately after the [.
- Example: echo [!abc] # Match any character that is not a or b or c.
Using Ranges of Letters in [ ]
- You can use a dash - to indicate a range of digits inside a [ ] list.
- Example: touch 1 2 3 4 5; echo [2-4] # Match 2, 3, and 4.
- Important: Don't use ranges of letters, e.g., [a-c], unless you fully understand the effects of your machine's locale setting.
Using [ ] to Match Case Insensitive Patterns
- GLOB patterns are case-sensitive.
- You can make each letter into its own little two-character [ ] list to match both upper-case and lower-case letters.
- Example: touch abc aBc aBC ABc ABC Abc; echo [aA]bc # Match Abc and abc.
Matching Character Classes
- There are certain preset character classes (part of the POSIX standard) that can be used inside a list to match any letter belonging to a certain class.
- Character classes:
- [:upper:] - All uppercase letters
- [:lower:] - All lowercase letters
- [:alpha:] - All letters
- [:digit:] - All digits, equivalent to [0-9]
- [:alnum:] - All letters and digits
- Example: echo [:lower:] # Match all lowercase letters.
Verifying GLOB Patterns
- Use the echo or ls command to see what names are being matched (if any) before using a GLOB pattern.
- Example: echo [abc]* # Verify that the GLOB pattern works.
Pattern Explanation
- *foo - Matches non-hidden names ending with foo
- foo* - Matches non-hidden names beginning with foo
- foo - Matches non-hidden names containing foo anywhere
Using ? to Match Single Characters
- The question mark ? matches exactly one of any character in a name, including a space or other symbols.
- The command echo ? never shows the current directory name . that is a single dot.
- Example: ??? - Matches non-hidden names that are exactly three characters long.
- Example: ???* - Matches non-hidden names that are three or more characters long.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Learn about GLOB patterns used for pathname-matching in the shell and how they work with square brackets to match characters. Understand the rules of GLOB patterns and how they expand into existing pathnames.