CmdKeys LogoCommand Quiz

Tar Command Practice

tar packs many files into one archive; -z/-j/-J only choose the compressor. This track drills create, extract, list, and append/update — GNU clustered packs like -czvf, not gzip(1) or zip. The same commands show up in release tarballs and backup scripts.

Command Reference

extract

CommandDescription
tar -xf <archive>Extract an archive into the current directory.
tar -xvf <archive>Extract an archive into the current directory and list each member.
tar -xzf <archive>Extract a gzip-compressed archive using the gzip filter explicitly.
tar -xf <archive> -C <dir>Extract an archive into a chosen directory.
tar -xf <archive> --strip-components=<num>Extract an archive after dropping the first N path components from each member.
tar -xf <archive> --wildcards "<pattern>"Extract only members whose names match a glob.

create

CommandDescription
tar -czvf <archive> <file>Create a gzip-compressed archive and list each member as it is added.
tar -cf <archive> <file>Create an uncompressed tar archive from the given files.
tar -czf <archive> <file>Create a gzip-compressed archive from the given files.
tar -cjf <archive> <file>Create a bzip2-compressed archive from the given files.
tar -cJf <archive> <file>Create an xz-compressed archive from the given files.
tar -caf <archive> <file>Create an archive and pick the compressor from the archive filename suffix.
tar -czf <archive> -C <dir> .Create a gzip archive of a directory's contents using relative paths.

list

CommandDescription
tar -tf <archive>List member names in an archive without extracting.
tar -tvf <archive>List archive members with size and timestamp details.
tar -tzf <archive>List members of a gzip-compressed archive using the gzip filter.
tar -tf <archive> --wildcards "<pattern>"List only members whose names match a glob.

modify

CommandDescription
tar -rf <archive> <file>Append files to the end of an existing uncompressed archive.
tar --delete -f <archive> <name>Remove a named member from an uncompressed archive.
tar -df <archive>Compare archive members against the files on disk.
tar -uf <archive> <file>Append files that are newer than the copy already in the archive.

Key Use Cases

  • Create a gzip tarball of a project directory
  • Extract an archive into a chosen directory with -C
  • List members before you unpack anything
  • Create an xz archive from the file extension with -a
  • Append or update members in an existing uncompressed archive
  • Extract only files matching a glob

Frequently Asked Questions

Is tar -czf the same as tar -czvf?

No. -v lists each member as tar works. This track treats them as different commands. -czvf and -cvzf are the same flags in another order.

Do I need -z to extract a .tar.gz?

GNU tar usually detects gzip on -xf. -xzf still forces the gzip filter. Both appear here; type the flags the prompt asks for.

Why isn't this the same as gzip or zip?

gzip compresses one stream. zip is another format. tar is the archiver; compression is an optional filter (-z/-j/-J/-a).

Where does -C apply?

-C changes directory before the following arguments. tar -czf out.tar.gz -C src . packs the contents of src, not the src directory name.

Ready to master Tar commands?

Test your muscle memory with our spaced-repetition quiz system. Free forever.

Start Practice Now →