_                    _
  ___ | |__   __ _ _______ | |_
 / _ \| '_ \ / _` |_  / _ \| __|
| (_) | | | | (_| |/ / (_) | |_
 \___/|_| |_|\__,_/___\___/ \__|

tararchive tool: usage

tar -zvcf TAR_FILE DIRECTORY
tar -zvcf TAR_FILE DIRECTORY/*
tar -zvxd TAR_FILE

back to top

-c : compress
-x : extract
-v : verbose
-f TAR_FILE : use specified TAR_FILE
-z : use gzip compression
-j : use bzip2 compression
-t : list archive contents
-C DIR : cd to directory
The options can be collapsed but f needs to be the last option. Eg.:
tar -zvxf tar_file

  • Filename(s) can be specified to extract only specified file(s).
  • The full path inside the tar file needs to be specified.
$ tar -ztf tar_file
d1/file1
d2/file2
$ tar -zxf tar_file d1/file1

  • Compress the contents of dir_to_compress located in parent_directory into dir.tar.gz.
    $ pwd
    cur_directory
    $ ls parent_directory
    dir_to_compress
    $ tar -C parent_directory -zcf dir.tar.gz dir_to_compress
    $ ls
    parent_directory dir.tar.gz
  • Extract the contents of TAR_FILE into EXTRACT_DIR.
    $ tar -C EXTRACT_DIR -zxf TAR_FILE

back to top

- OpenBSD manpages: tar(1)

back to top

ohazot | about | ohazot.com <admin@ohazot.com>

OpenBSD 7.7 linux| Created:2025-10-03|Updated:2025-10-07|