How do I exclude absolute paths for tar?

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

    If you don't know how many components are in the path, you could try this:

    DIR_TO_PACK=/www/path/
    cd $DIR_TO_PACK/..
    tar -cf tarname.tar $(basename $DIR_TO_PACK)
    

提交回复
热议问题