i'm trying to have a script organize files by their first few letters into directories made automatically. my problem is i'd like to skip making directories for single files
i have found a command on here that very simply does what i want. if i run it i will have my files placed into alphabetical folders, A, B, etc. after playing with that, i studied the unix "cut " command and have changed the code into a .sh script. now it works and it will make the folders the first four letters of the filename(i want a folder for each customer, and this way i can easily rename them later).
i am afraid to run it. i do not want to end up with a bunch of odd folders that only contain one file each. it also seems to easy. i like to learn and i have my linux shell scripting bible handy.
how can i make my script sort files into directories as it does now, but have it not make directories that would only contain a single file?
like if i had the following seven files:
robert01.cdr
robert02.cdr
mom01.cdr
mom02.cdr
mom03.cdr
father.cdr
sister.cdr
i would want the roberts and moms in their respective directories, but i would want the single file father and the single file sister to remain unfoldered, ie:
[robe]
[mom0]
father.cdr
sister.cdr
i'm new, this is my first time using this site. i'm not lazy looking for someone to do this for me, i'm just a little lost. if someone could provide a link to a sample i could learn from, or at least point me towards a command i might study up on, that is what i want. i'm here to learn (:
we have a small sign business with a few thousand unorganized coreldraw files in about 50 different folders on a few different computers. i'm trying to undo years of bad organizing while learning in the process
for R in *.cdr; do
name=`echo "$R"|sed 's/ -.*//'`
letter=`echo "$name"|cut -c1-4`
dir="rawr/$letter/$name"
mkdir -p "$dir"
mv "$R" "$dir"
done