![폴더의 파일 이름을 일괄적으로 바꾸는 방법 [닫기]](https://linux55.com/image/149605/%ED%8F%B4%EB%8D%94%EC%9D%98%20%ED%8C%8C%EC%9D%BC%20%EC%9D%B4%EB%A6%84%EC%9D%84%20%EC%9D%BC%EA%B4%84%EC%A0%81%EC%9C%BC%EB%A1%9C%20%EB%B0%94%EA%BE%B8%EB%8A%94%20%EB%B0%A9%EB%B2%95%20%5B%EB%8B%AB%EA%B8%B0%5D.png)
각 파일의 이름이 다음과 같은 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