Skip to content

/errors/tar/removing-leading-slash-from-member-names

tar: Removing leading `/' from member names

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · tar (GNU tar) 1.35updated
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

bash
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:

bash
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.ini

Output

tar: Removing leading `/' from member names
exit status: 0
1

Fix: archive a relative path with -C

bash
mkdir -p data/app && echo x > data/app/config.ini
tar -czf backup.tgz -C "$PWD/data" app
tar -tzf backup.tgz

Output

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.

CommandStored member namesNotice
tar -czf b.tgz /etc/nginxetc/nginx/...Yes
tar -czf b.tgz -C / etc/nginxetc/nginx/...No
tar -czf b.tgz -C /etc nginxnginx/...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:

bash
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.

Sources