How do I exclude absolute paths for tar?

前端 未结 4 1342
耶瑟儿~
耶瑟儿~ 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:41

    If you want to remove the first n leading components of the file name, you need strip-components. So in your case, on extraction, do

    tar xvf tarname.tar --strip-components=2
    

    The man page has a list of tar's many options, including this one. Some earlier versions of tar use --strip-path for this operation instead.

提交回复
热议问题