Linux Bash:在用户输入目录中查找含有某字符串的文件,打印行号
2008-12-24 12:07
330 查看
#!/bin/bash
######## My homework for Network Operating System#########
######## To find files that contains the entered string###########
#######################################################
if test $# -ne 2####判断参数是否合法
then
echo "Please enter the Directory that you want to search:/c"
read dir#####读入用户输入目录
echo "Please enter the word you want to find:/c"
read word###读入用户输入字符串
dir=${dir}*
if grep -n $word $dir
then
echo "The result is listed above!"
exit 0
else
echo "Sorry,The word was not found."
exit -1
fi
else
dir=$1
word=$2
dir=${dir}*
if grep -n $word $dir#这里我用grep带n参数来过滤出来文件。
then
echo "The result is listed above!"
else
echo "Sorry,The word was not found."
fi
fi
exit 0
######## My homework for Network Operating System#########
######## To find files that contains the entered string###########
#######################################################
if test $# -ne 2####判断参数是否合法
then
echo "Please enter the Directory that you want to search:/c"
read dir#####读入用户输入目录
echo "Please enter the word you want to find:/c"
read word###读入用户输入字符串
dir=${dir}*
if grep -n $word $dir
then
echo "The result is listed above!"
exit 0
else
echo "Sorry,The word was not found."
exit -1
fi
else
dir=$1
word=$2
dir=${dir}*
if grep -n $word $dir#这里我用grep带n参数来过滤出来文件。
then
echo "The result is listed above!"
else
echo "Sorry,The word was not found."
fi
fi
exit 0
相关文章推荐
- 查找目录下的所有文件中是否含有某个字符串 查找目录下的所有文件中是否含有某个字符串 find .|xargs grep -ri "IBM" 查找目录下的所有文件中是否含有某个字符串,并且只打印出文件
- 在当前目录以及当前目录的所有子目录下查找文件名包含指定字符串的文件,并打印出相对路径
- 查找目录下的所有文件中是否含有某个字符串(grep 命令)
- linux查找目录下的所有文件中是否含有某个字符串
- linux查找目录下的所有文件中是否含有某个字符串
- linux查找目录下的所有文件中是否含有某个字符串
- linux查找目录下的所有文件中是否含有某个字符串
- Linux系统中 查找目录下的所有文件中是否含有某个字符串
- linux查找目录下的所有文件中是否含有某个字符串
- 查找目录下的所有文件中是否含有某个字符串
- linux查找目录下的所有文件中是否含有某个字符串
- linux查找目录下的所有文件中是否含有某个字符串
- linux查找目录下的所有文件中是否含有某个字符串
- linux 查找 目录下的所有文件是否含有某个字符串
- 编写一个Python程序,能在当前目录以及当前目录的所有子目录下查找文件名包含指定字符串的文件,并打印出相对路径
- linux查找目录下的所有文件中是否含有某个字符串
- Python:编写函数,能在当前目录以及子目录下查找文件名包含指定字符串的文件,并打印出完整路径
- 编写一个程序,能在当前目录以及当前目录的所有子目录下查找文件名包含指定字符串的文件,并打印出相对路径。
- 查找目录下的所有文件中是否含有某个字符串
- Linux 查找目录中含有关键字的文件并打印文件名