您的位置:首页 > 运维架构 > Shell

Linux shell常用脚本

2013-10-06 12:53 330 查看
【test】
-n:测试string长度是否是大于0
name='Jack'
if test -n" $name"; then
echo "YES"
else
echo "NO"
fi
输出是YES

【if】
测试string相等
if [ $str = 'abc' ];then
fi

【变量赋值】

myName='liu'
echo $myName
myName='huang'
echo $myName

【Linux 下批量修改后缀名 】

一、rename解决
1. Ubuntu系统下
rename 's/.c/.h/' ./*
把当前目录下的后缀名为.c的文件更改为.h的文件
2. CentOS5.5系统下
rename .c .h *.c
把当前目录下的后缀名为.c的文件更改为.h的文件

二、shell 脚本解决
#!/bin/bash
#http://blog.csdn.net/longxibendi
find ./ -name *.c | while read i
do
echo "$i";
mv $i.c $i.h
done

三、find xargs 解决
find ./ -name"*.c" | awk -F "." '{print $2}' | xargs -i -t mv./{}.c ./{}.h
{},表示awk的{print
$2}的输出值;
该例子把所有.c,该为.h的后缀名;
=====END=====
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: