FLOPPIX | Home | FAQ | Download | Labs | ToC | Back | Next |
The grep command searches the contents of a file for lines that contain a certain pattern.
Examples:
Use the grep command to display the lines from the file /etc/passwd for users
with the flin login shell.
Use the grep command to display the lines from the file /etc/hosts.deny that
are NOT comment lines (the comment lines are the lines that start with #).
Use the grep command to display all lines from any file in /etc/init.d that
start with echo.
Which files in /etc/init.d contain the string "dmesg"? ____________________
Which files in /etc/init.d contain the word tr? _________________________
Note: use the man command to lookup to option for grep that searches for
the word "tr" instead of the string "tr".
What command will display all lines in /etc/init.d/userinitials that start
with echo?
Answer: grep ^echo /etc/init.d/userinitials
What command will display all lines that contain echo in any file in the
directory /etc/init.d?
Answer: grep echo /etc/init.d/*
What command will display the lines in the file /etc/login.defs that do not
start with #
Answer: grep -v '^#' /etc/login.defs
What command will display a list of users whose login shell is /bin/bash.
(Recall that the login shell is the last entry in the line for each user
in the file /etc/passwd).
Answer: grep /bin/bash$ /etc/passwd
Copyright © L. M. MacEwan
FLOPPIX | Home | FAQ | Download | Labs | ToC | Back | Next |