Linux中的find大法
2016-05-18 14:43
239 查看
在.nx(MAC OS和各种linux)系统中,find方法可谓是广泛中运用,好的find方法规则匹配算法又是高效执行的关键。现在我把find方法常用的搜索方法做下总结:
1 搜索当前文件夹及其子目录中的所有文件
$ find . 或者find . -print
2 搜索指定文件夹及其子目录中的所有文件,以test文件夹为例:
$ find ./test
如果按文件名查找app.js,可以使用-name参数
$ find ./test -name ‘app.js’
3 不区分大小写查找 ‘app.js’,参数-iname,
$ find ./test -iname ‘aPP.Js’
可以匹配到
./test/subdir/app.js
./test/app.js
4 反向匹配,例如,匹配扩展名不为’*.php’的文件
$ find ./test -not -name ‘*.php’
匹配的结果应该是这样的
./test
./test/app.js
./test/subdir
./test/subdir/package.json
5 匹配多个规则,匹配’*.js’和’package.json’
$find ./test -name ‘*.js’ ! -name ‘package.json’
这样就可以匹配到
./test/src/jasmine/functionlist.js
./
也可以另一个参数-o达到同样的效果
$find ./test -name ‘*.js’ -o -name ‘package.json’
6 匹配文件或者目录
只匹配文件
$find ./test -type f -name ‘package*’
只匹配目录
$find ./test -type f -name ‘node_modules’
7 从多个目录查找
$find ./test ./test2 -type f -name ‘package*’
8 查找隐藏文件
$find ~ -type d -name ‘name*’
9 可以感觉具体的权限/用户/用户组/大小查找,参数-perm , -user, -group,-size
10 相当于ls功能
$ find ./test -exec ls -ld {} \;
11删除匹配到的文件
$find ./test -type f -name ‘package.tmp’ -exec rm -r {} \;
暂时写到这里,有问题请留言!
1 搜索当前文件夹及其子目录中的所有文件
$ find . 或者find . -print
2 搜索指定文件夹及其子目录中的所有文件,以test文件夹为例:
$ find ./test
如果按文件名查找app.js,可以使用-name参数
$ find ./test -name ‘app.js’
3 不区分大小写查找 ‘app.js’,参数-iname,
$ find ./test -iname ‘aPP.Js’
可以匹配到
./test/subdir/app.js
./test/app.js
4 反向匹配,例如,匹配扩展名不为’*.php’的文件
$ find ./test -not -name ‘*.php’
匹配的结果应该是这样的
./test
./test/app.js
./test/subdir
./test/subdir/package.json
5 匹配多个规则,匹配’*.js’和’package.json’
$find ./test -name ‘*.js’ ! -name ‘package.json’
这样就可以匹配到
./test/src/jasmine/functionlist.js
./
也可以另一个参数-o达到同样的效果
$find ./test -name ‘*.js’ -o -name ‘package.json’
6 匹配文件或者目录
只匹配文件
$find ./test -type f -name ‘package*’
只匹配目录
$find ./test -type f -name ‘node_modules’
7 从多个目录查找
$find ./test ./test2 -type f -name ‘package*’
8 查找隐藏文件
$find ~ -type d -name ‘name*’
9 可以感觉具体的权限/用户/用户组/大小查找,参数-perm , -user, -group,-size
10 相当于ls功能
$ find ./test -exec ls -ld {} \;
11删除匹配到的文件
$find ./test -type f -name ‘package.tmp’ -exec rm -r {} \;
暂时写到这里,有问题请留言!
相关文章推荐
- linux硬盘的分区、格式化、挂载以及LVM
- linux下的GetTickCount
- 18款开源/商用的Linux服务器控制面板
- linux驱动之--ts移植
- linux驱动之--lcd
- linux驱动之--I2C子系统
- CentOS配置rsyslog Serve
- linux驱动之--输入子系统
- linux源码安装iostat,dstat,systat的方法分享
- linux驱动之--平台总线
- CentOS 5.9 安装OpenCV 2.4.9
- linux C 多线程获取字符输入方法
- Linux下开发C#程序
- linux下touch命令修改文件时间戳
- 用lsb_release -a 查看linux版本
- linux下touch修改文件的时间戳
- CentOS 6.4下安装Python 3.3.4
- LinuxServer开机自动登录和自启动程序设置
- 详解Linux中的mv命令
- 在linux的路上