[置顶] Linux shell常用脚本

【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=====


你可能感兴趣的:([置顶] Linux shell常用脚本)