CEST-CE Term_2 GNU/LINUX (Week 6)
40 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the term used to describe the pattern matching feature in the Unix shell?

  • Wildcard
  • GLOBbing (correct)
  • Pathname matching
  • Regexp
  • What type of names can be matched by GLOB patterns?

  • Any kind of name, including files, directories, and symbolic links (correct)
  • Only directory names
  • Only file names
  • Only hidden files
  • What is the purpose of the shell when it encounters a GLOB pattern?

  • To prompt the user for confirmation
  • To generate new names that do not exist
  • To replace the pattern with every matching existing pathname (correct)
  • To ignore the pattern and move on to the next command
  • What is the definition of a meta-character in the shell?

    <p>A character that has a special meaning to the shell</p> Signup and view all the answers

    What is the purpose of quoting in the shell?

    <p>To make a meta-character a regular character</p> Signup and view all the answers

    What is a token in the shell?

    <p>A small meaningful part of a command</p> Signup and view all the answers

    What is the result of the command cp a*..?

    <p>It copies all files starting with 'a' to the parent directory</p> 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?

    <p>GLOB patterns</p> Signup and view all the answers

    What is the purpose of the ! or ^ symbol in a GLOB square bracket list?

    <p>To match any character that isn't listed</p> 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?

    <p>It matches the exact characters specified in the range, as well as their uppercase and lowercase counterparts</p> Signup and view all the answers

    What is the purpose of the [.] pattern in a GLOB pattern?

    <p>To match any hidden file</p> Signup and view all the answers

    What is the difference between the GLOB patterns [aA] and [a][A]?

    <p>The first matches only single-character names, while the second matches only two-character names</p> Signup and view all the answers

    Why is it recommended to only use ranges of digits in a GLOB square bracket list?

    <p>Because it avoids issues with locale settings</p> Signup and view all the answers

    What is the default behavior of GLOB patterns in terms of case sensitivity?

    <p>They are case-sensitive</p> Signup and view all the answers

    What is the purpose of using the * character in a GLOB pattern?

    <p>To match any file or directory</p> Signup and view all the answers

    What is the effect of using the pattern [a] in a GLOB pattern?

    <p>It matches only files that contain exactly one character, which is a</p> Signup and view all the answers

    How can you match both upper-case and lower-case letters in names?

    <p>Make each letter into its own little two-character list</p> Signup and view all the answers

    What is the purpose of using [:upper:] in a GLOB pattern?

    <p>To match all uppercase letters</p> Signup and view all the answers

    What is the result of running the command 'echo [aA]bc'?

    <p>It will match both files 'abc' and 'Abc'</p> Signup and view all the answers

    What is the purpose of using echo or ls command to verify GLOB patterns?

    <p>To avoid taking action on the wrong files with more impactful commands</p> Signup and view all the answers

    What is the result of running the command 'echo [:alpha:]'?

    <p>It will match all files starting with a letter</p> Signup and view all the answers

    How can you match all files starting with an uppercase letter?

    <p>Using the command 'echo [:upper:]*'</p> Signup and view all the answers

    What is the result of running the command 'echo [abc]'?

    <p>It will match all files containing the characters 'a', 'b', or 'c'</p> Signup and view all the answers

    What is the purpose of using character classes in GLOB patterns?

    <p>To match files based on a certain class of characters</p> Signup and view all the answers

    What happens to the GLOB pattern before the command is executed?

    <p>The shell processes the GLOB pattern</p> Signup and view all the answers

    What is the purpose of quoting in GLOB patterns?

    <p>To hide GLOB meta-characters from the shell</p> Signup and view all the answers

    What is the result of running the command find /usr/bin -name *ho*?

    <p>The shell replaces <em>ho</em> with matching pathnames</p> Signup and view all the answers

    What is the purpose of piping the output into a pagination program such as less?

    <p>To handle too many matches</p> Signup and view all the answers

    What is the result of running the command echo "\*"?

    <p>The command prints a single asterisk (*)</p> Signup and view all the answers

    What is the effect of not quoting the GLOB pattern in a command?

    <p>The shell processes the GLOB pattern</p> Signup and view all the answers

    What is the purpose of the find command in the example?

    <p>To search for files in the /usr/bin directory</p> Signup and view all the answers

    What is the effect of preceding a GLOB meta-character with a backslash?

    <p>The shell processes the GLOB pattern as a literal character</p> Signup and view all the answers

    What does the command **echo *** never show?

    <p>Names starting with a period</p> Signup and view all the answers

    What does the pattern *foo match?

    <p>Names ending with <strong>foo</strong></p> Signup and view all the answers

    What does the pattern ??? match?

    <p>Names with exactly three characters</p> Signup and view all the answers

    What does the pattern [abc] match?

    <p>Names with exactly one character that is <strong>a</strong>, <strong>b</strong>, or <strong>c</strong></p> Signup and view all the answers

    What does the command echo ? never show?

    <p>The current directory name <strong>.</strong></p> Signup and view all the answers

    What does the pattern *foo* match?

    <p>Names containing <strong>foo</strong> anywhere</p> Signup and view all the answers

    What is the difference between the patterns ? and [abc]?

    <p>The pattern <strong>?</strong> matches any character, while the pattern <strong>[abc]</strong> matches any character in the list</p> Signup and view all the answers

    What does the pattern ???* match?

    <p>Names that are three or more characters long</p> 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.

    Quiz Team

    Related Documents

    Week 6.docx

    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.

    More Like This

    Glob (1)
    5 questions

    Glob (1)

    LushMossAgate1393 avatar
    LushMossAgate1393
    Glob (2)
    7 questions

    Glob (2)

    LushMossAgate1393 avatar
    LushMossAgate1393
    Use Quizgecko on...
    Browser
    Browser