copy or move file and create target directory at the same time?
by taylorkh from LinuxQuestions.org on (#5MRBG)
I am posting this to the Newbie forum as it seems to be rather fundamental and an answer might be helpful here. In a nutshell, I have a bunch of files representing my monthly data backup in a stucture as shown below. My objective is to copy or move the files to two new directory trees - one containing the .tar.gz files and the other containing the .tar.gz.gpg files. Here is a sample of the source directory tree and files:
/data/stage/
/data/stage/data/
/data/stage/data/LibreOffice.tar.gz
/data/stage/data/LibreOffice.tar.gz.gpg
/data/stage/data/thunderbird.tar.gz
/data/stage/data/thunderbird.tar.gz.gpg
/data/stage/static/
/data/stage/static/PersonalDocuments.tar.gz
/data/stage/static/PersonalDocuments.tar.gz.gpg
/data/stage/static/Receipts&Statements.tar.gz
/data/stage/static/Receipts&Statements.tar.gz.gpg
The objective is to copy or move the documents to a structure like:
/data/proton/data/LibreOffice.tar.gz
/data/proton/data/thunderbird.tar.gz
/data/proton/static/PersonalDocuments.tar.gz
/data/proton/static/Receipts&Statements.tar.gz
/data/mega/data/LibreOffice.tar.gz.gpg
/data/mega/data/thunderbird.tar.gz.gpg
/data/mega/static/PersonalDocuments.tar.gz.gpg
/data/mega/static/Receipts&Statements.tar.gz.gpg
I can cp the entire /data/stage/ tree to /data/proton/ However, that copies both the .gz and .gpg files. I have not found any option to cp which will allow me to filter on only one file extension. No luck with mv either.
If I create the entire target tree manually to start with I can use a "find ... -exec" approach to copy of move the files one by one. And I could hard code the commands to create the target tree in my script. I am looking for a more elegant and flexible approach. Any advice greatly appreciated.
TIA,
Ken
/data/stage/
/data/stage/data/
/data/stage/data/LibreOffice.tar.gz
/data/stage/data/LibreOffice.tar.gz.gpg
/data/stage/data/thunderbird.tar.gz
/data/stage/data/thunderbird.tar.gz.gpg
/data/stage/static/
/data/stage/static/PersonalDocuments.tar.gz
/data/stage/static/PersonalDocuments.tar.gz.gpg
/data/stage/static/Receipts&Statements.tar.gz
/data/stage/static/Receipts&Statements.tar.gz.gpg
The objective is to copy or move the documents to a structure like:
/data/proton/data/LibreOffice.tar.gz
/data/proton/data/thunderbird.tar.gz
/data/proton/static/PersonalDocuments.tar.gz
/data/proton/static/Receipts&Statements.tar.gz
/data/mega/data/LibreOffice.tar.gz.gpg
/data/mega/data/thunderbird.tar.gz.gpg
/data/mega/static/PersonalDocuments.tar.gz.gpg
/data/mega/static/Receipts&Statements.tar.gz.gpg
I can cp the entire /data/stage/ tree to /data/proton/ However, that copies both the .gz and .gpg files. I have not found any option to cp which will allow me to filter on only one file extension. No luck with mv either.
If I create the entire target tree manually to start with I can use a "find ... -exec" approach to copy of move the files one by one. And I could hard code the commands to create the target tree in my script. I am looking for a more elegant and flexible approach. Any advice greatly appreciated.
TIA,
Ken