How can I pipe information into tar specifying the names of the file?
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.
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.
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With