WezM.net Menu

How to create an empty tar file

Published on Thu, 27 March 2008

Strangely enough I had the need to determine if it was possible to create a valid but empty tar file. Turns out it is. The method varies slightly depending on your flavour of tar program, here’s how to do it on three of the big ones:

BSD tar cvf empty.tar --from-file /dev/null

GNU (Linux) tar cvf empty.tar --files-from /dev/null

Solaris tar cvf empty.tar -I /dev/null

Now if you wondering why I would want this, here’s the explanation. I work on a batch processing system that processes files delivered from other systems. In some cases its necessary to wait for a file to arrive but give up after some time. In order to give up we copy an empty file (automatically) so that the processing proceeds normally. Ordinarily this is an empty plain text file but for the system I’m working on I’m expecting a tar file, hence the need for an empty one.

Something to Add?

Contact me by email, App.net or Twitter if you have a comment, correction or just want to get in touch.