Filtering output with grep and sed
The grep
command is heavily used (and commonly mistyped) in system administration. It helps when finding a pattern in a line, whether in a file or via standard input (STDIN).
Let's do a recursive search of the files in /usr
with find
and put it in /root/usr-files.txt
:
[root@rhel8 ~]# find /usr/ > /root/usr-files.txt [root@rhel8 ~]# ls -lh usr-files.txt -rw-r--r--. 1 root root 1,9M dic 26 12:38 usr-files.txt
As you can see, it's a file 1.9 MB in size, and it isn't easy to go through it. There is a utility in the system called gzip
and we want to know which files in /usr
contain the gzip
pattern. To do so, we run the following command:
[root@rhel8 ~]# grep gzip usr-files.txt /usr/bin/gzip /usr/lib64/python3.6/__pycache__/gzip.cpython-36.opt-2.pyc /usr/lib64/python3.6/__pycache__/gzip.cpython-36.opt-1.pyc /usr/lib64/python3.6/__pycache__/gzip.cpython-36.pyc /usr/lib64/python3.6/gzip.py /usr/share/licenses/gzip /usr/share...