How to Fix “tar: removing leading `/’ from member names”?

The “tar” command utility compresses the files and extracts the gzip and other format files. Sometimes when this command is used to compress or extract the file, it generates the error on the screen of “tar: removing leading ‘/’ from member names” as the shell does not recognize the path. 

This post will find the reason behind the error “tar: removing leading ‘/’ from member name”, and the solutions are demonstrated. 

Reason: Archives With Absolute Locations Causes Security Risks

Sometimes when you are using the “tar” command utility with its option “cjf” to compress the file, it generates the error. The path where we want to extract the file starts with the “/”, so this error is generated:

$ tar cjf  /sqlite-autoconf-3390000.tar.gz /home/itslinux/Downloads/

In the above command, we are trying to extract the /sqlite-autoconf-3390000.tar.gz to the /home/itslinux/Downloads/ directory, and it has generated the error.

Solution 1: Change the Directory 

We can remove this error by using the “-C” option before the path starting with “/”. This option will change the directory by ignoring the error:

$ tar cjf  /sqlite-autoconf-3390000.tar.gz -C /home/itslinux/Downloads/

The error has been removed and navigates to the “sqlite” file. 

Note: It recommends you use the absolute name of the directories where the file is to be extracted.

Solution 2: Disable the Feature of Checking the Leading Character of the Path

Another option to remove this error is using the “-P” option. It will disable the feature of checking the leading character of the path and will run the command. For this, execute the “tar” command with the am additional “P” option as follows: 

$ tar Pcjf  <tar-file.gz> /home/itslinux/Downloads/

Or this can also be ignored by using the option “–absolute-names” as follows: 

$ tar cjf  <tar-file.gz> --absolute-names /home/itslinux/Downloads/

Conclusion

The error “tar: removing leading ‘/’ from member names” occurs because the archives with absolute path locations cause security risks, users can utilize the “-C” before the path. However, it can be ignored by using the “P” option with extraction parameters or the “–absolute-names” option. This post has demonstrated the reason and the solution to fix the error.

Over 500 Million Views on Our Blogs and YouTube! We’re inviting 10 businesses to partner with us and grow together. Click here to join us! ×