#!/bin/bash
# This would match files that begin with YYYYMMDD format.
files=(*[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].wav)
# If you want to match those in the current year, start it with that year instead.
# current_year=$(date +%Y)
# files=("$current_year"[0-9][0-9][0-9][0-9]*)
#expands its values to multiple arguments '${files[@]}'
for file in ${files[@]}; do
file_date=${file:(-12):8}
file_year=${file_date:0:4}
file_month=${file_date:4:2}
# Adding -p option to mkdir would create the directory only if it doesn't exist.
mkdir -p "$file_year"
file_month=${file:4:2}
cd $file_year
mkdir -p "$file_month"
cd ..
mv $files "$file_year"/"$file_month"
done
第 20 行出现错误: cd: -9: invalid option cd: usage: cd [-L|[-P [-e]]] [dir] mv: invalid option -- '9' Try `mv --help' for更多信息。