Lab 13: The Find Command

Objective Focus
Understand and use essential tools
Not listed as an official of objective, but very important!

Official RHCSA EX200 Exam Objectives

The find command

The find command is not explicitly written in the EX200 objectives but it is talked about in every book related to Linux administration, including RHCSA related ones.

So, I have decided to include a page for it.

 $ man find 
 $ find path search_option action 
find path search option action
Command Where to search by name, size, permissions, etc. a command to be executed on matches
/, /etc,/var/log File name: -name, -iname -exec cmd {};
UID and GID: -user, -group - ok cmd {};
Permission: -perm delete
Inode: -inum
Size and type: -size, -type

Lets run a few examples of the find command as the root user.

 $ find /etc -iname *ssh* 

 $ find /etc -iname *ssh* -type f 

 $ find . -user learner 
 $ find . -user root 
 $ find /var/log/ -mmin -1 
 $ find / -size +100m 
Using -exec and -ok

The -exec and -ok option is how we perform an action on the matches found through the first portion of the find command.

The difference between -exec and -ok, is that -ok will prompt you to confirm the action.

 $ find . -iname "file*" -user learner -exec chmod 644 {} \; 
 $ find / -size +50M -exec du -sh {} \;

That is all for the find command. There are many options to use with this command. I encourage you to pull up the man page and try some options not mentioned above.