In this Mid-Week article, I am going to share/remind few useful things that can be done using TAR command in Linux/UNIX.
What is TAR stands for?
Tape ARchive==> A Utility which helps to create single file called an ""archive" or a TAR file from number of individual files in Linux/UNIX.
->The contents of this archive can be only the names of the individual files used to create it but not the actual data those file have.
Creating an archive or a TAR file:
Example:
In the below example, I have created f1.out, f2.out and f3.out files with some text.
[root@server2]# ls -lrth
total 12K
-rw-r--r-- 1 root root 317 Mar 15 11:10 f1.out
-rw-r--r-- 1 root root 579 Mar 15 11:11 f2.out
-rw-r--r-- 1 root root 508 Mar 15 11:11 f3.out
Then I used below command to create a tar file which contains the above three files
[root@server2]# tar -cvzf File.tar.gz f1.out f2.out f3.out
f1.out
f2.out
f3.out
[root@server2]# ll
total 16
-rw-r--r-- 1 root root 317 Mar 15 11:10 f1.out
-rw-r--r-- 1 root root 579 Mar 15 11:11 f2.out
-rw-r--r-- 1 root root 508 Mar 15 11:11 f3.out
-rw-r--r-- 1 root root 857 Mar 15 11:17 File.tar.gz
File.tar.gz is the command file that was created using the above TAR command.
Why should we TAR a file?
In my experience I used TAR utility to move bunch of files in compressed mode up to the 1/3rd of the original size of the data with a single command.
==>So, suppose I have 10 files combined have a data of 30 GB, I can make a single TAR file that has a size of just 10 GB and move to the target
How to UnTAR an archive or a TAR file?
#tar -xvzf File.tar.gz
==>The above command gives you back the original files with their actual sizes in the target directory you wish either on local or on network.
Example:
[root@server2]# tar -xvzf File.tar.gz
f1.out
f2.out
f3.out
What other things TAR can do?
Scenario: Suppose you have received a TAR file from one of your superior or a colleague, but you want to know what that file actually has before opening that file. How?
#tar -tvf
==>The above command actually shows the names of the files that the above TAR file or archive has.
[root@server2]# tar -tvf File.tar.gz
-rw-r--r-- root/root 317 2017-03-15 11:10:27 f1.out
-rw-r--r-- root/root 579 2017-03-15 11:11:07 f2.out
-rw-r--r-- root/root 508 2017-03-15 11:11:29 f3.out
-So, if the files above seen are relevant to you, you can think of un-tarring the actual contents. If not, the file could be a malware or virus or anything that could be marked as danger.
Feel free to comment or add more details in the comment's section.
Little follow up work :
You can also break a big tar file into parts for easy uploads, just think of it or try to get the information :).
As always, refer man page of TAR to get required information.
#man tar
HAPPY LINUX LEARNING :)
Easy search from Google:
What is TAR stands for?
Tape ARchive==> A Utility which helps to create single file called an ""archive" or a TAR file from number of individual files in Linux/UNIX.
->The contents of this archive can be only the names of the individual files used to create it but not the actual data those file have.
Creating an archive or a TAR file:
Example:
In the below example, I have created f1.out, f2.out and f3.out files with some text.
[root@server2]# ls -lrth
total 12K
-rw-r--r-- 1 root root 317 Mar 15 11:10 f1.out
-rw-r--r-- 1 root root 579 Mar 15 11:11 f2.out
-rw-r--r-- 1 root root 508 Mar 15 11:11 f3.out
Then I used below command to create a tar file which contains the above three files
[root@server2]# tar -cvzf File.tar.gz f1.out f2.out f3.out
f1.out
f2.out
f3.out
[root@server2]# ll
total 16
-rw-r--r-- 1 root root 317 Mar 15 11:10 f1.out
-rw-r--r-- 1 root root 579 Mar 15 11:11 f2.out
-rw-r--r-- 1 root root 508 Mar 15 11:11 f3.out
-rw-r--r-- 1 root root 857 Mar 15 11:17 File.tar.gz
File.tar.gz is the command file that was created using the above TAR command.
Why should we TAR a file?
In my experience I used TAR utility to move bunch of files in compressed mode up to the 1/3rd of the original size of the data with a single command.
==>So, suppose I have 10 files combined have a data of 30 GB, I can make a single TAR file that has a size of just 10 GB and move to the target
How to UnTAR an archive or a TAR file?
#tar -xvzf File.tar.gz
==>The above command gives you back the original files with their actual sizes in the target directory you wish either on local or on network.
Example:
[root@server2]# tar -xvzf File.tar.gz
f1.out
f2.out
f3.out
What other things TAR can do?
Scenario: Suppose you have received a TAR file from one of your superior or a colleague, but you want to know what that file actually has before opening that file. How?
#tar -tvf
==>The above command actually shows the names of the files that the above TAR file or archive has.
[root@server2]# tar -tvf File.tar.gz
-rw-r--r-- root/root 317 2017-03-15 11:10:27 f1.out
-rw-r--r-- root/root 579 2017-03-15 11:11:07 f2.out
-rw-r--r-- root/root 508 2017-03-15 11:11:29 f3.out
-So, if the files above seen are relevant to you, you can think of un-tarring the actual contents. If not, the file could be a malware or virus or anything that could be marked as danger.
Feel free to comment or add more details in the comment's section.
Little follow up work :
You can also break a big tar file into parts for easy uploads, just think of it or try to get the information :).
As always, refer man page of TAR to get required information.
#man tar
HAPPY LINUX LEARNING :)
Easy search from Google:
Use the text in quotes shown below to get into my blog quickly:
"linuxunixdatabase blogger"
No comments:
Post a Comment