查看字符数的方法:
seq -s " " 100 #以空格为分隔符,输出从1到100
seq 100 #以换行为分隔符
chars=`seq -s " " 100`
echo $chars
echo ${#chars} #统计字符数
echo $(expr length "$chars") #统计字符数
echo $chars | wc -m #统计字符数,多一个结尾的换行符
time for i in $(seq 100000); do count=${#chars}; //最快
done;time for i in $(seq 100000); do count=$(expr length "$chars"); done; //中
time for i in $(seq 100000); do count=`echo $chars | wc -m`; done; //最慢
变量子串的常用方法:
${#string} #返回字符串长度
${string:position} #从位置position之后开始提取字符串,不包含position上的字符
${string:position:length} #从位置position之后提取length个字符
${string/oldstring/newstring} #替换第一个oldstring
${string/%oldstring/newstring} #从后替换第一个oldstring
批量创建文件:
1、将需要创建的文件写入一个文本filename.txt中;
2、执行命令for i in `cat filename.txt`; do touch $i; done
批量改名:rename .jpg .JPG *
rename from to file
/etc/init.d/httpd #yum 安装的apache
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
/etc/init.d/crond
t=${CRON_VALIDATE_MAILRCPTS:-UNSET}
[ "$t" != "UNSET" ] ...