Welcome 微信登录

首页 / 操作系统 / Linux / Linux中find常见用法示例

Linux中find常见用法示例·find path -option [ -print ] [ -exec -ok command ] {} ;find命令的参数;
 
pathname: find命令所查找的目录路径。例如用.来表示当前目录,用/来表示系统根目录。
-print: find命令将匹配的文件输出到标准输出。
-exec: find命令对匹配的文件执行该参数所给出的shell命令。相应命令的形式为"command" { } ;,注意{ }和;之间的空格。
-ok: 和-exec的作用相同,只不过以一种更为安全的模式来执行该参数所给出的shell命令,在执行每一个命令之前,都会给出提示,让用户来确定是否执行。
 
#-print 将查找到的文件输出到标准输出
#-exec command {} ;      —–将查到的文件执行command操作,{} 和 ;之间有空格
#-ok 和-exec相同,只不过在操作前要询用户
 例:find . -name .svn | xargs rm -rf
 ====================================================
 
-name filename           #查找名为filename的文件
-perm                        #按执行权限来查找
-user    username           #按文件属主来查找
-group groupname            #按组来查找
-mtime -n +n                #按文件更改时间来查找文件,-n指n天以内,+n指n天以前
-atime    -n +n             #按文件访问时间来查GIN: 0px">
 
-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]*" -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
  • 1
  • 2
  • 3
  • 4
  • 下一页
Linux进程优先级管理Linux系统定时关机相关资讯      Find  Linux find用法  linux find的用法 
  • Linxu命令与文件的搜索 - which,  (08/03/2015 09:30:37)
  • Linux下查找文件find命令  (10/28/2014 20:11:29)
  • 文本查找利器find的使用  (03/03/2014 09:20:35)
  • Linux基础教程:find 与 xargs  (04/05/2015 10:20:11)
  • find、xargs命令使用及方法详解  (03/07/2014 17:49:41)
  • 功能强大的find命令  (01/15/2014 15:03:36)
本文评论 查看全部评论 (0)
表情: 姓名: 字数