- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Copy directory tree
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2001 07:17 AM
08-01-2001 07:17 AM
/test/dir1/subd1.1/file
I would like to end up with /test/dir1 and everything below copying (retaining permissions and ownership) and being named as a tree called /test/dir2. Thus ending up with;
/test/dir1/subd1.1/file
&
/test/dir2/subd1.1/file
So I thought something like;
cp -pr /test/dir1 /test/dir2, but I end up with;
/test/dir2/dir1/subd1/file, not what I wanted.
Any ideas?
Regards
Chris
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2001 07:26 AM
08-01-2001 07:26 AM
Re: Copy directory tree
'cp' is the hard-way to do what you want! Try this:
# cd /test/dir1
# find . | cpio -pudlmv /test/dir2
See the man pages for the 'cpio' options!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2001 07:26 AM
08-01-2001 07:26 AM
Re: Copy directory tree
Try something like this:
mkdir /test/dir2
(set ownership and permission of this directory as desired using chown, chmod)
cd /test/dir1
find subd1.1 -print | cpio -pudvm /test/dir2/
Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2001 07:26 AM
08-01-2001 07:26 AM
Re: Copy directory tree
cp -pr /test/dir1/subd1.1/* /test/dir2
Just a thought,
Rita
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2001 07:27 AM
08-01-2001 07:27 AM
Re: Copy directory tree
The -R should do it, otherwise create a tar
from the tree you wish to keep
cd /mydir/tree
tar -cvf tree.tar tree
cd /newdir
tar -xvf tree.tar
Later,
Bill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2001 07:32 AM
08-01-2001 07:32 AM
Re: Copy directory tree
cd /test/dir1
find . -depth -print | cpio -pdumv /test/dir2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2001 07:45 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2001 07:50 AM
08-01-2001 07:50 AM
Re: Copy directory tree
mkdir /test/dir2
cp -pR /test/dir1/* /test/dir2
and a "chown"on /test/dir2 to get the same permissions as on dir1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2001 08:13 AM
08-01-2001 08:13 AM
Re: Copy directory tree
many cp-solutions, but only two cpio ones.
But cpio is the better one, because of the correct handling of sym-links.
See this sample (c being a copy of a instead of b):
# touch a
# ln -s a b
# ll ?
-rw-rw-rw- 1 root sys 0 Aug 1 18:12 a
lrwxrwxrwx 1 root sys 1 Aug 1 18:12 b -> a
# cp -p b c
# ll ?
-rw-rw-rw- 1 root sys 0 Aug 1 18:12 a
lrwxrwxrwx 1 root sys 1 Aug 1 18:12 b -> a
-rw-rw-rw- 1 root sys 0 Aug 1 18:12 c
#
Hope this helps
Volker
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2001 08:16 AM
08-01-2001 08:16 AM
Re: Copy directory tree
but as everyone stated, the best way is with find and cpio.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2001 08:22 AM
08-01-2001 08:22 AM
Re: Copy directory tree
#cd /test
#mkdir test2
#cd /test/dir1
#cp -Rp . /test/dir2
Thanks.
Prashant.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2001 08:31 AM
08-01-2001 08:31 AM
Re: Copy directory tree
I have ended up with;
cd /test
cp -pr dir1/. dir2
which does the trick.
Thanks yall.
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2001 08:38 AM
08-01-2001 08:38 AM
Re: Copy directory tree
I based my usage of your suggestion but modified the source to
cp -pr dir1/. dir2
As with an asterix it complained of too many files in my production usage.
Regards
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2001 08:56 AM
08-01-2001 08:56 AM
Re: Copy directory tree
cd to target_dir
find /path/source_dir -depth -print |cpio -pvdum .
I know this has already been suggested.....
good luck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2001 09:55 AM
08-01-2001 09:55 AM
Re: Copy directory tree
mkdir /test/dir2; cd /test/dir1;tar cpf - . | ( cd /test/dir2; tar xpf - )
A million ways to skin a cat!!!
...jcd...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2001 04:42 PM
08-01-2001 04:42 PM
Re: Copy directory tree
it does everything you want to do.