linux tar create code example

Example 1: create tar gz file from directory

tar -czf tarball.tar.gz my_directory/

Example 2: how to tar linux

tar -zcvf file.tar.gz /path/to/dir/

Example 3: how to tar a file

tar -czvf name-of-archive.tar.gz /path/to/directory-or-file

Example 4: linux tar command

Create a new tar archive.
$ tar cvf archive_name.tar dirname/

Extract from an existing tar archive.
$ tar xvf archive_name.tar

View an existing tar archive.
$ tar tvf archive_name.tar