for i in $(ls | cut -c 1 | grep -v ‘[0-9]’ | uniq); do mkdir “$i”; done
EDIT: So that ^ was my first thing. Then I decided to take this further…one line to rule them all and both create the single letter directory and then continue to move every other folder into the single letter directory:
for i in $(ls | cut -c 1 | grep -v ‘[0-9]’ | uniq); do mkdir “$i” && for j in $(ls | grep ‘^’$i’..*‘); do mv “$j” “$i”; done ; done
^What that does is look for every first letter existent in the current directory, make a folder for each, and at the same time, look for any other folders starting with that same letter (but which are made up of >1 characters) and move them to this new directory.
So this:
drwxr-xr-x 7 god staff 238B Nov 27 00:24 . drwxr-xr-x+ 83 god staff 2.8K Nov 27 00:24 .. drwxr-xr-x 2 god staff 68B Nov 27 00:06 Cakes drwxr-xr-x 2 god staff 68B Nov 27 00:21 Crapshoot drwxr-xr-x 2 god staff 68B Nov 27 00:21 Razzle drwxr-xr-x 2 god staff 68B Nov 27 00:06 Rofl
would become this:
[~/test]> ls -lah [0:27:24 on 11/27/13] total 0 drwxr-xr-x 4 god staff 136B Nov 27 00:27 . drwxr-xr-x+ 83 god staff 2.8K Nov 27 00:27 .. drwxr-xr-x 5 god staff 170B Nov 27 00:27 C drwxr-xr-x 4 god staff 136B Nov 27 00:27 R [~/test]> ls -lah * [0:27:26 on 11/27/13] C: total 0 drwxr-xr-x 5 god staff 170B Nov 27 00:27 . drwxr-xr-x 4 god staff 136B Nov 27 00:27 .. drwxr-xr-x 2 god staff 68B Nov 27 00:06 Cakes drwxr-xr-x 2 god staff 68B Nov 27 00:21 Crapshoot R: total 0 drwxr-xr-x 4 god staff 136B Nov 27 00:27 . drwxr-xr-x 4 god staff 136B Nov 27 00:27 .. drwxr-xr-x 2 god staff 68B Nov 27 00:21 Razzle drwxr-xr-x 2 god staff 68B Nov 27 00:06 Rofl