Network Operating Systems GREP Command Quiz
14 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 does the grep command do?

The grep command is used to search for a pattern of characters in a file and display the matching lines.

What is the purpose of regular expression in searching text?

Regular expression provides the ability to match a string of text in a flexible and concise manner.

What does the -w option do in the grep command?

  • It ignores the line of the searched string.
  • It searches for the entire word only. (correct)
  • It searches for the matched line number.
  • It searches for the entire pattern only
  • By default, the grep command is Case-Sensitive.

    <p>True</p> Signup and view all the answers

    How can you make the grep command Case-Insensitive?

    <p>The <code>-i</code> option makes the <code>grep</code> command Case-Insensitive.</p> Signup and view all the answers

    What is the purpose of the -v option in the grep command?

    <p>It ignores the line of the searched string.</p> Signup and view all the answers

    Which option in the grep command will print `N' lines after the matched line?

    <p>-A</p> Signup and view all the answers

    Which option in the grep command will print 'N' lines before the matched line?

    <p>-B</p> Signup and view all the answers

    Which option in the grep command will print 'N' lines around the matched line?

    <p>-C</p> Signup and view all the answers

    What are aliases in Linux?

    <p>Aliases are custom shortcuts used to represent a command or set of commands, executed with or without custom options.</p> Signup and view all the answers

    How do you list all defined aliases in Linux?

    <p>You can use the <code>alias</code> command to display a list of all currently defined aliases on your profile.</p> Signup and view all the answers

    How to define an alias temporarily in Linux?

    <p>To define an alias temporarily, you can use the command <code>alias alias_name='your_command'</code>.</p> Signup and view all the answers

    How to define an alias permanently?

    <p>To make an alias permanently defined in Linux, you need to set it in the <code>.bashrc</code> file, which is the configuration file for the bash shell.</p> Signup and view all the answers

    How do you remove an alias in Linux?

    <p>You can remove an alias in Linux using the command <code>unalias alias_name</code>.</p> Signup and view all the answers

    Study Notes

    Network Operating Systems - GREP and Aliasing

    • Regular expressions allow flexible and concise matching of text strings. Text strings can be a single character, word, sentence or a pattern of characters.

    GREP Command

    • grep (Global Regular Expression Print) command prints lines of text matching a regular expression.

    • Displays a list of lines matching a pattern within a text file.

    • The presented examples use grep with a target text file named names.txt. This file contains a list of names.

    Searching in Files

    • To find a specific line in names.txt, use grep "Brad William" names.txt.

    Whole Word Match

    • Using grep -w "Brad Williamson" ensures only complete words match.
    • grep -i "Chris Evans" or grep -wi "Chris Evans" perform a case insensitive search.

    Line Numbering

    • grep -n "Chris Evans" displays the line number of matching lines.

    Displaying Lines Around Matches

    • grep -A 2 "Chris Evans" shows the matched line and the two following lines.

    • grep -B 2 "Chris Evans" displays the matched line and the two preceding lines.

    • grep -C 2 "Chris Evans" shows the matched line and the two lines before and after the matched line.

    Printing Only Matched Strings

    • grep -o "Chris" prints only the matched substring "Chris".
    • grep -oi "Chris" performs the same operation while ignoring case.
    • Using the -o option to extract matched strings only instead of complete lines.

    Aliases

    • Aliases are custom shortcuts for commands or sets of commands.
    • Aliases are only active during a specific shell session.

    Listing Aliases

    • The alias command displays defined aliases.

    Defining Aliases Temporarily

    • alias shortname='your custom command here' sets a temporary alias; the alias is discarded when the current session ends.

    Defining Aliases Permanently

    • Defining an alias permanently requires modification of the .bashrc file. These changes make the alias available for all subsequent sessions using the same shell. A .bashrc example was given.

    Removing Aliases

    • unalias ls removes the alias for a command.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    Description

    Test your knowledge on the GREP command in Network Operating Systems. This quiz covers key concepts such as regular expressions, case-insensitive searches, and line numbering. Prepare to demonstrate your understanding of searching through text files effectively.

    More Like This

    Use Quizgecko on...
    Browser
    Browser