UNIXETC

find命令使用实例

目录

find按名称搜索文件 #

1
2
3
$ find ./ -name dis55.csv
./dis55.csv
./shell/dis55.csv

find按扩展名搜索文件 #

1
2
3
4
5
6
$ find ./ -name "*.TAB"
./dis54.TAB
./dis55.TAB
./ltebaseinfo.TAB
./newsite_nr.TAB
./nrbaseinfo.TAB

find查找最近第7天修改过的文件 #

1
2
$ find ./ -mtime 7
./ST_DOC/netcare_20240805083230.png

find查找最近7天内修改过的文件 #

1
2
3
4
5
6
7
8
$ find ./ -mtime -7
./ST_DOC/netcare_20240807084933.png
./ST_DOC/netcare_20240808083619.png
./ST_DOC/netcare_20240811130038.png
./ST_DOC/netcare_20240812083054.png
./ST_DOC/OP_SiteList.xlsx
./ST_DOC/OP_SiteList0807.xlsx
./ST_DOC/OP_SiteList0808.xlsx

find查找超过7天修改过的文件 #

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$ find ./ -mtime +7
./ST_DOC/netcare_20240726081508.png
./ST_DOC/netcare_20240729085021.png
./ST_DOC/netcare_20240730091007.png
./ST_DOC/netcare_20240731082438.png
./ST_DOC/netcare_20240801091744.png
./ST_DOC/netcare_20240802082300.png
./ST_DOC/OP_SiteList0719.xlsx
./ST_DOC/OP_SiteList0722.xlsx
./ST_DOC/OP_SiteList0724.xlsx

find查找并删除文件 #

1
2
3
4
5
$ ls dis55.TAB
dis55.TAB
$ find ./ -name "dis55.TAB" -delete
$ ls dis55.TAB
ls: cannot access 'dis55.TAB': No such file or directory

find查找空文件或文件夹 #

1
2
3
4
5
6
7
$ find ./ -empty
./.git/objects/info
./.git/refs/tags
./newsite_lte.txt
./shell/template_lte_b1.txt
./shell/template_lte_b3.txt
./shell/template_lte_b5.txt

find查找大小超过5M的文件 #

1
2
3
$ find ./ -size +5M
./.git/objects/pack/pack-5801296dc7e415dcea25931abee82177cde60377.pack
./ltebaseinfo.txt

find查找指定用户的文件 #

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
$ find ./ -user bbq
./ST_DOC/test_image.docx
./ST_DOC/~$OP_SiteList.xlsx
./Template_PrjPara_NR_XY.xlsx
./wknote.md
./zombie_site.xlsx
./~$20240812_1723428772_NR-BSL.xlsx
./~$20240812_1723428780_NBR_4G.xlsx
./~$20240812_1723428780_NBR_5G.xlsx
./~$nr_ct_xy.xlsx
./~$SA_V15.xlsx

find查找大小小于1k的文件 #

1
2
3
4
5
6
7
find ./ -size -1k
./4G_TAC_XY/xy_psite_lte_tac_20230317
./5G_TAC_XY
./5G_TAC_XY/NR_TAC_XY
./lstmmls
./lte800_prj
./mml_templates

find查找大小5M的文件 #

1
2
$ find ./ -size 5M
./ltebaseinfo.xlsx

find查找指定权限的文件 #

1
2
3
4
5
6
7
8
$ find ./ -perm 0644
./wknote.md
./zombie_site.xlsx
./~$20240812_1723428772_NR-BSL.xlsx
./~$20240812_1723428780_NBR_4G.xlsx
./~$20240812_1723428780_NBR_5G.xlsx
./~$nr_ct_xy.xlsx
./~$SA_V15.xlsx

find查找指定文件并执行命令(压缩特定文件) #

1
find ./ -name "*.txt" -exec gzip {} \;

find查找空文件并删除 #

1
$ find ./ -type f -empty -exec rm {} \;

find查找文件并打印内容 #

1
$ find ./ -type f -exec ls -lh {} \;

find查找文件并排除指定目录 #

1
$ find ./ -path "./shell" -prune -o -name "*.config" -print

find查找15分钟内修改过的文件 #

1
2
3
4
$ find ./ -mmin -15
./
./lsmml.txt
./SA_V15.xlsx

find查找文件打包压缩 #

1
 find ./ -name "*.jpg" | xargs tar -czvf jpgs.gz

find查找链接文件 #

1
$ find /usr/bin/ -type l