What is grep?

A command that searches files or standard input for lines matching a given pattern (regular expression) and prints them. -i ignores the difference between upper and lower case, -v prints non-matching lines, -c prints the number of matching lines, -n adds line numbers, and -r searches subdirectories as well. -E uses extended regular expressions, and -F treats the pattern as a literal string rather than a regular expression. It returns exit status 0 if any line matches and 1 if none does, so it can also be used in script conditions. Finding error lines in a log or narrowing output in a pipe makes it one of the most used commands on the command line.

Japanese name: grep

grep appears in 3 practice questions across 1 topic, including Linux and Command-Line Basics.

Field: Linux and Command-Line Basics

Try it: questions about grep

Which of the following correctly pairs standard Linux directories with what is placed in them?

  1. A/etc: configuration files of the system and services; /var/log: log files; /usr/bin: executables of the commands users run
  2. B/etc: executables of the commands users run; /var/log: log files; /usr/bin: configuration files of the system and services
  3. C/etc: configuration files of the system and services; /var/log: log files; /usr/bin: each user's personal files
Show answer and explanation

Answer: A. /etc: configuration files of the system and services; /var/log: log files; /usr/bin: executables of the commands users run

The directory layout of Linux broadly follows a convention called the FHS (Filesystem Hierarchy Standard). /etc holds configuration files of the system and services, /var/log holds log files, and /usr/bin holds the executables of commands users run, such as ls and grep. Each user's personal files live in that user's home directory under /home. Temporary files that may be lost at a reboot go in /tmp.

grep in the explanations

Questions that mention grep (3)

  1. In the session above, which of the following are the lines printed by the last grep?
  2. Which of the following correctly pairs standard Linux directories with what is placed in them?
  3. In the session above, which of the following is the value printed by the last command?

Books on Linux and Command-Line Basics Ad

As an Amazon Associate I earn from qualifying purchases.

Related terms

Regular expression cron Environment variable File permissions Git Hard link I/O redirection inode Pipe (|) Shell

Back to the glossary