Chinaunix首页 | 论坛 | 博客
  • 博客访问: 96360
  • 博文数量: 40
  • 博客积分: 426
  • 博客等级: 下士
  • 技术积分: 305
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-02 11:04
文章分类

全部博文(40)

文章存档

2013年(1)

2012年(1)

2011年(38)

我的朋友

分类: LINUX

2011-09-15 15:04:46

1,当前目录查找*.java
find . -name "*.java"

find . -name \*.java
 
2,列出当前目录所有文件,类似  ls -l  ,但是带路径
find . -print
 
3,避免因为没有权限而输出错误
find /usr /home  /tmp -name "*.jar" 2>/dev/null
 
4,查找名字不区分大小写
find . -iname "*.gif"
 
5,按照类型搜索
搜索所有子目录
find . -type d
搜索所有link
find . -type l
 
6,按照文件变化时间查找
mtime — 文件内容上次修改时间
atime — 文件被读取或访问的时间
ctime — 文件状态变化时间
查找最近1小时内修改过的文件
find . -mtime -1
结果出来了:可以用下面两个形式:
find . -mtime -4 -mtime +2
find . -mtime +2 -mtime -4
都是找出在4天之内2天以前修改过的文件

find . -atime +10
查找10天前的
-newer 指内容最近被修改的文件
-anewer 指最近被读取过的文件
-cnewer 指状态最近发生变化的文件
find . -newer  backup.tar.gz
 

7,查找完后,继续输出给其他命令
查找类型为file,并且大小小于100字节,输出给ls -l
find . -type f -size -100 -exec ls -l {} \;
find . -type f -size +50000000c -exec ls -l {} \;
find . -type f -size +100000000c -exec ls -l {} \;
在test文件夹内查找大小为0的文件,移动到/tmp/zerobyte
find test -type f  -size 0 -exec mv {} /tmp/zerobyte \;
查找空文件
find test -empty
 
8,按权限查找
在当前目录查找文件权限为777,然后ls -l
find . -type f -perm 777 -exec ls -l {} \;
 
9,按用户名查找
查找文件属于bluher的,ls -l
find / -type f -user bluher -exec ls -ls {}  \;
查找属于users用户组的文件
find /  -type f -group users
查找group id等于100的目录
find / -type d -gid  100

10,目录深度
查找当前目录下3层子文件夹中的log文件
find . -maxdepth 3  -name "*log"
-depth 选项确保先在一个目录中进行查找,然后才在其子目录中进行查找。以下命令提供了一个示例:
find -name "*test*" -depth
./test/test
./test
./localbin/test
./localbin/test_shell_var
./localbin/test.txt
./test2/test/test
./test2/test
./test2
11,
阅读(617) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~