Operating System - HP-UX
1819818 Members
3289 Online
109607 Solutions
New Discussion юеВ

Re: copying directory structure

 
SOLVED
Go to solution
Claudio_17
Frequent Advisor

copying directory structure

Hello ,

I need copy a directory structure from one poit to another ; I've many direcory and sub-directory . I want also maintain owernships and permission.


13 REPLIES 13
Pete Randall
Outstanding Contributor

Re: copying directory structure

Use the find command with cpio:


cd /source_dir
find . -print |cpio -pdumxl /target_dir


Pete


Pete
Massimo Bianchi
Honored Contributor

Re: copying directory structure

I will try this:


Creating the archive:
find . -type d -print | pax -w -d -f directory.pax


on the destination:
pax -r -f directory.pax


Massimo
Umapathy S
Honored Contributor

Re: copying directory structure

Claudio,
You can use tar.

tar -cvf

untar in your destination dir

tar -xvf

man tar for more details.

HTH,
Umapathy
Arise Awake and Stop NOT till the goal is Reached!
Patrick Wallek
Honored Contributor

Re: copying directory structure

Do you need the directory structure only, or do you also need the files in the directories? When you one point to another, do you mean on the same system, or from one system to another?

To copy a directory structure and all files and sub-dirs to another spot on the same machine:

# cp -Rp /dir/to/copy /destination/dir

If you need to transfer to another machine, I'd use tar.

# cd /dir/to/copy
# tar -cvf dir_file.tar .

If you just need the directory structure, I can't think of a good way offhand.
Jeff Schussele
Honored Contributor

Re: copying directory structure

Hi

Use

cp -r sourceidr targetdir

targetdir should not already exist

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Claudio_17
Frequent Advisor

Re: copying directory structure

I need copy a directory structure ; only dir , not files . And is from one system to another , but in target system I've same user/group so is not and UID/GID problem

Thanks
Pete Randall
Outstanding Contributor

Re: copying directory structure

OK, then:

cd /source_dir

find . -type d |cpio -pdumxl /target_dir


Pete


Pete
Massimo Bianchi
Honored Contributor
Solution

Re: copying directory structure

Hi Claudio, i made a little mistake in the extraction part:

should read


cd destination_base_dir
pax -rv < directory.pax


Massimo
Leif Halvarsson_2
Honored Contributor

Re: copying directory structure

Hi,
Try
find . -type d -print |cpio -pdvmux /
Claudio_17
Frequent Advisor

Re: copying directory structure

Thanks very much to all ; sorry I didn't specify copy was between two box


Jeff Schussele
Honored Contributor

Re: copying directory structure

Hi (again) Claudio,

Well if it's between systems & it's a one-time shot, then I'd just use tar & ftp

On host1:
tar cvf /tmp/dir_name.tar /dir_name
ftp host2
>put /tmp/dir_name.tar /tmp/dir_name.tar

On host2
tar xvf /tmp/dir_name.tar

Make sure /tmp has enough space - if not use a holding dir that does. This will preserve ownership (provided host2 has the user(s) defined) & permissions.

HTH,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
hein coulier
Frequent Advisor

Re: copying directory structure

here's a nice one i use to copy files from one system to another :

cp_dir()
{
source_dir=$1
target_dir=$2
target_host=$3

cd ${source_dir} ; tar cf - . |
rexec ${target_host} -l root "cd ${target_dir} ; tar xpf -"
cd -
}
Rodney Hills
Honored Contributor

Re: copying directory structure

I use the following for large amounts of data-

fbackup -f - -i /path1 -i /path2 | compress -c | ( remsh otherhost "cd /newpath ; zcat - | frecover -Xx -f - )

Where-
/path1,/path2 are the directories to copy
otherhost is the remote host name
/newpath is where the directories are to be copied

The benefits-
Any ACL info is maintained, and with "compress" the amount of data across the network is kept to a minimum. With fbackup I can select multiple paths, whereas tar is relative to the current working directory.

Downside-
Dependent on "r" commands (remsh,rlogin,rexec) which are not the most secure.

HTH

-- Rod Hills
There be dragons...