In a terminal: cd
into the directory in question, then
for x in `ls -1 | sed -e 's/^\(.\).*/\1/' | sort -u`; do
mkdir $x && mv -i ${x}?* $x
done
This assumes that no files have a single character name before you start. If they do, you might move them aside before you run the above procedure:
mkdir singles && mv ? singles
and then move them to their appropriate destinations aftwards.
Edit: See the comments below for some caveats. If you run into problems with too long command lines, you could replace the second line by
mkdir $x && find . -maxdepth 1 -name "${x}?*" -exec mv -i {} $x \;
So, does it matter if the file is the same file?
ie: Let say there is a picture google.png
and you want it to copied into the same dir 4 times.
as an in that directory you would have
google.png google 2.png google 3.png google 4.png?
If thats what you want:
for i in {1..4}
do
cp google.png "google$i.png"
done
But if you want the "images" files to be different, and they are going to be gibrish files, but 10m in size exactly
you wanna do something like
for i in {1..5}
do
dd if=/dev/random of="yourfilename$i.test" bs=12428800 count=1
done
This will make four files that are 10m in size filled with bunch of random characters.
Comment and let me know what you really want and I can go back and redo this.
It would help if you posted your script that fails so I can see what youre trying to do.
EDIT:
Changed the in device from /dev/zero to /dev/random to generate random file content.
Best Answer
Command
This command was tested in a bash shell.
Explanation
The code shown below is not necessary commands you can execute. Rather, what is shown is an explanation of various parts of the code shown above.
Loop through all file names in current directory.
Only do regular files. (Skip the directories.)
Make new directory
newdir
.Move file
x
to new directorynewdir
.Rename
newdir
to the name of the desired new directory. (Setnewdir
to file namex
after removing the last.
and all characters that follow.)Comments
If the desired directory already exists, then the
newdir
folder (containing the file) will be moved to the desired directory. For example, if the file123.mp4
and directory123
both already exist, then file123.mp4
will end up in123/newdir
. You can test to see if this occurred by entering the command given below.For example, if
123/newdir/123.mp4
existed, then the follow output would appear.