/errors/tar/removing-leading-slash-from-member-names
tar: Removing leading `/' from member names
- tool
- tar
- exit code
- 0
- versions
- GNU tar 1.x
- os
- linux, macos, windows
GNU tar prints tar: Removing leading `/' from member names (in some locales with typographic quotes instead) when you archive an absolute path. It is a notice, not an error: tar still creates the archive and exits with status 0, but stores etc/nginx/... instead of /etc/nginx/..., so extracting it later recreates the files under the current directory instead of overwriting the system's. Use -C to archive a relative path and the message disappears.
Reproduce it
mkdir -p data/app && echo x > data/app/config.ini
tar -czf backup.tgz "$PWD/data/app"
echo "exit status: $?"
tar -tzf backup.tgz | sed 's#^.*/data/#.../data/#'Output
tar: Removing leading `/' from member names exit status: 0 .../data/app/ .../data/app/config.ini
The member names have no leading /.
The same notice appears in scripts that never type a /: "$PWD/data", "$HOME/app" or a variable holding an absolute directory all expand to absolute paths before tar sees them.
Extracting an archive with absolute names
If someone created the archive with -P, GNU tar strips the slash again when you extract without -P, prints the same line, and puts the files below the current directory:
mkdir -p data && echo x > data/config.ini
tar -czPf abs.tgz "$PWD/data"
mkdir restore && cd restore
tar -xzf ../abs.tgz
echo "exit status: $?"
find . -name config.ini | grep -c config.iniOutput
tar: Removing leading `/' from member names exit status: 0 1
Fix: archive a relative path with -C
mkdir -p data/app && echo x > data/app/config.ini
tar -czf backup.tgz -C "$PWD/data" app
tar -tzf backup.tgzOutput
app/ app/config.ini
-C DIR makes tar change into DIR before reading the following names, so the archive holds app/.... When restoring, choose the destination explicitly: tar -xzf backup.tgz -C /path/to/restore.
Keep absolute paths with -P
-P (--absolute-names) stores the leading / and, on extraction, writes to the absolute paths. Only use it for archives you created yourself.
bsdtar, macOS and Windows
bsdtar (the tar on macOS and the tar.exe shipped with Windows 10 and 11) behaves the same way and also strips leading / by default. On Windows it removes a drive letter instead and prints tar.exe: Removing leading drive letter from member names. Both accept -P to keep absolute names.
| Command | Stored member names | Notice |
|---|---|---|
| tar -czf b.tgz /etc/nginx | etc/nginx/... | Yes |
| tar -czf b.tgz -C / etc/nginx | etc/nginx/... | No |
| tar -czf b.tgz -C /etc nginx | nginx/... | No |
| tar -czPf b.tgz /etc/nginx | /etc/nginx/... | No, absolute names kept |
Silence it in scripts
If the absolute paths are intended, redirect only this notice and keep real errors visible:
tar -czf backup.tgz /etc/nginx 2> >(grep -v 'Removing leading' >&2)FAQ
Is the archive broken when tar prints Removing leading / from member names?
No. The message goes to stderr, tar exits with status 0 and the archive contains every file; only the leading slash of each name is gone, so the paths are relative.
Where do the files go when I extract such an archive?
Under the directory you extract into. An archive of /etc/nginx extracted in /tmp/restore produces /tmp/restore/etc/nginx; use -C to choose that directory.
Why does my cron backup email me this message every night?
cron mails anything written to stderr. Archive with -C / and a relative path, which removes the notice at its source, instead of discarding all of tar's stderr and hiding real errors.