Which command in UNIX is used to search for a specific pattern in files?
a) grep
b) find
c) locate
d) search
Answer:
a) grep
Explanation:
The grep
command in UNIX is used to search for a specific pattern within files and display the matching lines. It stands for “global regular expression print” and allows users to find text patterns efficiently. It is one of the most powerful search tools in UNIX.
For example, running grep "pattern" file
will search for the string “pattern” in the specified file and display any matching lines. With options like -i
for case-insensitive search or -r
for recursive search in directories, grep
can handle complex search requirements.
Learning to use grep
is essential for extracting information from large files or logs. It simplifies data search and retrieval, making it a must-have skill for anyone working in UNIX environments.