Last active
June 16, 2024 05:42
-
-
Save KyonLi/13519d7f9b06046723c2de3da88c5bfc to your computer and use it in GitHub Desktop.
Batch rename files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
prefix="*-" | |
shopt -s nullglob | |
rename(){ | |
local files=( $prefix* ) | |
for i in ${!files[*]} | |
do | |
local file=${files[i]} | |
mv "$file" "${file#$prefix}" | |
echo "$file → ${file#$prefix}" | |
done | |
} | |
rename |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ext=jpg | |
shopt -s nullglob | |
OLDIFS=$IFS | |
rename(){ | |
IFS=$'\n' | |
local arr=( $(ls -v *.$ext) ) | |
IFS=$OLDIFS | |
for i in ${!arr[*]} | |
do | |
local filename=$(printf "%03d" $(($i+1))) | |
mv "${arr[i]}" "${filename}.${ext}" | |
echo "${arr[i]} → ${filename}.${ext}" | |
done | |
} | |
rename |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
vid_ext=mkv | |
sub_ext=ass | |
after_sub_ext=sc.ass | |
shopt -s nullglob | |
rename(){ | |
local vid_arr=( *.$vid_ext ) | |
local sub_arr=( *.$sub_ext ) | |
for i in ${!vid_arr[*]} | |
do | |
local filename=${vid_arr[i]%.*} | |
mv "${sub_arr[i]}" "${filename}.${after_sub_ext}" | |
echo "${sub_arr[i]} → ${filename}.${after_sub_ext}" | |
done | |
} | |
rename |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment