Sequence 1: Using find

Scenario: Log in as user student. Devise and execute a find command that produces
the result described in each of the following problems, then write down the
command in the space provided.

You may need to refer to the man page for find. Remember that you can search
man pages with /string.

You will encounter a number of Permission denied messages when
find attempts to recurse 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.

Instructions:

1. Produce a listing of everything under /var/lib owned by user rpm.

find /var/lib -user rpm 2> /dev/null

2. Produce a listing of everything under /var owned by user root and group mail.

find /var -user root -group mail 2> /dev/null

3. Produce an ls -l style listing of everything on the system not owned by users root, bin or
student

This will 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 student -ls 2> /dev/null
or
find / ! -user root ! -user bin ! -user student -ls 2>/dev/null

4. Produce an ls -l style listing of everything under /usr/bin with size greater than 50
kilobytes

find /usr/bin -size +50k -ls 2> /dev/null

5. Execute the file command on everything under /etc/mail

find /etc/mail -exec file {} \; 2> /dev/null

6. Produce an ls -l style listing of all symbolic links under /etc

Hint: man find and search for an option that searches for files by type

find /etc/ -type l -ls 2> /dev/null

7. Produce an ls -l style listing of all "regular" files under /tmp that are owned by user
student, and whose modification time is greater than 120 minutes ago.

Hint: man find and search for an option that searches by modification time in minutes

find /tmp -user student -mmin +120 -type f -ls 2> /dev/null

8. Modify the command above to find all "regular" files under /tmp that are owned by user
student, 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 student -mmin +120 -type f -ok rm {} \;

Note: The standard error is not redirected in answer number 9 because that would prevent
the questions being asked by -ok from being displayed.

9. Produce a listing of all files under /bin and /usr/bin that have the SetUID bit set.

find /bin /usr/bin -perm -4000 2> /dev/null
or
find /bin /usr/bin -perm -u+s 2> /dev/null

posted on 2013-12-09 17:51  逝者如斯(乎)  阅读(178)  评论(0编辑  收藏  举报