LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Copy an entire folder tree (https://www.linuxquestions.org/questions/linux-newbie-8/copy-an-entire-folder-tree-834717/)

pshankland 09-27-2010 07:42 AM

Copy an entire folder tree
 
Hi,

I am trying to use the cp command to copy some files around but want to preserve the entire folder structure. Example:

cp /folder1/folder2/file /backup

Then within the /backup location I want to see /backup/folder1/folder2/file.

I have tried cp -a and cp -p but neither give me the above.

Any suggestions?

Thanks.

druuna 09-27-2010 07:50 AM

Hi,

Is this what you are looking for?

cp --parents /folder1/folder2/file /backup

Hope this helps.

pshankland 09-28-2010 03:03 AM

Thanks Druuna that works perfectly :)

However, when I now run that in the following script I get 'cp: omitting directory' errors:

Code:

NAGIOS_FILES="/usr/local/nagios/etc/nagios.cfg \
                /usr/local/nagios/etc/cgi.cfg \
                /usr/local/nagios/etc/resource.cfg \
                /usr/local/nagios/etc/htpasswd.users \
                /usr/local/nagios/libexec/"
NAGVIS_FILES="/etc/php.ini \
                /usr/local/nagvis/etc/maps/ \
                /usr/local/nagvis/share/userfiles/"
mkdir $BACKUP_TEMP
cp --parents $NAGIOS_FILES $BACKUP_TEMP
cp --parents $NAGVIS_FILES $BACKUP_TEMP

I assume it is because of the way I put putting multiple locations within the variables to be copied but am not sure.

Thanks.

vinaytp 09-28-2010 03:48 AM

Quote:

Originally Posted by pshankland (Post 4111133)
cp --parents $NAGIOS_FILES $BACKUP_TEMP
cp --parents $NAGVIS_FILES $BACKUP_TEMP

May be you have to include -r switch with --parents


All times are GMT -5. The time now is 10:31 PM.