#!/usr/bin/env bash : <<'END' bash zip.sh --stage 0 --stop_stage 0 \ --min_date 2025-04-28 \ --target_dir E:/Users/tianx/HuggingDatasets/nx_noise/data/noise/en-PH \ --debug true bash zip.sh --stage 0 --stop_stage 0 \ --min_date 2025-04-28 \ --target_dir E:/Users/tianx/HuggingDatasets/nx_noise/data/noise/en-PH \ --debug false bash zip.sh --stage 0 --stop_stage 0 \ --min_date 2022-04-28 \ --target_dir /data/tianxing/HuggingDatasets/nx_noise/data/speech/nx-speech/en-PH \ --debug true bash zip.sh --stage 0 --stop_stage 0 \ --min_date 2022-04-28 \ --target_dir /data/tianxing/HuggingDatasets/nx_noise/data/speech/nx-speech/en-PH \ --debug false END # params system_version="windows"; verbose=true; stage=0 # start from 0 if you need to start from data preparation stop_stage=9 min_date="2025-04-28" target_dir="E:/Users/tianx/HuggingDatasets/nx_noise/data/noise/en-PH" debug=true; # parse options while true; do [ -z "${1:-}" ] && break; # break if there are no arguments case "$1" in --*) name=$(echo "$1" | sed s/^--// | sed s/-/_/g); eval '[ -z "${'"$name"'+xxx}" ]' && echo "$0: invalid option $1" 1>&2 && exit 1; old_value="(eval echo \\$$name)"; if [ "${old_value}" == "true" ] || [ "${old_value}" == "false" ]; then was_bool=true; else was_bool=false; fi # Set the variable to the right value-- the escaped quotes make it work if # the option had spaces, like --cmd "queue.pl -sync y" eval "${name}=\"$2\""; # Check that Boolean-valued arguments are really Boolean. if $was_bool && [[ "$2" != "true" && "$2" != "false" ]]; then echo "$0: expected \"true\" or \"false\": $1 $2" 1>&2 exit 1; fi shift 2; ;; *) break; esac done if [ ${stage} -le 0 ] && [ ${stop_stage} -ge 0 ]; then $verbose && echo "stage 0: zip run" target_date=$(date -d "$min_date" +%s) cd "$target_dir" || { echo "无法进入目录: $target_dir"; exit 1; } # do it. ... # 遍历所有子目录 for dir in */; do dir_name=${dir%/} if [[ $dir_name =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then dir_date=$(date -d "$dir_name" +%s 2>/dev/null) if [ -n "$dir_date" ] && [ "$dir_date" -ge "$target_date" ]; then if [ "${debug}" == "true" ]; then echo "[DEBUG] zip -r ${dir_name}.zip $dir_name" else echo "zip -r ${dir_name}.zip $dir_name" zip -r "${dir_name}.zip" "$dir_name" fi fi fi done fi