Supondo que os arquivos nunca tenham traços -
ou maiúsculas T
nos nomes, você pode criar o seguinte laço bash:
for f in *
do
date=$(tmp=${f#*-};echo ${tmp%T*})
time=$(tmp=${f#*T};echo ${tmp%-*})
suffix=${f##*-}
mkdir -p ${date}/${time}/${suffix}
mv $f ${date}/${time}/${suffix}/
done
Esta é a sintaxe básica de expansão de parâmetros do bash, conforme a página man:
${parameter#word} ${parameter##word} Remove matching prefix pattern. The word is expanded to produce a pattern just as in pathname expansion. If the pat‐ tern matches the beginning of the value of parameter, then the result of the expansion is the expanded value of param‐ eter with the shortest matching pattern (the ''#'' case) or the longest matching pattern (the ''##'' case) deleted. If parameter is @ or *, the pattern removal operation is applied to each positional parameter in turn, and the expan‐ sion is the resultant list. If parameter is an array variable subscripted with @ or *, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list. ${parameter%word} ${parameter%%word} Remove matching suffix pattern. The word is expanded to produce a pattern just as in pathname expansion. If the pat‐ tern matches a trailing portion of the expanded value of parameter, then the result of the expansion is the expanded value of parameter with the shortest matching pattern (the ''%'' case) or the longest matching pattern (the ''%%'' case) deleted. If parameter is @ or *, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with @ or *, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.
Eu usei uma variável temporária como espaço reservado, já que o bash não permite o aninhamento direto da expansão op.
date=$(tmp=${f#*-};echo ${tmp%T*})
$f
é o nome do arquivo atual
tmp={f#*-}
: remova tudo até e incluindo o PRIMEIRO -
Neste momento, o tmp contém {date}T{time}-{suffix}
e ${tmp%T*}
: remove tudo depois de T
(inclusive)