↑ ↓ select, Enter open, Esc close

Extract a tar.gz archive without overwriting files

Caution: This command changes the system. Understand what it does before you run it.

Adjust the values, the command updates live
user@server
mkdir -p /tmp/restore && tar -xzf /var/backups/example.com-httpdocs-2026-10-09.tar.gz -C /tmp/restore --skip-old-files

Creates the target directory if needed and extracts the archive there. --skip-old-files leaves existing files untouched, so an accidentally wrong target does not overwrite data. The safest choice is an empty directory from which you then copy back selectively.

Note: Owners from the archive are only restored when extracting as root, otherwise all files belong to the user running the command.

Also searched as

  • extract tar.gz to directory
  • restore backup from tar.gz
  • extract archive without overwriting
  • tar skip existing files

Related one-liners

All in rsync and backup

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.