find命令详解
 
来源: ChinaUnix博客  日期: 2008.07.25 16:04 (共有条评论) 我要评论
 
[url=http://www.sudu.cn/web/host.php][/url]
用法总结如下:
find pathname -options [-print -exec -ok]
pathname:查找路径
-option:主要选项如下:
-name:按照文档名称查找
-perm:按照文档权限查找
-prune:不在当前指定的路径查找。假如同时指定了-depth选项,则prune被忽略
-user:按照文档属主查找
-group:按照文档属组查找
-mtime -n +n:按照文档更改时间查找。-n 指距离现在时间n天以内;+n n天以外
-nogroup:查找无效属组文档
-nouser:查找无效属主文档
-newer file1 !file2:查找更改时间比file1新比file2旧的文档
-type:查找某一类型文档
b:块设备文档
d:目录
c:字符设备文档
P:管道文档
l:符号链接文档
f:普通文档
-size n[c]查找文档长度为n块的文档 有[c]表示文档长度以字节计
-depth:查找时,首先查找当前目录文档,然后再在其子目录查找
-fstype:查找位于某一类型文档系统中的文档,文档系统类型可在/etc/fstab中找到
-mount:查找文档不跨越文档系统mount点
-follow:如碰到链接文档,则跟踪至链接所指向文档
-cpio:对匹配的文档使用cpio命令,将文档备份到磁带设备中 
-print:将匹配的文档输出到标准输出
-exec:对匹配的文档执行所给的shell命令。形式为:command { } \;注意{ }和\;之间的空格
-ok:和-exec作用相同。只但是以一种更安全的模式执行该参数所给的shell命令。在执行每个命令之前,都会给出提示,让用户确定是否执行
Linux中find常见用法示例
·find  path  -option  [  -print ]  [ -exec  -ok  command ]  {} \;
#-print 将查找到的文档输出到标准输出
#-exec  command  {} \;     -----将查到的文档执行command操作,{} 和 \;之间有空格
#-ok 和-exec相同,只但是在操作前要询用户
====================================================
-name  filename             #查找名为filename的文档
-perm                       #按执行权限来查找
-user   username            #按文档属主来查找
-group groupname            #按组来查找
-mtime  -n +n               #按文档更改时间来查找文档,-n指n天以内,+n指n天以前
-atime   -n +n              #按文档访问时间来查GIN: 0px">-perm                        #按执行权限来查找
-user   username            #按文档属主来查找
-group groupname            #按组来查找
-mtime  -n +n               #按文档更改时间来查找文档,-n指n天以内,+n指n天以前
-atime   -n +n              #按文档访问时间来查找文档,-n指n天以内,+n指n天以前 
-ctime   -n +n              #按文档创建时间来查找文档,-n指n天以内,+n指n天以前 
-nogroup                    #查无有效属组的文档,即文档的属组在/etc/groups中不存在
-nouser                     #查无有效属主的文档,即文档的属主在/etc/passwd中不存
-newer  f1 !f2              找文档,-n指n天以内,+n指n天以前 
-ctime   -n +n              #按文档创建时间来查找文档,-n指n天以内,+n指n天以前 
-nogroup                    #查无有效属组的文档,即文档的属组在/etc/groups中不存在
-nouser                     #查无有效属主的文档,即文档的属主在/etc/passwd中不存
-newer  f1 !f2              #查更改时间比f1新但比f2旧的文档
-type    b/d/c/p/l/f        #查是块设备、目录、字符设备、管道、符号链接、普通文档
-size     n[c]              #查长度为n块[或n字节]的文档
-depth                      #使查找在进入子目录前先行查找完本目录
-fstype                     #查更改时间比f1新但比f2旧的文档
-type    b/d/c/p/l/f        #查是块设备、目录、字符设备、管道、符号链接、普通文档
-size     n[c]              #查长度为n块[或n字节]的文档
-depth                      #使查找在进入子目录前先行查找完本目录
-fstype                     #查位于某一类型文档系统中的文档,这些文档系统类型通常可 在/etc/fstab中找到
-mount                      #查文档时不跨越文档系统mount点
-follow                     #假如碰到符号链接文档,就跟踪链接所指的文档
-cpio                %;     #查位于某一类型文档系统中的文档,这些文档系统类型通常可 在/etc/fstab中找到
-mount                      #查文档时不跨越文档系统mount点
-follow                     #假如碰到符号链接文档,就跟踪链接所指的文档
-cpio                       #对匹配的文档使用cpio命令,将他们备份到磁带设备中
-prune                      #忽略某个目录
====================================================
$find  ~  -name  "*.txt"  -print    #在$HOME中查.txt文档并显示
$find  .   -name  "*.txt"  -print
$find  .   -name  "[A-Z]*"  -pri26nbsp;   #对匹配的文档使用cpio命令,将他们备份到磁带设备中
-prune                              #忽略某个目录
=====================================================
$find  ~  -name  "*.txt"  -print    #在$HOME中查.txt文档并显示
$find  .   -name  "*.txt"  -print
$find  .   -name  "[A-Z]*"  -print  #查以大写字母开头的文档
$find  /etc  -name  "host*"  -print #查以host开头的文档
$find  .  -name  "[a-z][a-z][0--9][0--9].txt"   -print  #查以两个小写字母和两个数字开头的txt文档
$find .  -perm  755  -print
$find  .  -perm -007  -exec ls -l {} \;  #查任何用户都可读写执行的文档同-perm 777
$find  . -type d  -print
$find  .  !  -type  d  -print 
$find  .  -type l  -print
$find  .  -size  +1000000c  -print       #查长度大于1Mb的文档
$find  .  -size  100c        -print      # 查长度为100c的文档
$find  .  -size  +10  -print             #查长度超过期作废10块的文档(1块=512字节)
$cd /
$find  etc  home  apps   -depth  -print  | cpio  -ivcdC65536  -o  /dev/rmt0
$find  /etc -name "passwd*"  -exec grep  "cnscn"  {}  \;  #看是否存在cnscn用户
$find . -name "yao*"  | xargs file
$find  . -name "yao*"  |  xargs  echo   "" > /tmp/core.log
$find  . -name "yao*"  | xargs  chmod  o-w
======================================================
find  -name april*                      在当前目录下查找以april开始的文档
find  -name  april*  fprint file        在当前目录下查找以april开始的文档,并把结果输出到file中
find  -name ap* -o -name may*  查找以ap或may开头的文档
find  /mnt  -name tom.txt  -ftype vfat  在/mnt下查找名称为tom.txt且文档系统类型为vfat的文档
find  /mnt  -name t.txt ! -ftype vfat   在/mnt下查找名称为tom.txt且文档系统类型不为vfat的文档
find  /tmp  -name wa* -type l           在/tmp下查找名为wa开头且类型为符号链接的文档
find  /home  -mtime  -2                 在/home下查最近两天内改变过的文档
find /home   -atime -1                  查1天之内被存取过的文档
find /home -mmin   +60                  在/home下查60分钟前改变过的文档
find /home  -amin  +30                  查最近30分钟前被存取过的文档
find /home  -newer  tmp.txt             在/home下查更新时间比tmp.txt近的文档或目录
find /home  -anewer  tmp.txt            在/home下查存取时间比tmp.txt近的文档或目录
find  /home  -used  -2                  列出文档或目录被改变过之后,在2日内被存取过的文档或目录
find  /home  -user cnscn                列出/home目录内属于用户cnscn的文档或目录
find  /home  -uid  +501                 列出/home目录内用户的识别码大于501的文档或目录
find  /home  -group  cnscn              列出/home内组为cnscn的文档或目录
find  /home  -gid 501                   列出/home内组id为501的文档或目录
find  /home  -nouser                    列出/home内不属于本地用户的文档或目录
find  /home  -nogroup                   列出/home内不属于本地组的文档或目录
find  /home   -name tmp.txt   -maxdepth  4  列出/home内的tmp.txt 查时深度最多为3层
find  /home  -name tmp.txt  -mindepth  3  从第2层开始查
find  /home  -empty                     查找大小为0的文档或空目录
find  /home  -size  +512k               查大于512k的文档
find  /home  -size  -512k               查小于512k的文档
find  /home  -links  +2                 查硬连接数大于2的文档或目录
find  /home  -perm  0700                查权限为700的文档或目录
find  /tmp  -name tmp.txt  -exec cat {} \;
find  /tmp  -name  tmp.txt  -ok  rm {} \;
find   /  -amin   -10       # 查找在系统中最后10分钟访问的文档
find   /  -atime  -2         # 查找在系统中最后48小时访问的文档
find   /  -empty              # 查找在系统中为空的文档或文档夹
find   /  -group  cat        # 查找在系统中属于 groupcat的文档
find   /  -mmin  -5         # 查找在系统中最后5分钟里修改过的文档
find   /  -mtime  -1        #查找在系统中最后24小时里修改过的文档
find   /  -nouser             #查找在系统中属于作废用户的文档
find   /  -user   fred       #查找在系统中属于FRED这个用户的文档
查当前目录下的任何普通文档 
--------------------------------------------------------------------------------
# find . -type f -exec ls -l {} \; 
-rw-r--r--    1 root     root        34928 2003-02-25  ./conf/httpd.conf 
-rw-r--r--    1 root     root        12959 2003-02-25  ./conf/magic 
-rw-r--r--    1 root     root          180 2003-02-25  ./conf.d/README 
查当前目录下的任何普通文档,并在- e x e c选项中使用ls -l命令将他们列出
=================================================
在/ l o g s目录中查找更改时间在5日以前的文档并删除他们:
$ find logs -type f -mtime +5 -exec  -ok  rm {} \;
=================================================
查询当天修改过的文档
[root@book class]# find  ./  -mtime  -1  -type f  -exec  ls -l  {} \;
=================================================
查询文档并询问是否要显示
[root@book class]# find  ./  -mtime  -1  -type f  -ok  ls -l  {} \;  
? y
-rw-r--r--    1 cnscn    cnscn       13709  1月 12 12:22 ./classDB.inc.php
[root@book class]# find  ./  -mtime  -1  -type f  -ok  ls -l  {} \;  
? n
[root@book class]# 
=================================================
查询并交给awk去处理
[root@book class]# who  |  awk  '{print $1"\t"$2}'
cnscn   pts/0
=================================================
awk---grep---sed
[root@book class]# df  -k |  awk '{print $1}' |  grep  -v  'none' |  sed  s"/\/dev\///g"
文档系统
sda2
sda1
[root@book class]# df  -k |  awk '{print $1}' |  grep  -v  'none'
文档系统
/dev/sda2
/dev/sda1
1)在/tmp中查找任何的*.h,并在这些文档中查找“SYSCALL_VECTOR",最后打印出任何包含"SYSCALL_VECTOR"的文档名
A) find  /tmp  -name  "*.h"  | xargs  -n50  grep SYSCALL_VECTOR
B) grep  SYSCALL_VECTOR  /tmp/*.h | cut   -d':'  -f1| uniq > filename
C) find  /tmp  -name "*.h"  -exec grep "SYSCALL_VECTOR"  {}  \; -print
2)find / -name filename -exec rm -rf {} \;
   find / -name filename -ok rm -rf {} \;
3)比如要查找磁盘中大于3M的文档:
find . -size +3000k -exec ls -ld {} ;
4)将find出来的东西拷到另一个地方
find *.c -exec cp '{}' /tmp ';'
假如有特别文档,能够用cpio,也能够用这样的语法:
find dir -name filename -print | cpio -pdv newdir
6)查找2004-11-30 16:36:37时更改过的文档
# A=`find ./ -name "*php"` |  ls -l --full-time $A 2>/dev/null | grep "2004-11-30 16:36:37"

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/48205/showart_1092159.html

find命令详解的更多相关文章

  1. Git初探--笔记整理和Git命令详解

    几个重要的概念 首先先明确几个概念: WorkPlace : 工作区 Index: 暂存区 Repository: 本地仓库/版本库 Remote: 远程仓库 当在Remote(如Github)上面c ...

  2. linux yum命令详解

    yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器.基於RPM包管理,能够从指定的服务器自动下载RP ...

  3. Linux下ps命令详解 Linux下ps命令的详细使用方法

    http://www.jb51.net/LINUXjishu/56578.html Linux下的ps命令比较常用 Linux下ps命令详解Linux上进程有5种状态:1. 运行(正在运行或在运行队列 ...

  4. Docker命令详解

    Docker命令详解   最近学习Docker,将docker所有命令实验了一番,特整理如下: # docker --help Usage: docker [OPTIONS] COMMAND [arg ...

  5. linux awk命令详解

    linux awk命令详解 简介 awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大.简单来说awk就是把文件逐行的读入,以空格为默认分 ...

  6. android adb 命令详解

    ADB (Android Debug Bridge)  是android SDK中的工具,需要先配置环境变量才能使用.起调试桥的作用,可以管理安卓设备.(也叫debug工具) ---------查看设 ...

  7. Git 常用命令详解

    Git 是一个很强大的分布式版本管理工具,它不但适用于管理大型开源软件的源代码(如:linux kernel),管理私人的文档和源代码也有很多优势(如:wsi-lgame-pro) Git 的更多介绍 ...

  8. Top 命令详解

    Top 命令详解 先感受一下top命令的执行结果吧!哈哈-- top - 17:32:34 up 3 days, 8:04, 5 users, load average: 0.09, 0.12, 0. ...

  9. Ruby Gem命令详解

    转自:http://www.jianshu.com/p/728184da1699 Gem介绍: Gem是一个管理Ruby库和程序的标准包,它通过Ruby Gem(如 http://rubygems.o ...

  10. DOS命令详解

    DOS命令详解 命令 \? 可以进入命令帮助 1.md命令创建目录. MKDIR [drive:]pathMD [drive:]path 如果命令扩展被启用,MKDIR 会如下改变: 如果需要,MKD ...

随机推荐

  1. hdu 4023 2011上海赛区网络赛C 贪心+模拟

    以为是贪心,结果不是,2333 贪心最后对自己绝对有利的情况 点我 #include<cstdio> #include<iostream> #include<algori ...

  2. [Eclipse] Eclipse字体问题解决

    背景: Eclipse的字体总感觉有点问题,其中中文字体太小,不方便查看,今天网上搜索了一下,解决了问题,记录下来: 解决办法: Window --> Preferences --> Ge ...

  3. 利用Browser Link提高前端开发的生产力

    (此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:Browser Link是VS 2013开始引入的一个强大功能,让前端代码(比如Ang ...

  4. 人性的弱点&&影响力

    How wo win friends and influence people 人性的弱点 by 卡耐基 人际关系基本技巧 不要批评.谴责.抱怨 真诚的欣赏他人 激发他人的渴望 获得别人好感的方式 微 ...

  5. animation动画兼容所有手机

    .canvasAnim{ position: absolute; width:240px; height:240px; top:; z-index:; top:-20px; left:-5px; bo ...

  6. Arduino101学习笔记(十四)—— Flash库

    一.一些API 1.打开文件 SerialFlashFile file; file = SerialFlash.open("filename.bin"); if (file) { ...

  7. Linux学习笔记(6)Linux常用命令之帮助命令与用户管理命令

    (1)man man命令用于获得命令或配置文件的帮助信息,英文原意为manual,所在路径为/usr/bin/man,其语法格式为: man [命令或配置文件] 注意:查看配置文件的帮助信息时无需绝对 ...

  8. this和super

    1.this * 每个类的每个非静态方法(没有被static修饰)都会隐含一个this引用名称,它指向调用这个方法的对象. * 当在方法中使用本类的属性时,都会隐含地使用this名称,当然也可以明确指 ...

  9. error: bad symbolic reference. A signature in HiveContext.class refers to term hive

    在spark-shell中执行val sqlContext = new org.apache.spark.sql.hive.HiveContext(sc)报错: error: bad symbolic ...

  10. LoadRunner如何监控Tomcat性能

    使用LoadRunner做性能测试,一般的直觉是LR只能完成脚本录制和编写模拟用户的请求行为,但是在某些情况下,要监控一些中间件或web服务器的性能时,就不能通过录制脚本来完成了,那么就需要手工来编写 ...