两个shell脚本

来源:互联网 发布:dorado js 获取登录人 编辑:程序博客网 时间:2024/05/06 18:45

转自http://xiujie.5d6d.com/thread-2985-1-1.html

Shell 文件名大小写转换

 

shell判断文件,目录是否存在或者具有权限

 

在unix系统下经常要碰到改文件名,如果是改单个文件则好处理,但要是批量改文件名则工作量很大,必须运用shell程序来实现,以下程序就是通过shell来实现批量更改日志文件名的程序,大家可以稍作修改,就可以实现批更改你所需要更改的文件名。

以下就为程序内容,可供大家学习参考:

class='codetop'>CODE: class='codemain'>#此处SHELL脚本是将CYYMMDD.*的文件批改名为YYYYMMDD.*的文件
STR="请选择:"
DATE="请输入日期(031001):"
while true
echo "1) 批更改文件名"
echo "0) 退出/n"
printf $STR
read anwser
do
case $anwser in
1)
printf $DATE
read ndate
file1='C'$ndate'.*'
#定义FILE1为C打头的带日期的所有文件
#echo $file1
ls $file1 > test.txt
out1=`more test.txt|awk '{print $1}'`
number=`more test.txt|wc -l`
i=1
echo "number = " $number
while true
do
put1=`echo $out1|awk '{print $'$i'}'`
put2=`echo $out1|awk '{print substr($'$i',2,10)}'`
put2='20'$put2
echo $put1
echo $put2
mv $put1 $put2
i=`expr $i + 1`
if [ $i -gt $number ]
then
break
fi
done
echo "批更改文件成功!/n"
;;
0)
exit
;;
esac
done
原创粉丝点击