Regular used cmd line_ Shell_if_for_test
2013-03-14 14:10
337 查看
Copy files with full path
=========================
find /tmp/abc -type f|while read line; do mkdir -p /tmp/abc`dirname $line`; echo /tmp/abc`dirname $line`; done
Find some string from the filelist, list file name
=================================================
find . -type f -exec grep -il msg_nbr {} \;
find . -type f |xargs grep -il msg_nbr
bash-3.00$ find . -type f |while read line
> do
> grep -il msg_nbr $line
> done
under dos:http://www.jb51.net/article/31285.htm
List folder: for /D %s in (.,*) do echo %s
List file : for /R %s in (.,*) do echo %s
1、if语句
2、交互选择
3、循环判断
4、数值运算符
5、…………
if语句格式:
if [ 条件 ]
then
command
else
command
fi
交互选择(N可以为*)
echo -e "提示语言,后边有光标提供输入"\c
read VAR
case $VAR in
Y)
command
;;
N)
command
;;
esac
对条件进行循环检查,成立则处理,否则继续检查
a=1
while [ "$a" = "1" ]
do
fileno=`ls -l /list/filename* |wc -l`
if [ "$fileno" = "10" ]
then
a=10
command
else
a=1
sleep 300
fi
done
grep -v www filename 过滤不包含
grep www filename 过滤包含
uniq -u 过滤没有相同行
uniq -d 过滤具有相同行
sort 排序
paste -d";" filename1 filename2 把文件并列合并并且以;间隔
if [ "a" = "10" ] #a=10
[ "a" -ne "10" ] 同上一行
[ -s filename ] 文件大小大于0
-s 文件大小大于0返回真
-d 是一个目录是返回真
-e 文件或目录存在返回真
-g 存在是SGID返回真
-h 文件是连接文件返回真
-k 文件是粘滞位返回真
-r 文件或目录存在并可读时返回真
-w 文件或目录存在并可写时返回真
-u 文件是SUID返回真
-x 文件是可执行的返回真
-eq 等于
-ne 不等于
-lt 小于
-le 小于等于
-gt 大于
-ge 大于等于
2*3+4|bc 计算前面的数据
ping -w 2 www.163.com 测试2两次
对上一次指令结果判断
$?=0 为真
$?=1 为假
给SHELL后边加参数
XXXX=`echo | wc -c`
cat $HOME/list/file.txt 1>/dev/null 2>/dev/null
OK=$?
if [ "" = "" ] || [ "$XXXX" -lt "4" ] || [ "$OK" -ne "0" ]
then
echo "参数没有输入,输入位数不等于3,file.txt不存在,请重新输入"
exit
fi
一个循环检查
line=1
for i in `cat bb`
do
qq=`echo "scale=2;$i*100" | bc | awk -F. '{print }'`
if [ "$qq" -ge "75" ]
then
sed -n "$line"p temp.1 >> bad.1
fi
line=`expr $line + 1` ###每次加1
done
=========================
find /tmp/abc -type f|while read line; do mkdir -p /tmp/abc`dirname $line`; echo /tmp/abc`dirname $line`; done
Find some string from the filelist, list file name
=================================================
find . -type f -exec grep -il msg_nbr {} \;
find . -type f |xargs grep -il msg_nbr
bash-3.00$ find . -type f |while read line
> do
> grep -il msg_nbr $line
> done
under dos:http://www.jb51.net/article/31285.htm
List folder: for /D %s in (.,*) do echo %s
List file : for /R %s in (.,*) do echo %s
1、if语句
2、交互选择
3、循环判断
4、数值运算符
5、…………
if语句格式:
if [ 条件 ]
then
command
else
command
fi
交互选择(N可以为*)
echo -e "提示语言,后边有光标提供输入"\c
read VAR
case $VAR in
Y)
command
;;
N)
command
;;
esac
对条件进行循环检查,成立则处理,否则继续检查
a=1
while [ "$a" = "1" ]
do
fileno=`ls -l /list/filename* |wc -l`
if [ "$fileno" = "10" ]
then
a=10
command
else
a=1
sleep 300
fi
done
grep -v www filename 过滤不包含
grep www filename 过滤包含
uniq -u 过滤没有相同行
uniq -d 过滤具有相同行
sort 排序
paste -d";" filename1 filename2 把文件并列合并并且以;间隔
if [ "a" = "10" ] #a=10
[ "a" -ne "10" ] 同上一行
[ -s filename ] 文件大小大于0
-s 文件大小大于0返回真
-d 是一个目录是返回真
-e 文件或目录存在返回真
-g 存在是SGID返回真
-h 文件是连接文件返回真
-k 文件是粘滞位返回真
-r 文件或目录存在并可读时返回真
-w 文件或目录存在并可写时返回真
-u 文件是SUID返回真
-x 文件是可执行的返回真
-eq 等于
-ne 不等于
-lt 小于
-le 小于等于
-gt 大于
-ge 大于等于
2*3+4|bc 计算前面的数据
ping -w 2 www.163.com 测试2两次
对上一次指令结果判断
$?=0 为真
$?=1 为假
给SHELL后边加参数
XXXX=`echo | wc -c`
cat $HOME/list/file.txt 1>/dev/null 2>/dev/null
OK=$?
if [ "" = "" ] || [ "$XXXX" -lt "4" ] || [ "$OK" -ne "0" ]
then
echo "参数没有输入,输入位数不等于3,file.txt不存在,请重新输入"
exit
fi
一个循环检查
line=1
for i in `cat bb`
do
qq=`echo "scale=2;$i*100" | bc | awk -F. '{print }'`
if [ "$qq" -ge "75" ]
then
sed -n "$line"p temp.1 >> bad.1
fi
line=`expr $line + 1` ###每次加1
done
相关文章推荐
- shell 控制语句(if,for,while,case)
- shell脚本(for,if,while)
- shell 脚本编程之for语句、if语句(2 )
- java: Multiple encodings set for module chunk test "GBK" will be used by compiler
- shell中if判断条件中使用[],[[]],(())还是test,let的比较
- shell编程控制结构:expr、let、for、while、until、shift、if、case、break、continue、函数、select
- Shell 学习(四、条件测试(test,[]) 和 条件判断(if..then..fi))
- bash shell if-test
- 70个shell常用操作、 shell编程控制结构:expr、let、for、while、until、shift、if、case、break、continue、函数、select
- Shell中关于if,case,for,while等的总结
- shell编程控制结构:expr、let、for、while、until、shift、if、case、break、continue、函数、select
- shell if,case,for,while语法
- Shell中关于if,case,for,while等的总结
- shell脚本之while for if 小例子
- [shell] while read line 与for循环的区别
- [Shell] if、for、while流程语句以及整数字符串判断比较的实例详解
- need to set default value for Webservice's if it's used as datasource displayed in Moss
- CCommandLineInfo详解 和 ProcessShellCommand(cmdInfo)函数功能
- SHELL脚本语句 if、for、while、case 图示