LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-27-2010, 07:42 AM   #1
pshankland
Member
 
Registered: Feb 2006
Location: UK
Distribution: CentOS 5.5
Posts: 46

Rep: Reputation: 15
Question 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.
 
Old 09-27-2010, 07:50 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Hi,

Is this what you are looking for?

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

Hope this helps.
 
Old 09-28-2010, 03:03 AM   #3
pshankland
Member
 
Registered: Feb 2006
Location: UK
Distribution: CentOS 5.5
Posts: 46

Original Poster
Rep: Reputation: 15
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.
 
Old 09-28-2010, 03:48 AM   #4
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Rep: Reputation: 55
Quote:
Originally Posted by pshankland View Post
cp --parents $NAGIOS_FILES $BACKUP_TEMP
cp --parents $NAGVIS_FILES $BACKUP_TEMP
May be you have to include -r switch with --parents
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
want to copy an inode folder from acdrom to a home directory (folder). nhbob Linux - Newbie 8 12-20-2009 11:12 AM
can i copy the entire contents of a partition and use it. deathalele Linux - General 5 06-30-2008 11:31 AM
How to copy entire contents brick_46143 Linux - Newbie 15 02-27-2008 11:46 AM
ls entire subdirectory tree snocked Linux - General 6 07-27-2006 08:29 PM
How to copy files from an entire directory tree using terminal commands??? lusius188 Linux - General 3 04-10-2006 11:23 AM


All times are GMT -5. The time now is 12:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration