Differences between revisions 1 and 6 (spanning 5 versions)
Revision 1 as of 2007-05-02 22:54:40
Size: 558
Editor: redondos
Comment:
Revision 6 as of 2008-11-28 14:16:01
Size: 983
Editor: 89
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
[[Anchor(faq10)]] <<Anchor(faq10)>>
Line 3: Line 4:
With the {{{cpio}}} program:
{{{
    cd "$srcdir"
    find . -type d -print | cpio -pdumv "$dstdir"
Probably, the most easy to understand one, and the second "find" line does the same with files, creating their "dummy" copies, being empty, but having the original's modification and access times:

 . {{{
 cd "$srcdir"
 find . -type d -exec mkdir -p "$destination"/{} \;
 find . -type f -exec touch -r {} "$destination"/{} \;
Line 9: Line 12:
or with GNU-{{{tar}}}, and less obscure syntax: With the {{{cpio}}} program:
Line 11: Line 14:
{{{
    cd "$srcdir"
    find . -type d -print | tar c --files-from - --no-recursion | tar x --directory "$dstdir"
 . {{{
 cd "$srcdir"
 find . -type d -print | cpio -pdumv "$dstdir"
Line 16: Line 19:
This creates a list of directory names with find, non-recursively adds just the directories to an archive, and pipes it to a second tar instance to extract it at the target location. or with GNU {{{tar}}}, and more verbose syntax:

 . {{{
 cd "$srcdir"
 find . -type d -print | tar c --files-from - --no-recursion |
   tar x --directory "$dstdir"
}}}

This creates a list of directory names with {{{find}}}, non-recursively adds just the directories to an archive, and pipes it to a second {{{tar}}} instance to extract it at the target location.

 . ''There should be a way to do this with `pax` too....'' - GreyCat

How can I recreate a directory structure, without the files?

Probably, the most easy to understand one, and the second "find" line does the same with files, creating their "dummy" copies, being empty, but having the original's modification and access times:

  •  cd "$srcdir"
     find . -type d -exec mkdir -p "$destination"/{} \;
     find . -type f -exec touch -r {} "$destination"/{} \;

With the cpio program:

  •  cd "$srcdir"
     find . -type d -print | cpio -pdumv "$dstdir"

or with GNU tar, and more verbose syntax:

  •  cd "$srcdir"
     find . -type d -print | tar c --files-from - --no-recursion |
       tar x --directory "$dstdir"

This creates a list of directory names with find, non-recursively adds just the directories to an archive, and pipes it to a second tar instance to extract it at the target location.

  • There should be a way to do this with pax too.... - GreyCat

BashFAQ/010 (last edited 2023-09-22 06:29:48 by StephaneChazelas)