View Single Post

  #1 (permalink)  
Old 10-25-2007, 04:23 PM
kalt kalt is offline
Junior Member
User
 
Join Date: Oct 2007
My distro: Fedora
Posts: 2
Rep Power: 0
kalt is on a distinguished road
Default Shell script to restructure folders recursively

Hello all,

I need some help. I have to copy hundred of files from the following structure:

office/desk/file1.txt
office/desk/file2.txt
office/chair/file1.txt
office/chair/file2.txt
office/chair/file3.txt

to this structure:

office_desk1/file1.txt
office_desk2/file2.txt
office_chair1/file1.txt
office_chair2/file2.txt
office_chair3/file3.txt

I'm not good at writing shell script. The closes script that I found so far is this:

function copy_files() {
echo copying $1 files
tar -cf - `find . -name "*.$1" -print` | ( cd ../dest && tar xBf - )
}

I don't know how to create a folder from the folder it's in and the file number.
Reply With Quote