Linux下批量修改文件名
程序员文章站
2022-06-12 16:53:58
...
1. 修改文件名rename.sh
#!/bin/sh
suffix="$1"
if [ -z "$suffix" ]; then
echo "Usage: ./rename.sh <suffix>"
exit 1
fi
for file in `ls`
do
# 过滤掉指定文件
if [[ "$file" = rename* ]]; then
continue;
fi
# 或者通过正则等匹配指定类型文件
newfile=$(printf "%s%s" "$file" "$suffix")
echo $newfile
mv $file $newfile
done
2. 重命名回退rename_back.sh
#!/bin/sh
suffix="$1"
if [ -z $suffix ]; then
echo "Usage: ./rename_back.sh <suffix>"
exit 1
fi
for file in `ls`
do
if [[ "$file" = rename* ]]; then
continue;
fi
newfile=$(echo $file | sed "s#$suffix\$##g")
echo $newfile
mv $file $newfile
done
转载于:https://my.oschina.net/u/239075/blog/472332
上一篇: Swoole Server
下一篇: 夏至节气如何防病 热水泡脚针灸治病