How to overcome tar: Removing leading `/' from member names
I am trying to run this command in Linux:
tar zcvf ABCD.tar.gz -T Files.txt
and I am getting the following error:
Error: tar: Removing leading `/' from member names
Based on Find /SED to convert absolute path to relative path within a single line tar statement for crontab, I tried this command:
tar -C / -zcvf ABCD.tar.gz -T Files.txt
but I am still getting the same error message.
This is a feature!
If the slash
/ prefix was included in the archive during compression and extraction, it means that an attacker would just have to convince you to extract the file to overwite a sensitive file (like
It isn’t actually an error message, more an information.
If you really want to suppress it, change directory to the parent directory and use relative names:
tar -zcvf path/to/files
tar -zcvf /path/to/files
In your case, I suppose the files names in the
-T Files.txt are absolute location.
In GNU tar, if you want to keep the slashes in front of the file names, the option you need is:
Don't strip leading slashes from file names when creating archives.
tar zcvf ABCD.tar.gz -P -T Files.txt.
The slashes would probably be removed when the archive is extracted, unless of course you use
-P there, too.
If, on the other hand, you want to remove the slashes, but without tar complaining, you’d need to do something like
sed s,^/,, files.txt | tar czf foo.tar.gz -C / -T -.
Another possible answer is that you really do want your archive to have pathnames that are safe to extract, and you want to strip the leading slash from the list of files you have.
In this case there is no option in
tar, but you can generate
tar-compatible files with
pax -s '#^/##' -wz < Files.txt > ABCD.tar.gz
-s '#^/##' applies a substitution pattern to the filenames as they are written to the archive. This one strips a leading