I am sorry if my post was impolite or misleading. I just like to know about the knowledge the OP already has. It is just clear the OP is aware about the power of shell scripts. It might be that he has already used find, sort, sed and so on from time to time. Then it is not difficult to do the step to shell scripts. But it can also be the other way arround. From my perspective there is no clear indication in the initial question. Lets us wait for the answer of Mayhem30.In other words, google it? One suspects the OP knew that and was looking for pointers.
for i in {a..z}; do mkdir $i && mv $i* $i; done
Even if it's used once, something like below would be less tedious. Note, you'll get warnings that you can ignore, because it will try to move the newly created folder to itself.
for i in {a..z}; do mkdir $i && mv $i* $i; done
I'll leave it as an exercise to deal with files starting with numbers. I can't steal all the fun. I did this in zsh, but I think it will work in bash as well.
for i in `jot -c 26 a`; do mkdir $i && mv $i?* $i; done
## generate some (100) random files in the format @Mayhem30 described
~/tmp % for i in `seq 1 100`; do RAND=$(cat /dev/urandom | env LC_CTYPE=C tr -dc 'a-z0-9' | head -c 5); touch ${RAND}.png; done
## command to solve @Mayhem30's question without warnings (@jalla used the mv target $i?*)
~/tmp % for i in `jot -c 26 a; jot 10 0`; do mkdir $i && mv $i?* $i; done
#!/bin/sh
targetdir="/tmp"
for fname in *; do
firstchar=`expr "${fname}" : '\(.\)'`
echo "mkdir -p "{$targetdir}/${firstchar}-files""
echo "cp "${fname}" "${targetdir}/${firstchar}-files""
done
echo
s to verify that it was doing the right thing, and cp
rather than mv
because one bad mv
will ruin your day.