`
sjk2013
  • 浏览: 2185694 次
文章分类
社区版块
存档分类
最新评论

linux/unix shell的find用法小练

 
阅读更多

好久之前的笔记了,搬出来和大家共享:

参数解释:

find用来查询某个目录下的文件几种常用的参数如下

-path 后面跟着要查询的路径

-prune 表示不再指定目录下查询,如果同时使用-depth,那么-prune命令将会被忽略

-name 要查询的文件名,可以使用正则表达式来查询

-mtime 查询近n天更改过的文件+表示大于n,-n表示n天以内

-另外还有-atime和-ctime用法类似

-newer file1 ! -newer file2 表示查询比file1新,比file2旧的文件

-exec 表示对查询出来的文件进行某些命令操作,如 -exec ls -l {} \;

-type 要查询的文件类型

! -type d 表示除了类型为目录的

-size 指定大小的文件+10c或-10c:大于10个字节的,或者小于10个字节的

演示:

[oracle@localhost testDir]$ cat find.sh 
echo "prune:" >> find.out
find . -path "./folder" -prune -o -name "file*" >> find.out
echo "-name:" >> find.out
find . -name "[a-z][a-z]*" >> find.out
echo "-mtime: +3" >> find.out
find . -mtime +3 >> find.out
echo "-mtime: -3" >> find.out
find . -mtime -3 >> find.out
echo "find newer then 1 and older then 2 files:">> find.out
find . -newer "test1.sh" ! -newer "test2.sh" -exec ls -l {} \; >> find.out
echo "-type:" >> find.out
find . -type d >> find.out
echo "except type:" >> find.out
find . ! -type d >> find.out
echo "-size +10c :" >> find.out
find . -size +10c >> find.out
echo "-size -10c :" >> find.out
find . -size -10c >> find.out

输出结果:

[oracle@localhost testDir]$ cat find.out 
prune:
./folder
-name:
./blank_file
./find.sh
./shelltest.sh
./folder
./folder/file1
./test1.log
./test1.sh
./test2.sh
./main.sh
./find.out
-mtime: +3
./find.sh
./shelltest.sh
./folder
./folder/file1
./test1.sh
./test2.sh
./main.sh
-mtime: -3
.
./blank_file
./test1.log
./find.out
find newer then 1 and older then 2 files:
-rwxr-xr-x 1 oracle oinstall 100 Nov 10 23:08 ./test2.sh
-rwxr-xr-x 1 oracle oinstall 26 Nov 10 22:30 ./main.sh
-type:
.
./folder
except type:
./blank_file
./find.sh
./shelltest.sh
./folder/file1
./test1.log
./test1.sh
./test2.sh
./main.sh
./find.out
-size +10c :
.
./blank_file
./find.sh
./shelltest.sh
./folder
./test1.log
./test1.sh
./test2.sh
./main.sh
./find.out
-size -10c :
./folder/file1
分享到:
评论

相关推荐

    LINUX与UNIX SHELL编程指南(很全)

    11.1.12 使用k的其他sort方法 108 11.1.13 使用k做分类键排序 108 11.1.14 指定sort序列 108 11.1.15 pos用法 108 11.1.16 使用head和tail将输出分类 109 11.1.17 awk使用sort输出结果 109 11.1.18 将两个分类文件...

    LINUX与UNIX SHELL编程指南

    呵呵,这真的是一本好书《LINUX与UNIX SHELL编程指南》 --------------------------------------------- 经典《Linux与UNIX Shell编程指南》 shell是一种完整的编程语言,易学易用;shell脚本可以使烦人的手工作业...

    绝版经典 LINUX与UNIX SHELL编程指南 PDF 高清版 [16.3M]

    第二章 使用FIND和XARGS 第三章 后台执行命令 第四章 文件名置换 第五章 SHELL输入输出 第六章 命令执行顺序 第二部分 文本过滤 第七章 正则表达式介绍 第八章 GERP家族 第九章 AWK介绍 第十章 SED用法介绍...

    Linux与unix shell编程指南

    本书共分五部分,详细介绍了shell编程技巧,各种UNIX命令及语法,还涉及了UNIX下的文字处理以及少量的系统管理问题。本书内容全面、文字简洁流畅,适合Shell编程人员学习、参考。 目 录 译者序 前言 第一部分 shell ...

    绝版经典《Linux与UNIX Shell编程指南》

    11.1.12 使用k的其他sort方法 108 11.1.13 使用k做分类键排序 108 11.1.14 指定sort序列 108 11.1.15 pos用法 108 11.1.16 使用head和tail将输出分类 109 11.1.17 awk使用sort输出结果 109 11.1.18 将两个分类文件...

    LINUX与UNIX SHELL编程指南 高清PDF

    本书共分五部分,详细介绍了shell编程技巧,各种UNIX命令及语法,还涉及了UNIX下的文字处理以及少量的系统管理问题。本书内容全面、文字简洁流畅,适合Shell编程人员学习、参考。 目 录 译者序 前言 第一部分 shell...

    Linux与Unix Shell编程指南(PDF格式,共30章)

    本书共分五部分,详细介绍了shell编程技巧,各种UNIX命令及语法,还涉及了UNIX下的文字处理以及少量的系统管理问题。本书内容全面、文字简洁流畅,适合Shell编程人员学习、参考。 目 录 译者序 前言 第一部分 ...

    Linux与UNIX Shell编程指南.rar

    第二章 使用FIND和XARGS 第三章 后台执行命令 第四章 文件名置换 第五章 SHELL输入输出 第六章 命令执行顺序 第二部分 文本过滤 第七章 正则表达式介绍 第八章 GERP家族 第九章 AWK介绍 第十章 SED用法介绍 第十一...

    绝版高清经典Linux与UNIX_Shell编程指南中文版

    使用find 和xargs 后台执行命令 文件名置换 shell输入与输出 命令执行顺序 文本过滤正则表达式介绍 grep 家族 awk 介绍 sed用法介绍 合并与分割 tr用法 登陆环境 登陆环境 环境和shell变量 引号 ...

    linux与unix shell编程指南.rar

    linux/unix shell编程指南,全面介绍了Linu/unix shell编程的常用知识和技巧,是不可多得的编程宝典。 目 录 译者序 前言 第一部分 shell 第1章 文件安全与权限 1 1.1 文件 1 1.2 文件类型 2 1.3 权限 2 1.4 改变权限...

    Linux与UNIX Shell编程指南.

    第二章 使用FIND和XARGS 第三章 后台执行命令 第四章 文件名置换 第五章 SHELL输入输出 第六章 命令执行顺序 第二部分 文本过滤 第七章 正则表达式介绍 第八章 GERP家族 第九章 AWK介绍 第十章 SED用法介绍 第十一...

    UNIX shell 编程指南

    linux shell 变量和运算符 执行Shell脚本的方式 [小函数]:bash版rev&tac shell编程走马观花系列(KSH下set选项) 文章出处:http://www.diybl.com/chm/htm/3_program/shell/shelljs/2008821/2008821102938.html

Global site tag (gtag.js) - Google Analytics