commands

tar — bundle and restore files

GNU tar creates, lists or extracts archives; -z selects gzip, -C changes directory. List before extracting trusted archives into an empty private directory. Successful status does not establish safety. Example assumes a fresh archive lab fixture with new output names.

Formal Syntax & Structure

linux syntaxlinux
tar -{c|t|x}[z]f ARCHIVE [-C DIRECTORY] [MEMBER...]

Parameters & Attributes

NameTypeDescription
-coptioncreate
-toptionlist
-xoptionextract
-zoptiongzip
-foptionTakes an archive filename or - for the relevant standard stream.
-CoptionTakes a directory; changes the working directory for subsequent operands.
MEMBERoperandInput path(s) for creation; optional selection of archived members for listing or extraction. Supply explicit input paths when creating.
ARCHIVEoperandNew archive path for creation or existing trusted archive for listing/extraction.

Return Value

exit status and output

GNU tar creates, lists or extracts archives; -z selects gzip, -C changes directory. List before extracting trusted archives into an empty private directory. Successful status does not establish safety.

Working Example

Example Snippetlinux
tar -cf notes.tar notes.txt report.txttar -tf notes.tar
Linux Reference