File Archiving and Compressing - RHCSA

Why file archiving and compressing is important?

  • Creating Backups 
  • Transferring data across network is much easier.
If we want to send data Over the network and Machine to Machine, Compress the file and send.

What is an Archiving? 

Archiving is the process of collecting files or directories into one location.
We use tar command for it.
tar stands for Tape Archiving.
Options:
  1. c - Create an archive
  2. t - List the content of the archive
  3. x - Extend the archive 
  4. v - Verbose (print the file names when they are archiving or compressing)
  5. f - File name
Remember that The file extension of the archived file should be .tar

Examples:

#mkdir data1
#mkdir data2
#mkdir data3
#tar cvf data-archive.tar data1 data2 data3


data1, data2, data3 files are archived. Archived file name is data-archived.tar 
We cannot create same name archive files because they are overwriting without given any feedback. Hence use ls -l command.

#tar cvf <archive file path> <file paths which need to archive>

If we want to archive /var/log file in /root/log-archive.tar file. Use following command.

#tar cvf /root/log-archive.tar /var/log

c- create an archive | v- verbose | f- file name

Compressing 

Compressing is a mechanism to reduce the size of a file. There are two methods of compressing.
  • gzip - extension .gz or .tgz
  • bzip - extension .bz2 or .tbz2
Tar ball is a compressed file. 
If we want to zip /usr/local file,
  •  tar czvf local-zip.tgz /usr/local --> gzip
  • tar cjvf local-zip.tbz2 /usr/local --> bzip 

 Archiving and Compressing

If we want to archive and compress /usr/local,  
  • tar czvf /root/arzip.tar.tgz /usr/local --> gzip 
  • tar cjvf /root/arzip.tar.tbz /usr/local --> bzip

Extracting 

First identify what is the extension of compressed folder. (.tar.tgz or .tar.tbz)

#mkdir unzip
#cd unzip
#tar xzf /root/arzip.tar.tgz

x- extract | z- bzip | f- file name

Comments

Popular posts from this blog

Basic Configurations in Windows Server 2016 (2)

Interrupt the kernel to change the fstab - RHCSA

Controlling the boot process - RHCSA