How can I build a tar from stdin?

后端 未结 6 918
攒了一身酷
攒了一身酷 2020-12-04 16:20

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

6条回答
  •  广开言路
    2020-12-04 16:42

    Extending geekosaur answer:

    find /directory | tar -cf archive.tar -T -
    

    You can use stdin with the -T option.

    Note that if you filter files using some condition (e.g. -name option) in general you need to exclude directories in the pipe, otherwise tar will process all their content, that is not what you want. So, use:

    find /directory -type f -name "mypattern" | tar -cf archive.tar -T -
    

    If you don't use -type, all the content of directories matching "mypattern" will be added !

提交回复
热议问题