bash批量重命名、批量更改后辍的方法
网络编程
用特定的格式重命名当前目录的图像文件,脚本如下:
其他的执行重命名的命令:rename
#!/bin/bash
#Filename:rename_photo.sh
set -x
count=1
for img in *.jpg *.png
do
new=image-$count.${img##*.}
mv "$img" "$new" 2> /dev/null
if [ $? -eq 0 ]
then
echo "Renameing $img to $new"
let count++
fi
done
其他的执行重命名的命令:rename
[root@localhost script]# rename image photo image*
将当前目录下所有以image开头的文件,换成以photo开关
[root@localhost rename]# ls
image_1.jpg image_2.jpg image_3.jpg image_4.jpg image_5.jpg
[root@localhost rename]# rename image photo image*
[root@localhost rename]# ls
photo_1.jpg photo_2.jpg photo_3.jpg photo_4.jpg photo_5.jpg
将扩展名小写的.jpg改为大写.JPG
[root@localhost rename]# rename .jpg .JPG *.jpg
[root@localhost rename]# ls
photo_1.JPG photo_2.JPG photo_3.JPG photo_4.JPG photo_5.JPG
Bash Shell字符串操作小结
1.取长度str="abcd"exprlength$str#4echo${#str}#4expr"$str":".*"#4好像一般使用第二种2.查找子串的位置str="abc"exprindex$str"a"#1exprindex$str"b"#2exprindex$str"x"#0exprindex$str""#03.
使用shell脚本采集系统cpu、内存、磁盘、网络等信息
一、cpu信息采集1).采集cpu使用率采集算法:通过/proc/stat文件采集并计算CPU总使用率或者单个核使用率。以cpu0为例,算法如下:1.cat/proc/stat|grep‘cpu0'
使用shell脚本分析网站日志统计PV、404、500等数据
下面的脚本能统计出网站的总访问量,以及404,500出现的次数。统计出来后,我们可以结合监控宝来进行记录,进而可以看出网站访问量是否异常,是否
编辑:一起学习网
标签:使用率,脚本,算法,重命名,文件