转载,find.sh
#!/bin/bash
#find files contains a keyword
#write by xiaojing.zhao
#2012.12.14
echo -e "\nThis is a script to find all the files in a specified path contains a keyword!"
echo -e "\nPlease input a keyword:"
##从键盘里获得数据
read key
if [ "$key" == "" ]; then
echo -e "keyword can not be null!\n"
exit 0
fi
keyword=$key
echo -e "\nPlease input your specified path:"
read dir
#判断该路径是否存在,并且是目录,不存在输出提示
test ! -d $dir && echo -e "The $dir is not exist in your system.\n\n" && exit 0
echo -e "\n---------------You find files are:---------------\n"
#统计文件个数
file_count=0
#定义变量filelist,递归查看所有目录,即最深路径,不显示空行( $ )
file_list=`ls -R $dir 2> /dev/null | grep -v '^$'`
#定义变量file_name,通过 fielist 传递,循环调用
for file_name in $file_list
do
#临时文件变量temp,将ls -R即file_list中的文件名中所有匹配:后接一个或多个任意字符(.代表任意字符,*代表0个或多个$代表行尾结束符)全局替换为无
#简单的说,就是把file_name变量中的匹配:的行,将:后内容替换为空
temp=`echo $file_name | sed 's/:.*$//g'`
#如果临时文件变量temp是一个目录,而非文件,就将该目录赋值给cur_dir变量 ,循环调用
if [ "$file_name" != "$temp" ]; then
cur_dir=$temp
#echo "-"$cur_dir #临时显示,调试用
else
#用file命令查看文件真身是否为ASCII text类型
file_type=`file $cur_dir/$file_name | grep "text"`
if [ "$file_type" != "" ]; then
#定义变量,temp
temp=`grep $keyword $cur_dir/$file_name 2> /dev/null`
#echo "--"$cur_dir/$file_name #临时显示,调试用
if [ "$temp" != "" ]; then
echo $cur_dir/$file_name
#文件个数加1
let file_count++
fi
fi
fi
done
echo -e "\n-------------------------------------------------"
echo -e "\n\nFiles Total: $file_count"
echo -e "\nFind Finished!\n"
转载,find.sh的更多相关文章
- 转载:对#!/bin/sh的认识
转载网址:http://blog.163.com/hashes@yeah/blog/static/16867631220101029847420/ 对#!/bin/sh的认识 第一次学shell编程, ...
- linux启动jmeter(二十三),执行./jmeter.sh报错解决方法(转载)
转载自 http://www.cnblogs.com/yangxia-test 1.l-bash: ./jmeter.sh: Permission denied解决办法:jmeter.sh的执行权限改 ...
- [转载]Android 编译环境 build/envsetup.sh分析
2013-12-23 11:28:40 转载自: http://blog.csdn.net/evilcode/article/details/7005757 请到转载地址阅读原文, 转载以备查询.
- 交叉编译环境以及开发板上-/bin/sh: ./hello: not found 转载自 http://blankboy.72pines.com
交叉编译环境以及开发板上-/bin/sh: ./hello: not found 目标板是S3C2440.至于交叉编译环境的搭建就不多说了,网上很多教程. 搭建好了交叉编译环境后,第一件事就是传说中的 ...
- linux下sh语法(转载)
介绍: 1 开头 程序必须以下面的行开始(必须方在文件的第一行): #!/bin/sh 符号#!用来告诉系统它后面的参数是用来执行该文件的程序. 在这个例子中我们使用/bin/sh来执行程序. 当编写 ...
- 在CentOS 7/6.5/6.4 中安装Java JDK 8(转载)
转载在CentOS 7/6.5/6.4 中安装Java JDK 8 首先,在你的服务器上运行一下更新. yum update 然后,在您的系统上搜索,任何版本的已安装的JDK组件. rpm -qa | ...
- maven package 知识(转载)
“打包“这个词听起来比较土,比较正式的说法应该是”构建项目软件包“,具体说就是将项目中的各种文件,比如源代码.编译生成的字节码.配置文件.文档,按照规范的格式生成归档,最常见的当然就是JAR包和WAR ...
- iOS编译FFmpeg、kxmovie实现视频播放 (转载)
由于FFmpeg开源框架的功能非常强大,可以播放的视频种类很多,同时添加第三方库kxmovie,实现视频播放,真的是爽爆了,因此今天来说一下关于FFmpeg在iOS手机上的一些配置过程,配置工具,还有 ...
- 自动化运维工具Ansible详细部署 (转载)
自动化运维工具Ansible详细部署 标签:ansible 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://sofar.blog. ...
随机推荐
- 常用类型转换 一.常用int和string类型转换
常用类型转换 一.常用int类型转换1. int.parse(string) 这个类型只支持string类型 2.double doubleType = Int32.MaxValue + 1; i ...
- Spring Security(11)——匿名认证
目录 1.1 配置 1.2 AuthenticationTrustResolver 对于匿名访问的用户,Spring Security支持为其建立一个匿名的AnonymousAuthe ...
- tftp常用命令
root@hbg:/# tftpBusyBox v1.22.1 (2015-12-18 15:33:52 CST) multi-call binary. Usage: tftp [OPTIONS] H ...
- 朱丽叶—Cuda+OSG
#include <cuda_runtime.h> #include <osg/Image> ; typedef struct cuComplex { float r; flo ...
- LeetCode OJ 41. First Missing Positive
Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0] ...
- matlab显示图像的横纵坐标
imshow(I);title('公路');axis on; %如果不需要,on改为off
- jq的siblings对a标签不起效
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- java.io.IOException: Invalid header signature; read 0xE011BDBFEFBDBFEF, expected 0xE11AB1A1E011CFD0
根据网上的解释,这个表示poi读取excel(97-2003)的时候头文件被损坏了,正常的方式:能打开的话,另存一下即可,实在不行直接新建一个内容一样的 本人环境:eclipse部署到tomcat,e ...
- lua: Learning Official Doc notes
dynamically typed vars: basic types: nil, boolean, number, string, function, userdata, thread & ...
- #ifdef,#else,#endif,#if 拾忆
预处理就是在进行编译的第一遍词法扫描和语法分析之前所作的工作.说白了,就是对源文件进行编译前,先对预处理部分进行处理,然后对处理后的代码进行编译.这样做的好处是,经过处理后的代码,将会变的很精短. ...