RH033读书笔记(12)-Lab 13 Finding and Processing Files

本文详细介绍了如何使用find命令解决Linux系统中常见的文件查找问题,包括按权限、类型、大小、时间等条件筛选文件,并提供了实际命令示例。

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

转载于:https://www.cnblogs.com/thlzhf/p/3465833.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值