Differences between revisions 6 and 7
Revision 6 as of 2008-11-28 14:16:01
Size: 983
Editor: 89
Comment:
Revision 7 as of 2008-11-28 14:21:41
Size: 1351
Editor: Lhunath
Comment: portability warning.
Deletions are marked like this. Additions are marked like this.
Line 4: Line 4:
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:
With GNU find(1), the following is likely to be the simplest solution. The second find statement recreates the entire file tree with empty "dummy" files (empty files with the same timestamps). (Feel free to replace the `\;` by `+` if your find supports it to reduce the number of `mkdir`/`touch` forks, and thus increase the performance of the command).
Line 11: Line 12:

Be aware, though, that according to POSIX, the behaviour of find(1) is unspecified when {} not standing alone in an argument. Because of this, the following solutions are more portable than the previous.

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

With GNU find(1), the following is likely to be the simplest solution. The second find statement recreates the entire file tree with empty "dummy" files (empty files with the same timestamps). (Feel free to replace the \; by + if your find supports it to reduce the number of mkdir/touch forks, and thus increase the performance of the command).

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

Be aware, though, that according to POSIX, the behaviour of find(1) is unspecified when {} not standing alone in an argument. Because of this, the following solutions are more portable than the previous.

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)