Operating System - HP-UX
1827286 Members
1666 Online
109717 Solutions
New Discussion

what is a good command to copy the directory,

 
SOLVED
Go to solution
Hanry Zhou
Super Advisor

what is a good command to copy the directory,

and all leveles of its sub-directories underneath the top directory? I want to copy all directories structure only, not files underneath.

thanks,
Roger
none
12 REPLIES 12
Patrick Wallek
Honored Contributor

Re: what is a good command to copy the directory,

I know of no HP-UX command that will just copy the directory structure, but not the files.

You could possibly create something with a combination of 'find . -type d', mkdir and chmod/chown.

Geoff Wild
Honored Contributor

Re: what is a good command to copy the directory,

Sounds like you want to create the directories - not copy them...

Okay - find them all first:

for DIR in `find /home -type d -print`
do
mkdir -p /newdir/$DIR
done

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Alzhy
Honored Contributor

Re: what is a good command to copy the directory,


find ./srcdir -type d |cpio -pdvmu /tgtdir

Hakuna Matata.
Sundar_7
Honored Contributor

Re: what is a good command to copy the directory,

Sure there is a way...you can use pax for duplicating directory hierarchies

On system1

find . â type d â print | pax â w â d â p o â f /root/dir-structure

On system2

Copy the file /root/dir-structure from system1 and execute

# pax -rv -p o /root/dir-structure
Learn What to do ,How to do and more importantly When to do ?
Sundar_7
Honored Contributor
Solution

Re: what is a good command to copy the directory,

Sorry my last post got messed up

in system1

find . -type d -print | pax -w -d -p o -f /root/dir-structure

in system2

pax -rv -p o /root/dir-structure
Learn What to do ,How to do and more importantly When to do ?
Rick Garland
Honored Contributor

Re: what is a good command to copy the directory,

The cpio command is very useful in this situation. Will copy the files/subdirs and keep perms and ownerships intact.

cd
find . -depth | cpio -pmuldv

"cpio pmudl" is how I remember it.

Hein van den Heuvel
Honored Contributor

Re: what is a good command to copy the directory,



yet another option:

cd to target,
find -d,
cut off leading char(acters)
feed to mkdir.
For exameple:

find /var/opt -type d | cut -b 6- | xargs mkdir

(relatively) safe way to clean up after experiments:

find -depth -exec rmdir {} \;



Re: what is a good command to copy the directory,

Hi ..

Why are u all making things complex..

Try cp -R

That's it..Read "man cp"

regrads,
sree

Re: what is a good command to copy the directory,

oops..
I missed some thing...

After cp command
run rm `find .`


regards,
sree

Sยภเl Kย๓คг
Respected Contributor

Re: what is a good command to copy the directory,

Dear sree
I think u didn't understand Hanry's question.He don't want to copy the files under the child directories,need to copy the directory structure only.
#cp -R won't serve the purpose.

regards
SK
Your imagination is the preview of your life's coming attractions
Sundar_7
Honored Contributor

Re: what is a good command to copy the directory,

Hanry,

Believe me, PAX is the way to go. With all those find and mkdirs, you sure can duplicate the directory hierarchy. But it takes some more scripting to keep the ownership also the access permissions.

- Sundar
Learn What to do ,How to do and more importantly When to do ?
Geoff Wild
Honored Contributor

Re: what is a good command to copy the directory,

Sundar has it - right from the pax man page:

DESCRIPTION
The pax command extracts and writes member files of archive files;
writes lists of the member files of archives; and copies directory
hierarchies.

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.