-1

This question already has an answer here:

My command is totally different when you compare with that command

I am trying to run below command in linux

Command: tar zcvf ABCD.tar.gz -T Files.txt

and i am getting an error message as

Error: tar: Removing leading `/' from member names

I tried below command but still i am getting same error message (https://stackoverflow.com/questions/41641269/find-sed-to-convert-absolute-path-to-relative-path-within-a-single-line-tar-sta)

tar -C / -zcvf ABCD.tar.gz -T Files.txt

marked as duplicate by roaima, Christopher, Cyrus, Tomasz, muru Oct 12 at 19:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • @ I am not sure why negative votes are given , i can show that for this issue we dont have an answer.. I need an valid answer from the person who has done the negative vote – Arya Oct 9 at 19:03
  • @roaima. Command is totally different I am using "-T" to get all the files from a text file. Entire command is different. – Arya Oct 9 at 19:50
  • @roaima.. May be issue is same but both the commands are totally different. – Arya Oct 9 at 19:50
  • @roaima. This is not an duplicate question – Arya Oct 9 at 19:53
  • 2
    Do you want to store the files in the archive with their leading / (unwise), or somehow strip it off so that the files have relative pathnames (safer)? – roaima Oct 9 at 20:08
3

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 /etc/shadow).

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:

cd /
tar -zcvf path/to/files

Rather than

tar -zcvf /path/to/files

In your case, I suppose the files names in the -T Files.txt are absolute location.

  • @Hi Piat. Thanks a lot for the reply. Actually all the list of file names are available in Files.txt . So how can i get rid of this issue – Arya Oct 9 at 19:15
3

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.

pax -s '#^/##' -wz < Files.txt > ABCD.tar.gz

The -s '#^/##' applies a substitution pattern to the filenames as they are written to the archive. This one strips a leading /.

2

In GNU tar, if you want to keep the slashes in front of the file names, the option you need is:

   -P, --absolute-names
          Don't strip leading slashes from file names when creating archives.

So, 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 -.

  • @Solution worked. Is there any way without getting parent directory folder names and have only files inside the tar.gz file ? ( without using cd dir and do tar ) – Arya Oct 10 at 2:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.