Artificial intelligent assistant

How to split a directory of files into sub-directories I have a directory full of files similar to these: 3260_661901_2008-2008.dat 3260_661901_2009-2009.dat 3260_661901_2010-2010.dat 3260_661901_2011-2011.dat 3260_661901_por-1998.dat 3260_662336_1999-1999.dat 3260_662336_2000-2000.dat 3260_662336_2001-2001.dat 3260_662336_2002-2002.dat I would like to split off the files into directories names after the 6th and 7th character in the filename like this: 66/3260_661901_2008-2008.dat 66/3260_661901_2009-2009.dat 66/3260_661901_2010-2010.dat 66/3260_661901_2011-2011.dat 67/3260_671901_por-1998.dat 67/3260_672336_1999-1999.dat 67/3260_672336_2000-2000.dat 88/3260_882336_2001-2001.dat 88/3260_882336_2002-2002.dat Is there a quick one liner command I can use to create the subdirectories and move the files into them? I should mention the directory has over 33k files in it.

try


ls | awk '{d=substr($0,6,2) ; printf "mkdir %s ; mv %s %s\
",d,$1,d }' | bash


* in this case, you can use ls result as input.
* you'll get error message as dir exists after first `mkdir`, to get rid use :

awk '{d=substr($0,6,2) ; printf "test -d %s || mkdir %s ; mv %s %s\
",d,d,$1,d }'

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy dd10ab336b33d5c7bafda46cad42405f