I'm trying to group files automatically into subdirectories using a command like this:$ rename 's/(.)(.)(.+)/$1\/$2\/$1$2$3/' *.*A dry run with the -n parameter shows me what I want:test.jpg renamed as t/e/test.jpgBut the actual renaming fails withCan't rename test.jpg t/e/test.jpg: No such file or directorybecause the subdirectories do not exist yet.How can I achieve this without creating all subdirectories manually beforehand?
Rename command with non-existing target directory
files;perl;rename
There is difference between renaiming and moving to somewhere. In the case easyest way (in modern bash) is loop through all files:for f in *.*do    d=${f::1}/${f:1:1}    [ -d $d ] || mkdir -p $d    mv $f $ddone