top of page
Writer's pictureMukesh Chanderia

Linux - Commands Part 8 "Compress and Decompress files and folders"

Updated: Aug 21, 2021

1) Let's create folder "Mydata" & copy folder "/etc" to it


mkdir Mydata


cp -rfv /etc Mydata


2) Go to folder and check size of "/etc".


[root@RedHat7 administrator1]# cd Mydata

[root@RedHat7 Mydata]# du -sh /etc

36M /etc


3) Now create a tar file called "Redhat" by compressing "/etc"


[root@RedHat7 Mydata]# tar -cvf Redhat.tar /etc


C-Create V-verbose F -file type (not force)


[root@RedHat7 Mydata]# ls

Redhat.tar

[root@RedHat7 Mydata]# du -sh Redhat.tar

32M Redhat.tar (4 MB shrink with tar)


4) To extract tar use x (in place of c)

Here "C" is used to point to the location where you would like to extract the file.


[root@RedHat7 Mydata]# tar -xvf Redhat.tar -C /tmp

[root@RedHat7 Mydata]# ls

etc (this is our existing directory) Redhat.tar


[root@RedHat7 Mydata]# ls /tmp

etc systemd-private-48343043abf840dda7da8e2a947ca3a4-chronyd.service-ANgLZR


5) If you want to list data then use "t"... It's just like seeing content in zip files without extracting.

[root@RedHat7 Mydata]# tar -tvf Redhat.tar


As we have seen that by creating a tar command the compression isn't good.


So we are going to see in the next article how to compress tar file with Gunzip, Bunzip & XZ methods.




8 views0 comments

Comments


bottom of page