bash shell3 find

本文介绍了使用Linux find命令进行高级文件搜索的方法,包括按属主、组、修改时间、文件类型等条件查找文件,以及如何结合其他命令进行更复杂的操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目的:通过find可以查找具有一定特征的文件
例子:
1.希望按照文件属主查找文件
语法:find 目录 -user  属主名 -print
find /home/oracle oracle -print
2.查找属主账户被删除的文件
语法:find 目录 -nouser -print
find  /home -nouser -print
3.查找属于指定组的文件
语法:find 目录名 -group 组名 -print
find /home -group oinstall -print
4.查找不属于任何组的文件
语法:find 目录名 -nogroup  -print
find / -nogroup -print
5.查找指定目录下更改时间在指定时间天数内的文件
语法:find 目录名 -mtime -天数 -print 
find /home/db -mtime -10 -print   这就是找10天内修改过的文件
find /home/db -mtime +10 -print  这就是找10天前修改过的文件
6.查找比指定文件新或者旧的文件
语法:find 目录名 -newer 新文件名   !  -newer 旧文件名  -exec ls -ltr {}\
db@db-desktop:~/download/test$ find . -newer 7.sh ! -newer menu.sh -exec ls -l {} \;
-rwxr-xr-x 1 db db 59 2009-10-21 21:59 ./menu.sh
-rw-r--r-- 1 db db 8903 2009-10-21 21:54 ./2.txt
7.查找指定目录下的所有目录
语法:find 目录名 -type d -print
find /home -type d -print
8.查找出目录以外的所有文件类型
语法:find 目录名 ! -type -d -print
find . ! -type d -print
9.查找所有的符号连接文件
语法:find 目录名 -type l -print
db@db-desktop:~/download/test$ find . -type l -print
./www
db@db-desktop:~/download/test$ ls -ltr www
lrwxrwxrwx 1 db db 6 2009-10-11 15:00 www -> ./1.sh
db@db-desktop:~/download/test$
以字节计量文件长度的表达形式为N C ,以块记录文件长度只用数字表示
10.查找长度>1M字节的文件
语法:find 目录名 -size +字节大小c -print
find /home -size +1000000c -print
11.查找长度=XXX字节的文件
语法:find 目录名 -size 字节大小c -print

db@db-desktop:~/download/test$ find . -size 6c -print
./www
db@db-desktop:~/download/test$ ls -ltr www
lrwxrwxrwx 1 db db 6 2009-10-11 15:00 www -> ./1.sh
db@db-desktop:~/download/test$
12.查找长度>XXX块的文件  [1块=512字节]
语法:find 目录名 -size +块大小 -print
find /home -size +10 -print
13.先在当前目录查找指定文件,后在子目录查找该文件
语法:find 目录名 -name 文件名 -depth -print
find /home -name xxx -depth -print
14.在当前文件系统中查找文件,不在其它文件系统中去查找
语法:find 目录名 -name 文件名 -mount -print
db@db-desktop:~/download/test$ find . -mount -name 1.sh -print
./1.sh
./xxx/1.sh
15.当前目录中查找更改时间在5天以前的,并把它们删除
find . -type f -mtime +10 -exec rm {} \;   这种删除不会提示用户,直接就删除了!
 find . -type f -mtime +3 -ok rm {} \;        这种会提示
< rm ... ./test_ora_7064.trc > ? y
< rm ... ./test_ora_7091.trc > ? y
< rm ... ./test_ora_7035.trc > ? y
< rm ... ./test_ora_11940.trc > ? y
< rm ... ./test_ora_7036.trc > ? y
< rm ... ./test_ora_7007.trc > ? y
< rm ... ./test_ora_19693.trc > ? y
< rm ... ./test_ora_11968.trc > ? y
root@db-desktop:/u01/app/oracle/product/10.2.0/db_1/admin/test/udump#










来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15720542/viewspace-617624/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/15720542/viewspace-617624/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值