LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Move files from several subdirectories one level back (http://www.linuxquestions.org/questions/programming-9/move-files-from-several-subdirectories-one-level-back-521494/)

Marinus 01-21-2007 03:48 PM

Move files from several subdirectories one level back
 
Hi,

I hope you can help me with this issue. I'm trying to move a lot of files, currently located in numbered subdirectories, one level back. The subdirectories are named as

../invoices/invoice00001/
../invoices/invoice00002/
etc.

They all contain one file (invoicexxxxx.odt).
And all these files should all go to the folder directly above those directories, '/invoices/.

Is it possible to do that via a shell script? To do it manually would take me probably all day! :)

Thanks for any help,

Marinus.

MensaWater 01-21-2007 05:32 PM

Easy to do but not sure if you mean you want to move the files in invoice001 and invoice002 to invoices or if you mean invoices/invoice001 and invoices/invoice002 to the directory above invoices. Process is the same but off course details are different.

So within the directory invoices:

Code:

for DIR in `ls -d invoice*`
do cp -p $DIR/* .
done

The above would copy find invoice001, invoice002 etc... can copy all contents to the current directory (. = current directory) which is invoices.

If you want to go to the parent directory above invoices just use .. instead of . (.. = parent directory of current directory).

Marinus 01-21-2007 05:59 PM

Hi J.,

that's exactly what I was looking for!
Thanks very much.

Marinus.


All times are GMT -5. The time now is 05:24 AM.