root@server # tar fcz bkup.tar.gz /home/foo/
tar: Removing leading `/' from thành viên names
How can I solve this problem and keep the /
on tệp tin names ?
Renan
17.2k8 gold badges72 silver badges91 bronze badges
asked Dec 23, 2012 at 12:47
superusersuperuser
2,4212 gold badges14 silver badges6 bronze badges
3
If you want to tát get rid of "Removing leading `/' from thành viên names" being printed to tát STDERR, but still want to tát leave off those leading slashes as tar wisely does by mặc định, I saw an excellent solution here by commenter timsoft.
The solution involves using -C option to tát change directory to tát the root (/), then specifying the tệp tin tree to tát archive without a leading slash, because now you only need a relative path. This does the same thing as a normal tar create command, but no stripping is needed:
tar fcz bkup.tar.gz -C / home/foo/
answered Jan 18, 2013 at 15:33
MarcusMarcus
1,5711 gold badge8 silver badges4 bronze badges
5
Use the --absolute-names
or -P
option to tát disable this feature.
tar fczP bkup.tar.gz /home/foo
tar fcz bkup.tar.gz --absolute-names /home/foo
alper
5072 gold badges8 silver badges25 bronze badges
answered Dec 23, 2012 at 12:57
BarmarBarmar
10.2k1 gold badge20 silver badges29 bronze badges
7
That's actually a feature, not a problem. Archives with absolute locations are a security risk. Attackers could use such archives to tát trick users into installing files in critical system locations.
Yes, you could use -P
. But what's wrong with allowing tar to tát remove the forward slash, and simply requiring the user of the archive to tát explicitly tự the extraction in the root directory? Then they're consciously impacting critical system locations, and can't tự it by accident.
answered Dec 23, 2012 at 15:28
Mark AdlerMark Adler
2,0154 gold badges15 silver badges15 bronze badges
2
One month late, but I found the most appropriate solution for my case (in a shell script) is to tát go to tát the parent directory and execute the command there.
cd /var/www/
tar -czf mysite.gz mysite
Instead of:
tar -czf /var/www/mysite.gz /var/www/mysite
answered May 24, năm ngoái at 6:52
amdamd
6775 silver badges3 bronze badges
4
This is how I did it by using brute force method: 2>&1 | grep -v "Removing leading"
.
For example:
tar -cf "$BKUPDIR/${BKUPFILE}.tar" --overwrite --exclude '.*' --one-file-system "$SRCDIR" 2>&1 | grep -v "Removing leading"
kenorb
21.6k18 gold badges148 silver badges169 bronze badges
answered Aug 23, 2013 at 1:00
bjackflybjackfly
1991 silver badge3 bronze badges
5
Try to tát use -C
for path only which would prevent compressing with complete paths:
root@server # tar fcz bkup.tar.gz -C /home/ foo/
answered Jul 25, 2017 at 10:35
I solved this problem with:
cd /home/foo && tar czf ~/backup.tar.gz .
that way you aren't trying to tát put absolute paths into the tar archive in the first place. If you want untar it at the root of the tệp tin system you just
cd / && tar xzf backupt.tar.gz
after transferring it.
answered Jul 21, 2017 at 15:44
JamesJames
311 bronze badge
The path of the archive when specified causes this informational message, you can tự the following to tát resolve it:
tar -zvcf /tmp/mike.tar.gz -P /tmp/mike
or
tar -zvcf mike.tar.gz -P /tmp/mike
or
tar -zvcf mike.tar.gz /tmp/mike
Note: it is not an error, just informational.
answered Jun 5, 2020 at 21:20
Mike QMike Q
1595 bronze badges
its not a feature, its a bug. removing absolute paths creates an unextractable archive if path data gets fooey somehow. tar spits out the error and refuses to tát extract anything. better to tát use tardy to tát filter the path first.
answered Aug 21, 2020 at 8:47
1
You must log in to tát answer this question.
Not the answer you're looking for? Browse other questions tagged
.
Not the answer you're looking for? Browse other questions tagged
.