ITPub博客

首页 > Linux操作系统 > Linux操作系统 > bash shell3 find

bash shell3 find

原创 Linux操作系统 作者:oracle_db 时间:2009-10-28 19:43:33 0 删除 编辑
目的:通过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博客 ” ,链接:https://blog.itpub.net/15720542/viewspace-617624/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: bash shell 2
下一篇: bash shell 4
请登录后发表评论 登录
全部评论

注册时间:2008-11-13

  • 博文量
    158
  • 访问量
    354229