How do I exclude absolute paths for tar?

前端 未结 4 1349
耶瑟儿~
耶瑟儿~ 2021-02-03 19:27

I am running a PHP script that gets me the absolute paths of files I want to tar up. This is the syntax I have:

tar -cf tarname.tar -C /www/path/path/file1.txt /         


        
4条回答
  •  悲哀的现实
    2021-02-03 19:42

    For me the following works the best:

    tar xvf some.tar --transform 's?.*/??g'
    

    --transform argument is a replacement regex for sed, to which every extracted filepath is fed. Unlike --strip-components, it will remove all path information, not just fixed number of components.

提交回复
热议问题