批量生成文件
<pre>#!/bin/bash read -t 30 -p "please input the number of files to create:" n test=$(echo $n | sed 's/[0-9]//g') #检测非数字输入 if [ -n "$n" -a -z "$test" ] #检测空输入 then for ((i=0;i<$n;i=i+1 )) do name=$(date +%N) touch "./tmp/$name" echo "creat file $name successfully!" done else echo "invalid parameter!" exit 1 fi
</pre>
批量更改文件名
<pre>#!/bin/bash filenames=$(ls | grep -v "changeName.sh" ) #避免把自己脚本的文件名也改了 number=1 for name in $filenames do rename $name $number $name number=$(( $number + 1 )) #每个改名后的文件名后缀数字加1 done
</pre>
网友评论