10 Useful Tar Commands For Unix Users

command-line-blogImageTar is an amazing tool that it’s used by Linux users and system administrator on a daily basis. Tar can be used for compressing, backing up, and even encryption of files and directories. Moreover, tar Command provides many options which makes the command very flexible. In this “ten useful command” tutorial, I’m going to go over 10 basic and useful tar commands that every Linux user and System Administrator should know.

Tar command options covered here
-c compress
-v verbose
-z gz (more compression ratio)
-f filename of comressed file
-t list files

1- compressing a directory in gz format

tar -cvzf compress.tar.gz directory/

compressing a file or files in gz format

tar -cvzf compress.tar.gz file1 file2

2- Uncompressing a tar file

tar -xvzf compressed.tar.gz

3- Excluding directories from compressed file

tar -cvzf --exclude={dir1,dir2} -cvzf compressed.tar.gz directory/

4- performing incremental backups
this will backup files newer than filename

tar --newer filename -cvzf backup.tar.gz directory

5- listing content of compressed file
options: -t list files, and -z for tar.gz files

tar -ztvf compressed.tar.gz

for .tar files

tar -tvf compressed.tar

for tar.gz2 files

tar -jtvf compressed.tar.gz2

6- find a specific file inside a tar backup

tar -ztvf compressed.tar.gz | grep filename

7- extracting a file from compressed file

tar -zxvf compressed.tar.gz filename

8- extracting multiple files using wildcard
here we use wild card with the extension of the specific file

tar -zxvf compressed.tar.gz --wildcard --no-anchored '*.jpg'

9- compressing and encrypting

tar cz folder_to_encrypt | openssl enc -aes-256-cbc -e > out.tar.gz.enc

10- Enter your preferred tar command in the comments section

Share This!

Add a Comment

Your email address will not be published.

Sign up for our Newsletter

Download "Google Search Pro"

Enter your email and stay on top of things,