Hi Guys
I'm new to Unix admnistration, i'm currently looking after a set of directories that need to have the files ordered within them into a hierarchy depending on alphabetical order. I've been working on a shell script that would order all files by their first letter and create alphabetical directories accordingly.
It is only to arrange files in the current working directory and create the directories to store the files where appropriate, it doesnt need to create any empty subdirs. anything that is not an ordinary file needs to be left as it is. the twist in this script is I need to create a working list that can be appended to in text form to list the files that have been reordered so that I can keep an eye on where files are moving to.
So far I have came up with: -
#!/bin/sh
ls|while read xx
do
if [ -f $xx ] ;then
dir=$(echo $xx|awk '{print substr( $1, 1, 1)}')
if [ ! -d $dir ] ;then
mkdir $dir
fi
mv $xx $dir
fi
done
But I cant get it to work and its giving me a huge headache lol, any help would be greatly appreciated!
Marie
I'm new to Unix admnistration, i'm currently looking after a set of directories that need to have the files ordered within them into a hierarchy depending on alphabetical order. I've been working on a shell script that would order all files by their first letter and create alphabetical directories accordingly.
It is only to arrange files in the current working directory and create the directories to store the files where appropriate, it doesnt need to create any empty subdirs. anything that is not an ordinary file needs to be left as it is. the twist in this script is I need to create a working list that can be appended to in text form to list the files that have been reordered so that I can keep an eye on where files are moving to.
So far I have came up with: -
#!/bin/sh
ls|while read xx
do
if [ -f $xx ] ;then
dir=$(echo $xx|awk '{print substr( $1, 1, 1)}')
if [ ! -d $dir ] ;then
mkdir $dir
fi
mv $xx $dir
fi
done
But I cant get it to work and its giving me a huge headache lol, any help would be greatly appreciated!
Marie