Blog

MCQs

Disclaimer:

Educational Use Only:

The website links provided are to be used strictly for educational and knowledge-gaining purposes only.

No Misuse:

Do not misuse the links or the information contained therein for any commercial, illegal, or unethical activities.

Respect for Websites and Businesses:

Respect the intellectual property and business interests of the websites and their owners. Do not attempt to alter, copy, or redistribute content without proper authorization.

Acknowledge Value of Knowledge:

Recognize and value the knowledge and resources shared by these websites. Use the information responsibly and ethically.

No Endorsement:

The provision of these links does not imply endorsement of the linked sites, their content, or their products and services. Users are responsible for evaluating the suitability and accuracy of the information.

User Responsibility:

By accessing these links, you agree to use the information at your own risk and to comply with all applicable laws and website terms of use.


  1. What is the main purpose of the grep command in Linux?
    a. Searching for web pages
    b. Editing files
    c. Searching for patterns in text
    d. Managing user permissions
    Answer: c. Searching for patterns in texteitca+2
  2. Which option with grep makes the search case-insensitive?
    a. -l
    b. -i
    c. -v
    d. -c
    Answer: b. -ilabex+2
  3. Which symbol in grep is used to specify a regular expression?
    a. *
    b. %
    c. @
    d. $
    Answer: a. *infosecinstitute+1
  4. What is the correct basic syntax to use grep for searching for “error” in a file named logfile.txt?
    a. grep -i error logfile
    b. grep “logfile.txt” error
    c. grep error logfile.txt
    d. error grep logfile.txt
    Answer: c. grep error logfile.txtcyberciti+2
  5. Which grep option shows only the count of matching lines?
    a. -n
    b. -c
    c. -v
    d. -r
    Answer: b. -cgeeksforgeeks+1
  6. grep ‘error’ *.log will do what?
    a. Delete all files
    b. Search for ‘error’ in all .log files
    c. Rename files with .log extension
    d. Encrypt log files
    Answer: b. Search for ‘error’ in all .log fileseitca+1
  7. How can you invert a match to show lines that do NOT contain a pattern with grep?
    a. -i
    b. -c
    c. -v
    d. -r
    Answer: c. -vlabex+2
  8. What does grep -n pattern file.txt display?
    a. Only filenames
    b. Number of files
    c. Matching lines with line numbers
    d. File permissions
    Answer: c. Matching lines with line numbersgeeksforgeeks+1
  9. Which grep option searches files recursively in subdirectories?
    a. -v
    b. -E
    c. -r
    d. -l
    Answer: c. -rcyberciti+2
  10. What does the output of grep ‘root’ /etc/passwd show?
    a. User passwords
    b. Only empty lines
    c. All lines containing ‘root’
    d. Line numbers only
    Answer: c. All lines containing ‘root’eitca+1
  11. Which regular expression matches both ‘Error’ and ‘error’?
    a. grep [Ee]rror file.txt
    b. grep (Error|error) file.txt
    c. Both a and b
    d. None of the above
    Answer: c. Both a and bdigitalocean+1
  12. What does the -l option do in grep?
    a. Print filenames only
    b. Show last lines
    c. Print line numbers
    d. Print lowercase only
    Answer: a. Print filenames onlygeeksforgeeks+2
  13. The origin of the name “grep” is:
    a. Grouping Repetitive Entries Processor
    b. Global Regular Expression Print
    c. Generic Report Extractor Program
    d. General Repeat Pattern
    Answer: b. Global Regular Expression Printdigitalocean+1
  14. What will grep ‘^user’ file.txt match?
    a. Lines ending with ‘user’
    b. Lines starting with ‘user’
    c. Any line containing ‘user’
    d. Lines with only ‘user’
    Answer: b. Lines starting with ‘user’digitalocean+1
  15. Which option with grep allows using extended regular expressions?
    a. -r
    b. -E
    c. -v
    d. -C
    Answer: b. -Esanfoundry+2
  16. What does grep ‘.’ file.txt match?
    a. Only empty lines
    b. Only lines with at least one character
    c. Only numbers
    d. Only capital letters
    Answer: b. Only lines with at least one characterinfosecinstitute+1
  17. Which brackets in a pattern specify a character class with grep?
    a. ( )
    b. { }
    c. [ ]
    d. < >
    Answer: c. [ ]sanfoundry+2
  18. What does grep ‘error\|fail’ logfile.txt do?
    a. Finds lines with only ‘error’
    b. Finds lines with ‘fail’ only
    c. Finds lines with either ‘error’ or ‘fail’
    d. Finds empty lines
    Answer: c. Finds lines with either ‘error’ or ‘fail’eitca+1
  19. What will grep -v ‘^#’ config.txt display?
    a. Only lines starting with ‘#’
    b. All lines except those starting with ‘#’
    c. Only the last line
    d. All empty lines
    Answer: b. All lines except those starting with ‘#’cyberciti+1
  20. In cybersecurity, what can grep be useful for?
    a. Searching logs for security events
    b. Encrypting files
    c. Formatting text
    d. Scheduling backups
    Answer: a. Searching logs for security eventslabex+2
  21. What does the -w option in grep do?
    a. Searches for the whole word match
    b. Writes to the file
    c. Waits for input
    d. Wraps text output
    Answer: a. Searches for the whole word matchgeeksforgeeks+1
  22. Which command would print only the lines that do not match the pattern ‘admin’?
    a. grep -c ‘admin’ users.txt
    b. grep -i ‘admin’ users.txt
    c. grep -v ‘admin’ users.txt
    d. grep -n ‘admin’ users.txt
    Answer: c. grep -v ‘admin’ users.txteitca+1
  23. What is the default behavior of grep regarding case sensitivity?
    a. Ignores cases
    b. Case sensitive
    c. Changes all letters to uppercase
    d. Searches only numbers
    Answer: b. Case sensitivelabex+1
  24. Which grep option shows matches along with surrounding lines (context)?
    a. -C
    b. -i
    c. -v
    d. -W
    Answer: a. -Clabex+1
  25. What does the -A option do in grep?
    a. Prints all lines after the match
    b. Prints lines after a matched line
    c. Prints lines before a match
    d. Prints lines with an appended number
    Answer: b. Prints lines after a matched linecyberciti+1
  26. How can you use grep to search for lines ending in a specific word?
    a. Use the pattern with ^
    b. Use the pattern with $
    c. -w option
    d. -v option
    Answer: b. Use the pattern with $digitalocean+1
  27. What will grep ‘[0-9]’ file.txt find?
    a. Only uppercase letters
    b. Digits (numbers) in lines
    c. Special symbols only
    d. Only empty lines
    Answer: b. Digits (numbers) in linesinfosecinstitute+1
  28. What does grep -f pattern.lst file.txt do?
    a. Finds patterns listed in ‘pattern.lst’ in ‘file.txt’
    b. Filters only patterns
    c. Finds lines with the filename
    d. Searches for file extensions
    Answer: a. Finds patterns listed in ‘pattern.lst’ in ‘file.txt’sanfoundry+1
  29. What does the -e option in grep allow you to do?
    a. Encrypt files
    b. Specify multiple search patterns
    c. Edit lines directly
    d. Export the file
    Answer: b. Specify multiple search patternsgeeksforgeeks+1
  30. How does grep treat regular expressions by default?
    a. Uses extended regular expressions
    b. Uses basic regular expressions
    c. Ignores regular expressions
    d. Uses only numbers
    Answer: b. Uses basic regular expressionssanfoundry+2
  31. To perform a case-insensitive search for ‘error’, which command is correct?
    a. grep -i ‘error’ logfile.txt
    b. grep -I ‘error’ logfile.txt
    c. grep -e ‘error’ logfile.txt
    d. grep -v ‘error’ logfile.txt
    Answer: a. grep -i ‘error’ logfile.txtcyberciti+2
  32. What will grep -r ‘password’ /etc accomplish?
    a. Recursively searches for ‘password’ in the /etc directory
    b. Replaces ‘password’ in all files
    c. Removes ‘password’ from files
    d. Restarts the system
    Answer: a. Recursively searches for ‘password’ in the /etc directoryeitca+1
  33. Which command will display filenames with matches, not matching text?
    a. grep -r ‘root’ *
    b. grep -l ‘root’ *
    c. grep -n ‘root’ *
    d. grep -c ‘root’ *
    Answer: b. grep -l ‘root’ *geeksforgeeks+2
  34. The -n option in grep is used to:
    a. Print the number of files searched
    b. Print matching lines with line numbers
    c. Print only filenames
    d. Print all lines
    Answer: b. Print matching lines with line numberscyberciti+1
  35. What happens if you use grep without specifying a file?
    a. It gives an error
    b. It reads from the standard input
    c. It lists all available files
    d. It opens a text editor
    Answer: b. It reads from the standard inputlabex+2
  36. What is a common use of grep in cybersecurity?
    a. Filtering suspicious log entries
    b. Drawing network diagrams
    c. Encrypting files
    d. Resetting user accounts
    Answer: a. Filtering suspicious log entriesinfosecinstitute+2
  37. Which syntax would search for both ‘login’ and ‘logout’ in ‘auth.log’?
    a. grep ‘login|logout’ auth.log
    b. grep -i ‘login,logout’ auth.log
    c. grep ‘login logout’ auth.log
    d. grep -E ‘login|logout’ auth.log
    Answer: d. grep -E ‘login|logout’ auth.log geeksforgeeks+2
  38. What is the role of . (dot) in a grep pattern?
    a. Matches a space
    b. Matches any single character
    c. Ends the line
    d. Matches only digits
    Answer: b. Matches any single characterinfosecinstitute+1
  39. grep -q will do which of the following?
    a. Print matching lines
    b. Return exit status only, no output
    c. Print all lines
    d. Print quote characters
    Answer: b. Return exit status only, no outputgeeksforgeeks+1
  40. Which command will list the count of matches for ‘ssh’ in /var/log/auth.log?
    a. grep -n ‘ssh’ /var/log/auth.log
    b. grep -c ‘ssh’ /var/log/auth.log
    c. grep -v ‘ssh’ /var/log/auth.log
    d. grep -l ‘ssh’ /var/log/auth.log
    Answer: b. grep -c ‘ssh’ /var/log/auth.logcyberciti+1
  41. How do you print matched pattern in color with grep?
    a. Add –color option
    b. Add -X option
    c. Add -colorful option
    d. Add -z option
    Answer: a. Add –color optioncyberciti
  42. What does grep ‘^$’ file.txt show?
    a. Lines with numbers only
    b. Lines with special characters
    c. Empty lines (no text)
    d. Lines starting with ‘^’
    Answer: c. Empty lines (no text)sanfoundry+2
  43. Which command displays lines that begin with a number?
    a. grep ‘[0-9]$’ file.txt
    b. grep ‘^[0-9]’ file.txt
    c. grep ‘[^0-9]’ file.txt
    d. grep ‘^\d’ file.txt
    Answer: b. grep ‘^[0-9]’ file.txtinfosecinstitute+1
  44. What does grep -H do?
    a. Prints only matching text
    b. Always print filename in output
    c. Hides output
    d. Halts search
    Answer: b. Always print filename in outputgeeksforgeeks+1
  45. What does the following command do: cat file.txt | grep ‘admin’?
    a. Adds ‘admin’ to file.txt
    b. Filters lines with ‘admin’ from file.txt
    c. Deletes ‘admin’ from file.txt
    d. Only displays the word ‘admin’ on new lines
    Answer: b. Filters lines with ‘admin’ from file.txteitca+1
  46. To match ‘Error’ at the start of a line, what pattern is used?
    a. Error$
    b. ^Error
    c. Error.*
    d. \bError
    Answer: b. ^Errordigitalocean+1
  47. Which of the following options is NOT a valid use of grep?
    a. Finding IP addresses in logs
    b. Searching for passwords in config files
    c. Sorting files
    d. Finding URLs in files
    Answer: c. Sorting filesinfosecinstitute+2
  48. What will grep -B 2 ‘fail’ logfile.txt do?
    a. Prints 2 lines after match
    b. Prints 2 lines before match
    c. Prints every 2nd match
    d. Ignores ‘fail’ matches
    Answer: b. Prints 2 lines before matchgeeksforgeeks+1
  49. How can you count the occurrences of the word ‘admin’ in a file with grep?
    a. grep ‘admin’ file.txt
    b. grep -c ‘admin’ file.txt
    c. grep -n ‘admin’ file.txt
    d. grep -i ‘admin’ file.txt
    Answer: b. grep -c ‘admin’ file.txtcyberciti+1
  50. What will grep -i ‘User’ data.txt do?
    a. Finds only ‘User’, not ‘user’
    b. Finds both ‘User’ and ‘user’
    c. Finds only lowercase ‘user’
    d. Finds nothing unless capitalized
    Answer: b. Finds both ‘User’ and ‘user’labex+2

 

  1. https://eitca.org/cybersecurity/eitc-is-lsa-linux-system-administration/linux-shell-features/filtering-output-and-searching/examination-review-filtering-output-and-searching/how-can-the-grep-command-be-used-for-filtering-and-searching-in-the-linux-shell/
  2. https://labex.io/questions/what-is-the-purpose-of-grep-command-271291
  3. https://www.geeksforgeeks.org/linux-unix/grep-command-in-unixlinux/
  4. https://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/
  5. https://www.infosecinstitute.com/resources/general-security/grep-essentials/
  6. https://www.digitalocean.com/community/tutorials/using-grep-regular-expressions-to-search-for-text-patterns-in-linux
  7. https://www.sanfoundry.com/unix-questions-answers-grep-command-2/
  8. https://www.sanfoundry.com/unix-questions-answers-grep-command-1/
  9. https://www.sanfoundry.com/1000-cyber-security-questions-answers/
  10. https://www.placementpreparation.io/mcq/cyber-security/page/3/
  11. https://purplegriffon.com/quizzes/cyber-security-quiz-questions-and-answers
  12. https://www.youtube.com/watch?v=ixPjD0sWYpE
  13. https://www.igmguru.com/blog/cyber-security-mcqs
  14. https://www.theknowledgeacademy.com/blog/cyber-security-mcq-and-answers/
  15. https://www.yeahhub.com/certified-ethical-hacker-v10-multiple-choice-questions-answers-part-11/
  16. https://aticleworld.com/linux-mcq/
  17. https://www.interviewbit.com/cyber-security-mcq/
  18. https://www.scribd.com/document/350948880/unix-mcq
  19. https://www.scribd.com/document/925258538/MCQ-Set-2
  20. https://byjus.com/gate/cyber-security-mcqs/

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!