(Linux下的find的使用方法)
一、通过文件修改时间查询
1.查找5分钟前的文件
查找5分钟之前的文件,可使用以下命令:
[root@tianyi ~]# find /etc -mmin +5 |head |nl
1 /etc
2 /etc/pear.conf
3 /etc/NetworkManager
4 /etc/NetworkManager/conf.d
5 /etc/NetworkManager/conf.d/99-cloud-init.conf
6 /etc/NetworkManager/NetworkManager.conf
7 /etc/NetworkManager/dnsmasq.d
8 /etc/NetworkManager/system-connections
9 /etc/NetworkManager/dnsmasq-shared.d
10 /etc/NetworkManager/dispatcher.d
[root@tianyi ~]#
二、通过文件权限查找
1.创建不同权限文件夹
[root@tianyi ~]# mkdir -m 777 /data/test1
[root@tianyi ~]# mkdir -m 406 /data/test2
[root@tianyi ~]# mkdir -m 101 /data/test3
[root@tianyi ~]#
2.查找其他人有写的文件夹
[root@tianyi data]# find -perm -002
./test1
./test2
[root@tianyi data]# ll -ld ./test1
drwxrwxrwx 2 root root 4096 Dec 29 11:05 ./test1
[root@tianyi data]# ll -ld ./test2
dr-----rw- 2 root root 4096 Dec 29 11:05 ./test2
3.查找拥有人、拥有组、其他人都有写权限文件夹
[root@tianyi data]# find -perm -222
./test1
[root@tianyi data]# ll -ld ./test
drwxr-xr-x 2 root root 4096 Dec 1 00:48 ./test
[root@tianyi data]# ll -ld ./test1
drwxrwxrwx 2 root root 4096 Dec 29 11:05 ./test1
[root@tianyi data]#
4.查找拥有人有读权限的文件夹
[root@tianyi data]# find -perm -600
.
./test1
./test
./passwd
./scrips
./person.txt
[root@tianyi data]#
三、查找文件并处理
1.创建备份文件夹
[root@tianyi data]# mkdir /backup
2.备份以conf的文件
[root@tianyi backup]# find /etc -name *.conf -exec cp -a {} /backup/ \;
cp: not writing through dangling symlink '/backup/yum.conf'
cp: '/etc/authselect/nsswitch.conf' and '/backup/nsswitch.conf' are the same file
[root@tianyi backup]# head -n 10
^C
[root@tianyi backup]# ls |head
00-base.conf
00-dav.conf
00-keyboard.conf
00-lua.conf
00-mpm.conf
00-optional.conf
00-proxy.conf
00-systemd.conf
01-cgi.conf
05-redhat.conf
标签:tianyi,00,方法,data,etc,conf,Linux,root,find
From: https://blog.51cto.com/u_14664141/6114295