Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I build a tar from stdin?

Tags:

tar

How can I pipe information into tar specifying the names of the file?

like image 936
Kristopher Ives Avatar asked Apr 08 '10 06:04

Kristopher Ives


People also ask

Can tar read from stdin?

tar cannot read in file data from stdin for creating an archive, since then tar will have no way of knowing what a file is - where one begins or ends, what its path and metadata is.

How do you create a tar in Python?

Use the tarfile module to create a zip archive of a directory. Walk the directory tree using os. walk and add all the files in it recursively.


1 Answers

Something like:

tar cfz foo.tgz --files-from=- 

But keep in mind that this won't work for all possible filenames; you should consider the --null option and feed tar from find -print0. (The xargs example won't quite work for large file lists because it will spawn multiple tar commands.)

like image 144
geekosaur Avatar answered Sep 28 '22 22:09

geekosaur



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!