我有一个 zip 文件,其中每个文件的名称如下
original.jpg.1.png
original.jpg.2.png
这些文件实际上是 jpeg 我该如何将它们重命名为以下内容?
original1.jpg
original2.jpg
答案1
带名字(perl 重命名):
rename 's/original.jpg.(\d+).png/original$1.jpg/' original.jpg.*.png
答案2
我可以使用以下 bash 脚本来完成此任务:
#!/bin/bash
#Location of the zip file
zip_file="/path/to/jpegs.zip"
#Desired location of extracted files
dest_dir="/path/to/extract"
#Unzip the file to the desired location
unzip "$zip_file" -d "$dest_dir"
for f in "$dest_dir/"*.png; do
#Remove path from filename.
filename=$(basename "$f")
#Remove .jpg. from filename.
filename=${filename/.jpg./}
#Change .png to .jpg
filename=${filename/.png/.jpg}
#Rename the extracted files to the preferred naming convention using mv.
mv "$f" "${dest_dir}/${filename}"
done