如何重命名所有子目录中的所有文件,带有子目录名称和自动编号。
前任:
parent
-subdir
--file.jpg
--cat.jpg
--dog.jpg
Run Code Online (Sandbox Code Playgroud)
重命名为:
parent
-subdir
--subdir_01.jpg
--subdir_02.jpg
--subdir_03.jpg
Run Code Online (Sandbox Code Playgroud)
我正在使用这个脚本,但它不是递归的
#!/bin/bash
a=1
b="$1"
for i in *.jpg; do
new=$(printf "%04d" ${a}) #04 pad to length of 4
mv "${i}" ""$1"_${new}.jpg"
let a=a+1
done
Run Code Online (Sandbox Code Playgroud) 我正在使用这个 bash 脚本从视频生成缩略图:
#!/bin/bash
source_dir="."
output_dir="/output"
input_file_types=(avi wmv flv mkv mpg mp4)
output_file_type="jpg"
r1=$(( ( RANDOM % 10 ) + 5 ))
convert() {
echo "" | ffmpeg -ss 00:"r1":05 -y -i "$1" -an -f image2 -vframes 1 "$output_dir/$2"
}
for input_file_type in "${input_file_types[@]}"
do
find "$source_dir" -name "*.$input_file_type" -print0 | while IFS= read -r -d $'\0' in_file
do
echo "Processing…"
echo ">Input $in_file"
# Replace the file type
out_file=$(echo "$in_file" | sed "s/\(.*\.\)$input_file_type/\1$output_file_type/g")
# The above can be shortened …Run Code Online (Sandbox Code Playgroud)