View Single Post

  #2 (permalink)  
Old 10-25-2007, 08:25 PM
nixcraft's Avatar
nixcraft nixcraft is offline
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Ubuntu
Posts: 1,101
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Try out following code. setup DEST for actual location where you wanna put files. You need to put script in root directory of office/desk. For example it it is /home/tom/office/desk, put script in /home/tom, alternatively you can modify LIST=(find ...) to specify path.

Code:
#!/bin/bash
LIST=$(find . -iname "*.txt")
DEST="/tmp/test"
[ ! -d $DEST ] && mkdir $DEST || :
echo "Starting copy ..."
for f in $LIST
do 
 bdirs=$(echo $f | cut -d'/' -f2)
 bdirm=$(echo $f | cut -d'/' -f3)
 bfile=$(echo $f | cut -d'/' -f4)
 [ ! -d ${DEST}/${bdirs}_${bdirm} ] && mkdir ${DEST}/${bdirs}_${bdirm} || :
 /bin/cp -f $f ${DEST}/${bdirs}_${bdirm}/${bfile}
done
echo "Done! All files copied to $DEST"
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote