Copying only directory structure

Copying only directory structure

Post by John Do » Sat, 21 Dec 2002 00:09:09



I want to maintain the directory structure (not the contents of the
directory) in sync across 2 machines. How can I do this?

rdist seems to work fine for copying entire directory trees but I am not
interested in the contents of the directories, just the directory itself.

i.e. if a new directory ../new gets created on Source, I want it get created
on Target. If later, files are added to that directory, I dont want to copy
those files.

Any help appreciated.

Thanks

 
 
 

Copying only directory structure

Post by stephan bea » Sat, 21 Dec 2002 00:48:36



> I want to maintain the directory structure (not the contents of the
> directory) in sync across 2 machines. How can I do this?

This is probably a lame way to do it, but i've done it like this:

tar cf foo.tar $(find . -type d)
mv foo.tar /someplace
cd /someplace
tar xf foo.tar

--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.

 
 
 

Copying only directory structure

Post by stephan bea » Sat, 21 Dec 2002 00:50:43



> tar cf foo.tar $(find . -type d)
> mv foo.tar /someplace
> cd /someplace
> tar xf foo.tar

Or, to send them to another machine:


xf -'

--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.

 
 
 

Copying only directory structure

Post by Barry Margoli » Sat, 21 Dec 2002 01:12:46





>> I want to maintain the directory structure (not the contents of the
>> directory) in sync across 2 machines. How can I do this?

>This is probably a lame way to do it, but i've done it like this:

>tar cf foo.tar $(find . -type d)

I don't think that will do it.  When you give tar a directory name as an
argument, it archives the directory's contents.  In fact, the above command
will create lots of duplication in the archive; when tar archives "." it
will copy the entire hierarchy, and then when it archives "./subdir1" it
will copy that entire sub-hierarchy -- the result will be that each file
will exist N times in the archive, where N is its nesting depth.

--

Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

Copying only directory structure

Post by stephan bea » Sat, 21 Dec 2002 01:32:18



> I don't think that will do it.  When you give tar a directory name as an
> argument, it archives the directory's contents.

You're absolutely right about that, and i feel like an idiot.
i know i've zipped up dir structures before, though, and now need to
rediscover how i did it.

--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.

 
 
 

Copying only directory structure

Post by stephan bea » Sat, 21 Dec 2002 01:33:50



> I want to maintain the directory structure (not the contents of the
> directory) in sync across 2 machines. How can I do this?

> rdist seems to work fine for copying entire directory trees but I am not
> interested in the contents of the directories, just the directory itself.

> i.e. if a new directory ../new gets created on Source, I want it get
> created on Target. If later, files are added to that directory, I dont
> want to copy those files.

ignore my other posts, they have a fatal mistake in them. Here's a solution
using GNU tar:

tar cf - --no-recursion $(find . -type d) | ssh remote 'cd tmp && cat | tar
xf -'

(and this one i tested before posting ;)

--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.

 
 
 

Copying only directory structure

Post by Joerg Schilli » Sat, 21 Dec 2002 01:37:15





>> tar cf foo.tar $(find . -type d)
>> mv foo.tar /someplace
>> cd /someplace
>> tar xf foo.tar

>Or, to send them to another machine:


>xf -'

This will not work as tar will descend directories....

Use "star". It has a -D option to supress directory descending
and which doesn't descnd dirs if the filenames are in a "list" file

find . -type d -print | star -c list=- > out.tar

ftp://ftp.berlios.de/pub/star/alpha/

--



URL:  http://www.fokus.fhd.de/usr/schilling    ftp://ftp.berlios.de/pub/schily

 
 
 

Copying only directory structure

Post by Darren Dunha » Sat, 21 Dec 2002 01:44:38



> I want to maintain the directory structure (not the contents of the
> directory) in sync across 2 machines. How can I do this?
> rdist seems to work fine for copying entire directory trees but I am not
> interested in the contents of the directories, just the directory itself.
> i.e. if a new directory ../new gets created on Source, I want it get created
> on Target. If later, files are added to that directory, I dont want to copy
> those files.

I'd use rsync.

rsync -a --include "*/" --exclude "*" source/ target

The include includes all directories, the exclude excludes all files not
previously included.

--

Unix System Administrator                    Taos - The SysAdmin Company
Got some Dr Pepper?                           San Francisco, CA bay area
         < This line left intentionally blank to confuse you. >

 
 
 

Copying only directory structure

Post by David Walli » Sat, 21 Dec 2002 03:13:40



> I want to maintain the directory structure (not the contents of the
> directory) in sync across 2 machines. How can I do this?

> rdist seems to work fine for copying entire directory trees but I am not
> interested in the contents of the directories, just the directory itself.

> i.e. if a new directory ../new gets created on Source, I want it get created
> on Target. If later, files are added to that directory, I dont want to copy
> those files.

find <src> -type d -print | (cd <dest>; xargs mkdir)

--
David Wallis

 
 
 

Copying only directory structure

Post by Barry Margoli » Sat, 21 Dec 2002 04:20:43





>> I want to maintain the directory structure (not the contents of the
>> directory) in sync across 2 machines. How can I do this?

>> rdist seems to work fine for copying entire directory trees but I am not
>> interested in the contents of the directories, just the directory itself.

>> i.e. if a new directory ../new gets created on Source, I want it get created
>> on Target. If later, files are added to that directory, I dont want to copy
>> those files.

>find <src> -type d -print | (cd <dest>; xargs mkdir)

Except you need to throw in an rsh or ssh:

find <src> -type d -print | ssh <remote> "cd <dest>; xargs mkdir"

--

Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

1. copying a directory structure with a particular file in directories below

Hello,
I need some help/advise on how to copy a directory structure with a
particular file in directories below the start directory.

Let's say I have many text files [*.txt] with many data files and other
files [*.data, *.*]
The directory I want to copy across to another area with only the text
files but which also retains the directory structure.

i.e.,

[root_directory]
 |__[data]
       |__[directory_1]
       |__[direcotry_2]
       |    |__[directory_2.1]
       |
       |__[directory_3]
       |
       |__[directory_N]

I want to copy the directory [data] to another area with just the *.txt
files but retain the directory structure.

I tried to do this

cp -r `find /[root_directory]/[data] -name "*.txt"` .

NOTE: The above when I include the square brackets is meant to
represent the full name of the
directory and is not to be confused with anything else.

cp -r `find /root_directory/data/ -name "*.txt"` .

When doing this, all I get is the *.txt files without the directory
structure. If the *.txt files have the same name it will cause
problems. So I can copy the directory structure it would be great.

I hope you can understand the issue/problem statement from my
explanation.
If you have any questions please ask me.

Thanks,
ROuNIN

2. Wierd SIGXCPU problem (cpu time limit exceeded)

3. HELP:2 ques: Copying large directory structure and mkfs

4. DNS without named

5. Bash shell script to sort files by date and copy to directory structure

6. cdwriter software?

7. Copy entire directory structure from one system to another (Solaris v2.5.1)

8. Help! Save me from fsck!...

9. Copying a directory structure from Unix -> NT via FTP

10. copying directory structure only

11. How do I copy a whole structure of directory ?

12. automatically copy and rename directory structure

13. using find and copy to copy directories