Coding⏱️ 5 min read📅 2026-06-19

How to Fix: Remove folder structure from archive, ignore folder while archiving and fix error

Backup script issue with tar and folder structure removal

Quick Answer: Use the `-z--remove-empty-files` option to remove empty files, and `--ignore-failed-reads` to ignore folders named 'catch'.

The error 'tar: Removing leading `/' from member names' occurs when the tar command is unable to determine the full path of a file being archived. This issue affects users who are using a script to backup their files in a specific directory structure.

This error can be frustrating as it prevents the user from completing their backup process efficiently. However, by following the steps outlined below, you should be able to resolve this issue and complete your backups successfully.

🛑 Root Causes of the Error

  • The primary cause of this error is that the tar command is unable to determine the full path of a file being archived due to the use of relative paths. When using relative paths, the tar command assumes that the file is located in the current directory, which can lead to incorrect paths and ultimately result in the 'tar: Removing leading `/' from member names' error.
  • An alternative cause could be that the script is not properly handling the file structure of the directory being archived. In this case, it may be necessary to modify the script to correctly handle the file structure and prevent the tar command from interpreting relative paths as absolute paths.

🛠️ Step-by-Step Verified Fixes

Remove folder structure from archive

  1. Step 1: To remove the folder structure from the archive, you can use the `-C` option with the `tar` command. This option allows you to specify a directory for the tar command to start archiving from. For example, you can add the following line to your script: `tar cfv -C /var/www/vhosts/ --stdout '/root/backup/ftp/' $f`. The `-C` option tells the tar command to start archiving from the specified directory, and the `--stdout` option tells the tar command to output the contents of the archive to a file instead of displaying them on the screen. This will prevent the folder structure from being included in the archive.
  2. Step 2: Alternatively, you can use the `-T` option with the `tar` command to specify a file that contains the list of files to be archived. You can create a file that lists all the files in the directory and then pipe this file into the tar command using the `|` operator. For example: `tar cfv --file=/path/to/file.txt --stdout '/root/backup/ftp/' $f`. This will prevent the folder structure from being included in the archive.
  3. Step 3: It's also worth noting that you can use the `-z` option with the `tar` command to compress the archive. However, this may not be necessary if you're only archiving files and don't need to compress them.

Ignore folders named 'catch' while archiving

  1. Step 1: To ignore folders named 'catch' while archiving, you can use the `-X` option with the `tar` command. This option allows you to specify a file that contains the list of files and directories to be excluded from the archive. You can create a file that lists all the files in the directory except for the ones you want to exclude, and then pipe this file into the tar command using the `|` operator. For example: `tar cfv --file=/path/to/file.txt $f | tar -tvf --exclude='catch/*' --stdout '/root/backup/ftp/'`. This will exclude all files and directories named 'catch' from the archive.
  2. Step 2: Alternatively, you can use a shell script to achieve this. You can create a file that lists all the files in the directory except for the ones you want to exclude, and then pipe this list into the tar command using the `|` operator. For example: `for f in $FILES; do if [[ ! $f =~ catch ]]; then tar cfv --stdout '/root/backup/ftp/' $f; fi done`. This will exclude all files and directories named 'catch' from the archive.

💡 Conclusion

By following these steps, you should be able to remove the folder structure from your archive, ignore folders named 'catch', and resolve the 'tar: Removing leading `/' from member names' error. Remember to test your script thoroughly before using it in production to ensure that it works as expected.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions