In this blog you will come to know about that how to use find command in different ways, you can see many examples in this blog.
You will encounter a number of Permission denied messages when find attempts to recourse into directories to which you do not have read access -do not be concerned about these messages. Better yet, you can suppress these error messages by appending your find command with 2> /dev/ null
- Produce a listing of everything under /var/lib owned by user ntp.
$find /var/lib -user ntp 2> /dev/null
- Produce a listing of everything under /var owned by user root and group mail.
$find /var -user root -group mail 2> /dev/null
- Produce an ls -l style listing of everything on the system not owned by users root, bin or oliver.
This may take a long time, so run the command in one terminal and do the next problem in another terminal while it runs.$find / -not -user root -not -user bin -not -user oliver -ls 2> /dev/null
OR
$find / ! -user root ! -user bin ! -user oliver -ls 2> /dev/null
OR
$find / ! \( -user root -o -user bin -o -user oliver \) -ls 2> /dev/null - Produce an ls -l style listing of everything under /user/bin with size greater than 50 kilobytes
$find /usr/bin -size +50k -ls 2> /dev/null
- Execute the file command on everything under /etc/mail
$find /etc/mail -exec file {} \; 2> /dev/null
- Produce an ls -l style listing of all symbolic links under /etc
$find /etc/ -type l -ls 2> /dev/null
- Produce an ls -l style listing of all “regular” files under /tmp that are owned by user oliver, and whose modification time is greater than 120 minutes ago.
$find /tmp/ -user oliver -mmin +120 -type f -ls 2> /dev/null
- Modify the command above to find all “regular” files under /tmp that are owned by user oliver. and whose modification time is greater than 120 minutes ago and have find prompt you interactively whether or not to remove each one. Because you are using the interactive option, do not throw out error messages; that is, do not end your command with 2> /dev/null. Decline to remove all files when prompted.
$find /tmp -user oliver -mmin +120 -type f -ok rm {} \;
Note:
The standard error is not redirected in this solution because that would prevent questions being asked by -ok from being displayed.
Interactive 12.1: find Practice
1. Device a command that will list all files in /var that are more than 1 MB in size.
suggested solution:find /var -size +1M
2. How could you output the number of matching files instead of their names?
Hints
- find cannot do this by its self.
- What command can count lines of output?
Suggested Solution:find /var -size +1M / wc -l