Course Content
Linux Essentials for DevOps Automation
The "Linux Essentials for DevOps Automation" training provides a comprehensive understanding of Linux fundamentals tailored to DevOps practices. By mastering these concepts, participants can effectively leverage Linux in DevOps environments to automate tasks, manage infrastructure, and deploy applications with efficiency and reliability.
0/15
Linux Essentials for DevOps Automation

The tar, untar, and unzip commands are essential utilities in Linux used for creating, extracting, and managing compressed archive files. Here’s how you can use them:

 

1. tar:

Description: The tar command is used to create, list, and extract files from tar archives.

Options:

-c: Create a new archive.
-x: Extract files from an archive.
-t: List the contents of an archive.
-v: Verbose mode, display progress while processing files.
-f: Specify the filename of the archive.

 

List of files to be archived.

 
-rw-r--r--. 1 devnixops devnixops 22 Jun 5 21:56 test
-rw-r--r--. 1 devnixops devnixops 26 Jun 5 21:58 test1
-rw-r--r--. 1 devnixops devnixops 26 Jun 5 21:59 test2
-rw-r--r--. 1 devnixops devnixops 82 Jun 5 22:06 test4

 

Create Archive:

[devnixops@uadev tmp]$ tar -cvf devnixops.tar test test1 test2 test4 
test
test1
test2
test4

 

List the archive:

[devnixops@uadev tmp]$ ls -lrt devnixops.tar
-rw-r--r--. 1 devnixops devnixops 10240 Jun 5 22:32 devnixops.tar
[devnixops@uadev tmp]$

 

List the archive contents: 

[devnixops@uadev tmp]$ tar -tvf devnixops.tar
-rw-r--r-- devnixops/devnixops 22 2024-06-05 21:56 test
-rw-r--r-- devnixops/devnixops 26 2024-06-05 21:58 test1
-rw-r--r-- devnixops/devnixops 26 2024-06-05 21:59 test2
-rw-r--r-- devnixops/devnixops 82 2024-06-05 22:06 test4
[devnixops@uadev tmp]$
 
 
2. untar:

Description: There is no separate untar command; you can use tar to extract files from a tar archives. 

 

[devnixops@uadev tmp]$ tar -xvf devnixops.tar
test
test1
test2
test4
[devnixops@uadev tmp]$ ls -lrt test*
-rw-r--r--. 1 devnixops devnixops 22 Jun 5 21:56 test
-rw-r--r--. 1 devnixops devnixops 26 Jun 5 21:58 test1
-rw-r--r--. 1 devnixops devnixops 26 Jun 5 21:59 test2
-rw-r--r--. 1 devnixops devnixops 82 Jun 5 22:06 test4
[devnixops@uadev tmp]$

 
 
3. unzip:

Description: The unzip command is used to extract files from ZIP archives.

Options:

-l: List the contents of the archive without extracting.
-d directory: Extract files to the specified directory.

 

Archive files using zip utility:

[devnixops@uadev tmp]$ zip archive.zip test test1 test2 test4
adding: test (stored 0%)
adding: test1 (deflated 4%)
adding: test2 (deflated 12%)
adding: test4 (deflated 23%)
[devnixops@uadev tmp]$ ls -lrt archive.zip
-rw-r--r--. 1 devnixops devnixops 705 Jun 5 22:39 archive.zip
[devnixops@uadev tmp]$

 

Unarchive the files using unzip:

[devnixops@uadev tmp]$ unzip archive.zip
Archive: archive.zip
replace test? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
extracting: test
inflating: test1
inflating: test2
inflating: test4
[devnixops@uadev tmp]$

 

List the content of the zip archive: 

[devnixops@uadev tmp]$ unzip -l archive.zip 
Archive: archive.zip
Length Date Time Name
--------- ---------- ----- ----
22 06-05-2024 21:56 test
26 06-05-2024 21:58 test1
26 06-05-2024 21:59 test2
82 06-05-2024 22:06 test4
--------- -------
156 4 files
[devnixops@uadev tmp]$

 

 

Notes:

  • Tar archives typically have the .tar extension, while ZIP archives have the .zip extension.
  • Both tar and unzip commands can handle multiple files and directories at once.
  • tar is commonly used on Linux systems, while unzip is used for ZIP archives, which are more common in Windows environments.

Using these commands, you can efficiently create, extract, and manage compressed archive files in Linux. They are essential tools for packaging and distributing files and directories while conserving disk space and maintaining file structure.