hi there,
i'm new to UNIX( just 3month used),
i found my new box contained alot of files and directories in /home/box/
i've tried to search script in tis forum and found many of them but, i don't know
how to combine them to make a script, although using pipes.
my tasks are:
1) to scan user dir in /home/user/ - i'm used ls-ld /home/$user/ , $user must be key in.
2) Then, grouping all files in scanned dir(in task 1), into group of extensions such as ".txt",".sh",".dat"
i used the ls -l | awk 'BEGIN {FS="."} {print $2}'>index.txt
3) Based on index.txt, i'm going to make directories referring to those extensions eg.
/home/user/txtExtension
/home/user/datExtension/
then move all of files to their extension dir. i'm sorry, i can't find the way to create this script.
i tried all my best to combine all above simple script but, no.3 is quite hard for me.
is there any UNIX-Shell expert have ideas, solutions, or even example scripts to guide me
Regards,
Helmi.
I tested the below script by creating user directories under /tmp with different types of file extensions
#!/bin/ksh
/bin/rm index.dat
set -A USER_HOME /tmp/UserA /tmp/UserB /tmp/UserC /tmp/Root /tmp/GroupA /tmp/GroupB
set -A USERS UserA UserB UserC Root GroupA GroupB
for v in ${USERS[*]} ; do
find /tmp/$v -type f | awk -F. ' (NF == 2 ){ print $2 }' | sort -ud | tee -a index.dat
done
for type in $(<index.dat); do
NewDir=/tmp/${type}-IndexedFileDir
mkdir -p $NewDir
find ${USER_HOME[*]} -type f -name "*.$type" -print | xargs -I{} -t mv {} ${NewDir}
done
Please check the above script by running it on some fake directories and let us know if this doesnot help.
Oh, man...so cool ennstate
Thanks a lot pal!
it all work well ! but there is something i missed at first,
if certain file being removed without "noticing/asking permission to move" the user or root, is it really troublesome for other users to track back and maybe they expected the files had been deleted.
for second time , is there anyone can coupe this problems, maybe, by make a certain tracker log or something?