When executing tar commands with absolute paths, you'll often encounter this informational message:
tar -czvf /var/backups/svn.tgz /var/svn/*
# Outputs: tar: Removing leading /' from member names
This isn't an error - it's tar's way of telling you it's normalizing paths by stripping the leading slash to create relative paths within the archive.
In automated environments like cron jobs, we typically want:
- Clean logs containing only actionable errors
- Predictable behavior when parsing output
- No false positives in monitoring systems
Method 1: Change Directory First
The most elegant solution uses tar's -C
option:
tar -czvf /var/backups/svn.tgz -C /var/svn .
This works because:
-C /var/svn
changes working directory before archiving- The
.
refers to current directory contents - No absolute paths means no warning
Method 2: Explicit Path Handling
For more control over archived paths:
tar -czvf /var/backups/svn.tgz --transform='s,^var/svn/,,' /var/svn/*
The --transform
option lets you modify paths with sed expressions.
Method 3: Output Filtering
When you can't modify the tar command:
tar -czvf /var/backups/svn.tgz /var/svn/* 2>&1 | grep -v "Removing leading"
Here's a robust cron-ready solution:
#!/bin/bash
BACKUP_DIR="/var/backups"
SOURCE="/var/svn"
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
tar -czf "${BACKUP_DIR}/svn-${TIMESTAMP}.tgz" -C "${SOURCE}" . 2>/dev/null
Key improvements:
- Timestamps in filenames
- Silenced all non-error output
- Used proper variable quoting
For complex backup scenarios:
#!/bin/bash
# Archive with permissions and xattrs preserved
tar --xattrs --xattrs-include='*' \
-czf backup.tgz \
-C /source/path \
--exclude='*.tmp' \
--exclude='cache/*' .
Remember to test your backup and extraction process regularly!
When running tar commands in cron jobs or scripts, you might encounter this common warning:
tar -czvf /var/backups/svn.tgz /var/svn/*
Output:
tar: Removing leading /' from member names
This message appears because tar automatically removes the leading slash from absolute paths for security reasons (to prevent accidental overwrites of system files when extracting). While technically just a warning, it can clutter logs and trigger unnecessary alerts in monitoring systems.
The most elegant way to eliminate this warning is to use tar's -C option to change directory before archiving:
tar -czvf /var/backups/svn.tgz -C /var/svn .
This approach:
- Changes to the source directory first
- Archives the current directory (.)
- Preserves relative paths without leading slashes
If you prefer keeping your original command structure, consider these alternatives:
1. Redirecting stderr
tar -czvf /var/backups/svn.tgz /var/svn/* 2>&1 | grep -v "Removing leading"
2. Using --absolute-names (Not Recommended)
tar --absolute-names -czvf /var/backups/svn.tgz /var/svn/*
Warning: This disables the security feature - only use if you fully understand the implications.
Here's how to implement this properly in a cron job:
0 3 * * * /bin/tar -czvf /var/backups/svn.tgz -C /var/svn . >/dev/null 2>&1
Or with logging:
0 3 * * * /bin/tar -czvf /var/backups/svn.tgz -C /var/svn . > /var/log/backup.log 2>&1
- --warning=no-file-ignored: Suppress other non-critical warnings
- --exclude: Skip unwanted files
- --checkpoint: For large backups