[root@localhost images]# cat junshuv3.sh
#!/bin/bash
# 确保脚本在 ~/images 目录下运行
if [ "$(pwd)" != "$HOME/images" ]; then
cd ~/images
fi
# 创建目标目录 junshu,如果不存在则创建
mkdir -p junshu
# 获取CSV文件中的总行数,用于进度条
total_lines=$(wc -l < AiImgs-5Rope.csv)
current_line=0
bar_length=100
# 逐行读取 AiImgs-5Rope.csv 文件
while IFS=',' read -r id image_path
do
# 去除路径末尾的回车符
image_path=$(echo $image_path | tr -d '\r')
# 确定原图片路径
src_path="$image_path"
# 复制图片到目标目录 junshu,并保留原文件名
if [ -f "$src_path" ]; then
cp "$src_path" "junshu/$(basename "$src_path")"
else
echo "File $src_path does not exist."
fi
# 更新进度
current_line=$((current_line + 1))
progress=$((current_line * 100 / total_lines))
filled_length=$((bar_length * current_line / total_lines))
bar=$(printf "%-${bar_length}s" "#" | sed "s/ /#/g")
empty_bar=$(printf "%-${bar_length}s" " ")
echo -ne "Progress: [${bar:0:filled_length}${empty_bar:filled_length}] $progress% ($current_line/$total_lines)\r"
done < AiImgs-5Rope.csv
# 完成后换行
echo -ne '\n'
# 压缩目标目录为 AiImgs-5rope.zip
zip -r AiImgs-5rope.zip junshu
标签:shell,bar,海量,20240709,current,AiImgs,length,path,line From: https://www.cnblogs.com/huojunshu/p/18291723