Basically I want to create a tar image of a folder structure, but not store the actual file contents. So when I untar the file I want to get the original folders, filenames, timestamps, etc.., but all zero-length files instead of the original file contents.

The intent here is to capture the folder structure of a gigantic folder (gigabytes in size) without creating a multi-gigabyte tar file.

Thanks in advance.

  • I should mention I need this on stock RHEL 6.7
    – BrandonL
    Aug 21, 2020 at 14:03

2 Answers 2


If your cp is powerful enough, you can do this:

cp -a --attributes-only olddir newdir

Where newdir does not exist (yet) and --attributes-only means

Copy only the specified attributes of the source file to the destination. […]

This won't copy data; regular files in newdir will be of zero size. Note you need to be root to replicate all the attributes (e.g. ownership), so maybe you need sudo cp …. Instead of -a you can use more specific options to only replicate the attributes you really need.

Anyway, after you create newdir containing empty files, simply tar this directory instead of olddir.

  • Thanks, I like this idea but it seems my cp doesn't support --attributes-only :(
    – BrandonL
    Aug 21, 2020 at 14:03

star supports this since 18 years.... try:

star -c -dump -meta ... | star -tv

This lists all entries as 'm'eta type files...

star -c -dump -meta ... | star -C todir -xmeta

extracts all files a 0 byte sized files.

star -c -dump -meta ... | star -C todir -xmeta -force-hole

extracts all files as files of the original size with no data (sparse file).

star is part of the schilytools.

  • Thanks, but running external tools is not an option unfortunately.
    – BrandonL
    Aug 21, 2020 at 14:05
  • Mmm gtar is an external tool as well. star is what I use since 38 years without problems. BTW: star is on SUSE since it is used to implement pax via a symlink to star.
    – schily
    Aug 21, 2020 at 14:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .