9951 explained code solutions for 126 technologies


cli-tarHow can I fix an unexpected end of file error when compressing a file with tar and gzip?


An unexpected end of file error when compressing a file with tar and gzip can be fixed by using the --ignore-failed-read option. This option allows tar to ignore any unreadable files and continue processing the archive.

For example:

tar --ignore-failed-read -czf archive.tar.gz /path/to/files/

The command above will create an archive called archive.tar.gz which will contain all the files in /path/to/files/ directory.

The parts of the command are:

  • tar: the command to create archives
  • --ignore-failed-read: the option to ignore unreadable files
  • -czf: the options to create a gzip compressed tar archive
  • archive.tar.gz: the name of the archive
  • /path/to/files/: the path to the directory containing the files to be archived

For more information about the tar command, see GNU tar Manual.

Edit this code on GitHub