3 Basic Commands and Simple Shell Scripts Once you have your first Red Hat Enterprise Linux rhel



Download 1.85 Mb.
View original pdf
Page17/67
Date26.02.2024
Size1.85 Mb.
#63678
1   ...   13   14   15   16   17   18   19   20   ...   67
Pablo Iranzo Gómez, Pedro Ibáñez Requena, Miguel Pérez Colino, Scott McCarty - Red Hat Enterprise Linux 9 Administration-Packt Publishing (2022) -chap 3 82 - 180
/usr/share/doc/gzip/TODO
/usr/share/info/gzip.info.gz
/usr/share/mime/application/gzip.xml
As you can see, we have found all the files with gzip under the /usr directory by creating a file with all the content and searching through it with grep. Could we do the same without creating the file We sure could – by using a pipe. We can redirect the output of find to grep and get the same output:
[root@rhel-instance
]# find /usr/ | grep gzip

/usr/bin/gzip
/usr/lib64/python3.9/__pycache__/gzip.cpython-39.opt-2.pyc
/usr/lib64/python3.9/__pycache__/gzip.cpython-39.opt-1.pyc
/usr/lib64/python3.9/__pycache__/gzip.cpython-39.pyc
/usr/lib64/python3.9/gzip.py
/usr/share/licenses/gzip
/usr/share/licenses/gzip/COPYING
/usr/share/licenses/gzip/fdl-1.3.txt
/usr/share/man/man1/gzip.1.gz
/usr/share/doc/gzip
/usr/share/doc/gzip/AUTHORS
/usr/share/doc/gzip/ChangeLog
/usr/share/doc/gzip/NEWS
/usr/share/doc/gzip/README
/usr/share/doc/gzip/THANKS
/usr/share/doc/gzip/TODO
/usr/share/info/gzip.info.gz
/usr/share/mime/application/gzip.xml
In this command, the standard output from find was sent to grep to process it. We can even count the number of instances of files with wc, but this time, using the -l option to count the lines:
[root@rhel-instance
]# find /usr/ | grep gzip | wc -l

18

Basic Commands and Simple Shell Scripts
82
We have now concatenated two pipes, one to filter the output and another to count it. We will find ourselves doing this kind of plumbing often when searching for and finding information in the system.
Some very common options for grep areas follows -i for ignore-case. This will match the pattern whether it’s uppercase, lowercase, or a combination thereof -v for invert match. This will show all entries that do not match the pattern being searched for -r for recursive. We can tell grep to search fora pattern in all the files within a directory while going through all of them (if we have permission).
There is also away to also filter columns in the output provided. Let’s say we have a list of files in our home directory and we want to see its size. We run the following command:

Download 1.85 Mb.

Share with your friends:
1   ...   13   14   15   16   17   18   19   20   ...   67




The database is protected by copyright ©ininet.org 2024
send message

    Main page