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 (A)</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. (B)</p> Signup and view all the answers

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

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

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

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

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

<p>-C (A)</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

Flashcards

String

A sequence of characters, like a word, sentence, or even a single character.

grep

A tool that allows you to search for specific patterns within text files, using a special language called 'regular expressions.'

Regular Expression

A special type of text pattern that uses specific characters and symbols to match and find text in files.

grep Command

The command used to execute 'grep' and specify the text you want to find.

Signup and view all the flashcards

names.txt

A text file containing names, which you're searching using 'grep.'

Signup and view all the flashcards

'-w' option

The option used with 'grep' to search only for whole words and not partial matches.

Signup and view all the flashcards

'-i' option

The option used with 'grep' to ignore case sensitivity during the search.

Signup and view all the flashcards

'-n' option

The option used with 'grep' to display the line number of each matching line.

Signup and view all the flashcards

'-v' option

The option used with 'grep' to exclude lines that match the search pattern.

Signup and view all the flashcards

'-A' option

The option used with 'grep' to display 'N' lines after each matching line.

Signup and view all the flashcards

'-B' option

The option used with 'grep' to display 'N' lines before each matching line.

Signup and view all the flashcards

'-C' option

The option used with 'grep' to display 'N' lines around each matching line.

Signup and view all the flashcards

'-o' option

The option used with 'grep' to display only the matched text, not the complete line.

Signup and view all the flashcards

Alias

A shortcut to represent a command or a set of commands with custom options.

Signup and view all the flashcards

alias

The command that displays the list of defined aliases in the current user's profile.

Signup and view all the flashcards

Temporary Alias

A temporary alias that is only valid for the current shell session.

Signup and view all the flashcards

'.bashrc' file

The file where permanent aliases are stored for the Bash shell.

Signup and view all the flashcards

alias shortname='your custom command here'

The command used to define an alias temporarily.

Signup and view all the flashcards

Edit '.bashrc' file and add alias shortname='your custom command here'

The command used to define an alias permanently.

Signup and view all the flashcards

unalias lsl

The command used to remove an alias.

Signup and view all the flashcards

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