Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4529
  • 博文数量: 2
  • 博客积分: 65
  • 博客等级: 民兵
  • 技术积分: 30
  • 用 户 组: 普通用户
  • 注册时间: 2011-01-05 16:33
文章分类
文章存档

2013年(2)

我的朋友
最近访客

分类: LINUX

2013-01-07 22:33:26

find pathname -options [-print -exec -ok ...]


 options:

-print                          将匹配的文件输出到标准输出

-exec                            对匹配的文件执行该参数所给出的shell命令. 'command' {} \;

-ok                               -exec相同,以一种更为安全的模式来执行该参数所给出的shell命令,执行每一个命令之前,都会给出提示,让用户来确定是否执行

 

commands:

-name                        文件名查找文件

                                     find ~ -name "*.txt" -print

                                     find /etc -name "passwd*" -exec grep "eli" {} \;

 

-perm                         文件权限来查找文件

                                     find . -perm 755 -print

                                     find . -type f -perm 644 -exec ls -l {} \;

 

-prune                       使用这一选项可以使find命令不在当前指定的目录中查找如果同时使用-depth选项那么-prune将被find命令忽略

                                     find /apps -path "/apps/bin" -prune -o -print  # /apps目录下查找文件但不希望在/apps/bin目录下查找

                                     find . -path "./here" -prune -o -print

                                     find /usr/eli \( -path /usr/eli/dir1 -o -path /usr/eli/file1 \) -prune -o -print

 

-user                           按照文件属主来查找文件

                                     find ~ -user eli -print

 

-nouser                      无有效属主的文件属主不在/etc/passwd

                                     find /home -nouser -print

 

-group                       按照文件所属的组来查找文件

                                     find /apps -group users -print

 

-nogroup                  无有效所属组的文件, 属组不在/etc/groups

                                     find / -nogroup -print

 

-newer file1               查找更改时间比文件file1新但比文件file2旧的文件

                                     find . -newer test

                                     find . -newer f1 ! -newer f2

 

-type                           查找某一类型的文件

b - 块设备文件

d - 目录

c - 字符设备文件

p - 管道文件

l - 符号链接文件

f - 普通文件

                                     find . -type f -exec ls -l {} \;   # ';' use escaped to make certain the shell passes it to find literally, without interpreting it as a special character

                                     find logs -type f -mtime +5 -exec rm {} \;

                                     find . -type d | sort

                                     find . -type f | xargs ls -l | awk 'BEGIN{size=0}{size+=$5}END{print size/1024/1024"MB"}'  # calculate the file total size, include sub-direc

 

-size n[c]                   查找文件长度为n块的文件,c表示文件长度以字节计

                                     find . -size +1000000c -print   # 当前目录下文件长度大于1 M字节的文件

                                     find . -size +10 -print            # 当前目录下文件长度超过10块的文件(1Block=512Bytes)

                                     find / -type f -size 0 -exec ls -l {} \;

 

-depth                         在查找文件时,首先查找当前目录中的文件,然后再在其子目录中查找

                                     find .  -depth  -name template -print   # 保持depth在前面

 

-fstype                        查找位于某一类型文件系统中的文件这些文件系统类型通常可以在配置文件/etc/fstab中找到

 

-mount                       在当前的文件系统中查找文件不进入其他文件系统

                                     find . -name "*.XC" -mount -print     # 从当前目录开始查找位于本文件系统中文件名以XC结尾的文件

 

-follow                        如果find命令遇到符号链接文件,就跟踪至链接所指向的文件

-cpio                            对匹配的文件使用cpio命令,将这些文件备份到磁带设备中

 

-mtime -n +n           按照文件的更改时间来查找文件, - n表示文件更改时间距现在n天以内,+ n表示文件更改时间距现在n天以前

-atime -n +n

-ctime -n +n

                                     find /var/logs -type f -mtime +7 -ok rm {} \;

                                     find . -name "admin.log[0-9][0-9][0-9]" -atime -7  -ok rm {} \;

 

-amin n               查找系统中最后N分钟访问的文件

-cmin n                查找系统中最后N分钟被改变文件状态的文件

-mmin n              查找系统中最后N分钟被改变文件数据的文件

阅读(289) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:xargs命令

给主人留下些什么吧!~~