LFCS Admin Exam preparation guide – Archive, backup, compress, unpack, and uncompressed files

LFCS Admin Exam preparation guide series, main page can be found here.

This post is part of Essential Commands from the domain competency list for the exam. The full list can be found in the link above paragraph or the Linux Foundation page here.

This post is part of Essential Commands from the domain competency list for the exam. The full list can be found in the link above paragraph or the Linux Foundation page here.

In this post, we will learn how to use the tar command to archive files. One of the jobs of Linux Administrator is to keep the data on the server secure, this is where the tar command coming as a very handy tool.

tarTape Archive – it was originally created to write files to the tape, now is used mainly to archive the files and directories. In the below example, we are using the tar command to create backup file from one directory containing 2 files. tar cvf where c is created, v is verbose and f is a file, we can see after listing files inside the backup directory that one new file has been created

tar command example

Is always good to compress file while creating the new tar file, to do that we add z is zipped to our command, we can see that new file created is much smaller.

tar command example to create zip file

tar command allows us as well to see the content of the tar file without the need to expand the file, we use t for listing the file.

tar listing command example

And of course we can use the tar command to extract the archive file. tar xvf where x stands for extract will expand the archive file to current directory.

tar extracting command example

To extract to different directory we can add –directory=<path to directory>. There is much more we can do with the tar command, some of the operation example listed below

A, –catenate, –concatenate append tar files to an archive
-c, –create create a new archive
-d, –diff, –compare find differences between archive and file system
–delete delete from the archive (not on mag tapes!)
-r, –append append files to the end of an archive
-t, –list list the contents of an archive
–test-label test the archive volume label and exit
-u, –update only append files newer than copy in archive
-x, –extract, –get extract files from an archive

Thank you for reading.