tar: Removing leading `/' from member names

  • [email protected] # tar fcz bkup.tar.gz /home/foo/
    tar: Removing leading `/' from member names
    

    How can I solve this problem and keep the / on file names ?

    What exactly is not working as expected?

    It is not a problem. You **do not want** leading slashes in a tar archive. Seriously. If you want to extract an archive to your system root, specify `-C /` when extracting it.

  • Barmar

    Barmar Correct answer

    8 years ago

    Use the --absolute-names or -P option to disable this feature.

    tar fczP bkup.tar.gz /home/foo/
    
    tar fcz bkup.tar.gz --absolute-names /home/foo
    

    This is the correct answer, but be aware, that **in most cases, this is not what you want**, cause it results in an archive that extracts in complete paths!

    Using the `-C /` option as described in @Marcus' answer will git rid of the STDERR message if that is your primary goal.

    As @rubo77 commented, usually this is not the expected result of the command.

    Most of the time this is not what a user wants, simply because most of them don't read the manual until they need to (ain't nobody got time for that). So, it would be wise to, at least, expand your answer, warning people not to do this unless they are absolutely sure they understand what's the effect of it. Especially being accepted as an answer.

    @MladenB. `tar` also removes the leading slash by default when extracting. So even if you use this option when creating the archive, it won't be a problem unless the user also uses it when extracting.

    great, why not give an example though? where do these commands go? at the end? the beginning? in between?

    @Toskan Examples added

    Archives with absolute locations are a security risk. Attackers could use such archives to trick users into installing files in critical system locations.

    @A.B. That assumes you're making the archive for public distribution. If you're doing it for an internal backup, it's not as much of a concern.

    @A.B. And your point has already been made in Mark Adler's answer.

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM