创建脚本查找相应文件

创建 /usr/local/bin/myresearch 脚本,查找 /usr/ 下所有 小于10M 且 具有 修改组ID 权限的文件 ,将这些文件复制到 /root/myfiles/


提示:

find:
-size [+/-]大小
-a -and 且
-o -or 或
-not 非
-perm
-2000 sgid
-4000 suid

Answer:

vim /usr/local/bin/myresearch
#!/bin/bash
if [ ! -d "/root/myfiles/" ]; then
mkdir -p /root/myfiles/
fi
find /usr/ -size -10M -a -perm -2000 -exec cp -a {} /root/myfiles/ \;
chmod +x /usr/local/bin/myresearch
bash /usr/local/bin/myresearch

验证:

ll /root/myfiles/