Extract archive

2 snippets across 2 stacks — Bash & Linux, Docker

SHBash & Linux

Extract a Tar Archive

SH · Archives & Compression
syntax
tar -xf archive.tar [-C directory]
example
tar -xzf backup_20260404.tar.gz -C /opt/restore/
tar -xf release.tar.bz2
tar -tf archive.tar.gz

Note -x extracts, -C specifies the target directory. tar auto-detects compression on modern systems, so -xf often works without specifying -z/-j/-J. -t lists contents without extracting (always do this first on untrusted archives). WARNING: Tar archives can contain absolute paths or ../ that overwrite files outside the target; use -t to inspect first.

DKDocker

ADD — Copy with Extras

DK · Dockerfile
syntax
ADD <src> <dest>
example
ADD app.tar.gz /app/
ADD https://example.com/config.json /app/config.json

Note ADD can auto-extract tar archives and fetch URLs. However, COPY is preferred for simple file copies because ADD's extra behavior can be surprising. Using ADD for URL downloads also defeats layer caching — use RUN curl instead for better control.