-   Programming (
-   -   Move files from several subdirectories one level back (

Marinus 01-21-2007 03:48 PM

Move files from several subdirectories one level back

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


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,


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:


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

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.


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