The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 04-19-2007
ennstate ennstate is offline
Registered User
  
 

Join Date: Mar 2007
Location: Chennai
Posts: 222
Moving Files by Index

I tested the below script by creating user directories under /tmp with different types of file extensions

Code:
#!/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.

Thanks
Nagarajan Ganesan