Centos and Red Hat notes, part 3
I’ve decided to take the exams for Red Hat Certified Systems Administrator (RHCSA) and Red Hat Certified Engineer (RHCE). I’ve been meaning to do this for 10 or 15 years! This post is just notes for myself.
I usually use Ubuntu so these notes are specifically for learning CentOS.
grep and find usage
grep command
grep is the main command for browsing file contents.
-iis for case insensitive-dis for directories for when the input file is a directory (ie, what do you want to do with subdirectories: read them like a normal file (default but will throw error when it’s a directory not a file), skip them, or recurse through subdirectories)-ris for recursive (equivalent to-d recurse)-lor--files-with-matcheswill suppress normal output; instead print the name of each input file from which output would normally have been printed.-Lor--files-wihtout-matchesSuppress normal output; instead print the name of each input file from which no output would normally have been printed.-sor--no-messagesSuppress error messages about nonexistent or unreadable files.-qfor quiet
The first command will find all files within /etc/* that contain the text chrony (case insensitive)
The second will have same output, but silence the errors output by subdirectories not being skipped.
1
2
grep -li -d skip chrony /etc/*
grep -lis chrony /etc/*
find command
find will search for files in a directory hierarchy
maxdepthmeans go this number of levels deep. -maxdepth 0 means only apply the tests and actions to the command line arguments. maxdepth 1 means in the directory you specify in command line.-typed is for directory, f is for regular file, there are others-namepattern-pathpattern-mtime -ctime -atimeare modified time, status last changed time, accessed time. This command will find all regular files in/etcthat were modified within the last 180 days and copy all of them to a directory /var/tmp/pvt1
find /etc -type f -mtime +180 -maxdepth 1 -exec cp {} /var/tmp/pvt \;