#!/bin/bash
# When a match is not found, just present nothing.
shopt -s nullglob
files=(*.wav)
if [[ ${#files[@]} -eq 0 ]]; then
echo "No match found."
fi
for file in "${files[@]}"; do
# We get the date part
find_date=$(stat -c %y $file | awk '{print $1}')`
for t in "${parts[@]}"; do
IFS="-." read -ra parts <<< "$file"
if [[ $t == [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] ]]; then
file_date=$t
break
fi
done
# If a value was not assigned, then show an error message and continue to the next file.
# Just making sure there is nothing in Array and date before it moves on
if [[ -z $file_date ]]; then
continue
fi
file_year=${file_date:0:4}
file_month=${file_date:6:2}
mkdir -p "$file_year/$file_month"
# -- is just there to not interpret filenames starting with - as options.
echo "Moving: ./"$file "to: " "./"$file_year"/"$file_month
mv "$file" "$file_year/$file_month"
done
我有一些文件是 .wav .... 我想像我一样将文件放在一个数组中,然后 Stat -c %y filename |awk $1 这给了我 YYYY-MM-DD 然后我想放日期在数组中,然后我可以将其设置为 2 个变量年和月,这样我就可以创建一个 DIR 年/月,或者如果 DIR 已经存在,那么只需 mv 它。这是 mkdir -p... 在我的代码中出现错误,但我认为我没有正确读取数组中的文件。
25:继续:仅在一段时间内有意义for',
',或'直到'循环我的回声语句移动:./OUT117-20092025-5845.wav 到:.//