ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

find常用

2020-12-20 10:33:11  阅读:256  来源: 互联网

标签:常用 lenovo Demo file1 allen find dir


先看目录结构:

allen@lenovo:Demo$ tree $(pwd)
/home/allen/Downloads/Demo
├── dir
│   └── infile
├── file1
├── file2
└── file3

1 directory, 4 files

先看最简单的,按名称搜索:

allen@lenovo:Demo$ find . -name "file1"
./file1

支持通配符:

allen@lenovo:Demo$ find . -name "file*"
./file1
./file2
./file3

搜索出来的都是相对路径,那是因为搜索目录指定了当前目录,如果改成绝对路径:

allen@lenovo:Demo$ find $(pwd) -name "file*"
/home/allen/Downloads/Demo/file1
/home/allen/Downloads/Demo/file2
/home/allen/Downloads/Demo/file3

按类型搜索:

# 文件类型 f
allen@lenovo:Demo$ find . -type f
./dir/infile
./file1
./file2
./file3
# 目录类型 d
allen@lenovo:Demo$ find . -type d -name dir
./dir

匹配条件默认都是AND,如果是OR:

# 名称是dir且类型是文本的
allen@lenovo:Demo$ find . -name dir -type f
# 和上面一样的效果
allen@lenovo:Demo$ find . -name dir -a -type f
# 名称是dir或类型是文本的
allen@lenovo:Demo$ find . -name dir -o -type f
./dir
./dir/infile
./file1
./file2
./file3

按大小检索:

# 大于10k,且小于10M,且小于10G
allen@lenovo:Demo$ find . -size +10k -size -10M -size -10G

按修改时间,精确到天:

# 24小时内修改的
allen@lenovo:Demo$ find . -mtime 0
.
./dir
./dir/infile
./file1
./file2
./file3
# 昨天修改的
allen@lenovo:Demo$ find . -mtime 1
# 2天内修改的,小于2天
allen@lenovo:Demo$ find . -mtime -2
# 2天前修改的,大于2天
allen@lenovo:Demo$ find . -mtime +2

按修改时间,精确到分钟:

# 和上面一样的,只是换了个参数
# 30分钟内修改的,小于30分钟
allen@lenovo:Demo$ find . -mmin -30

按修改时间,指定一个时间:

# 先看修改时间
allen@lenovo:Demo$ ll
总用量 0
drwxrwxr-x 2 allen allen 20 12月 20 09:35 dir
-rw-rw-r-- 1 allen allen  0 12月 20 09:34 file1
-rw-rw-r-- 1 allen allen  0 12月 20 09:43 file2
-rw-rw-r-- 1 allen allen  0 12月 20 09:43 file3
# 比指定时间新的
allen@lenovo:Demo$ find . -newermt "2020-12-20 09:40"
.
./file2
./file3
# 反向
allen@lenovo:Demo$ find . ! -newermt "2020-12-20 09:40"
./dir
./dir/infile
./file1

按权限检索:

# 权限需要正好是664的
allen@lenovo:Demo$ find . -perm 664
./dir/infile
./file1
./file2
./file3
# 所属人,组,其他人,至少都要有r权限
allen@lenovo:Demo$ find . -perm -444
.
./dir
./dir/infile
./file1
./file2
./file3
# 所属人,组,其他人,只要有一个拥有x权限
allen@lenovo:Demo$ find . -perm /111
.
./dir

 

标签:常用,lenovo,Demo,file1,allen,find,dir
来源: https://blog.csdn.net/aliang_godlike/article/details/111413983

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有