• Contact
  • About Me
  • Privacy Policy
  • Disclaimer
DefenceDev
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
    • Bash Scripts
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos
  • Web Tools
No Result
View All Result
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
    • Bash Scripts
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos
  • Web Tools
No Result
View All Result
DefenceDev
No Result
View All Result
ADVERTISEMENT
Home Linux Tutorials Commands

How to Extract and View Compressed Files in Linux Using tar and zmore

neo by neo
September 11, 2025
in Commands
0
Linux Files Operation: tar and zmore Extracting Files

Linux Files Operation: tar and zmore Extracting Files

0
SHARES
10
VIEWS
Share on FacebookShare on LinkedIn
Table of Contents
  • Extract and Read Compressed Archives
  • Introduction
  • tar Compress Useful Examples
    • Compress a Single File / Compress Multiple Files
    • Compress a Directory
    • Exclude Specific Files or Directories
    • List Contents of a Compressed Archive
  • tar Extracting Files Useful Examples
    • To Unpack or Extract a tar File
    • Extract single File
    • Extracting Files to a Specific Directory
    • Viewing the Contents of an Archive Before Extracting
    • Preserving Permissions During Extraction
  • Using zmore command
    • View Compressed File
    • Search in the file Without Extracting
    • Check How Many Lines is in the File

Extract and Read Compressed Archives

Linux Files Operation: tar and zmore Extracting Files is a routine task for Linux users, whether you’re backing up files, transferring data, or inspecting system logs. The tar utility is a cornerstone for managing these archives, allowing you to create, extract, and modify .tar files with ease. Complementing it, tools like zmore enable users to view compressed archive contents without the need to extract them fully, saving both time and space.

In this guide, we’ll walk you through extracting files from archives using tar and previewing compressed data with zmore. With practical examples and tips, you’ll master these essential tools for managing files and archives efficiently.

Let’s get started!

Introduction

GNU tar is an archiving program on Linux designed to store multiple files in a single file (an archive), and to manipulate such archives. The archive can be either a regular file or a device (e.g. a tape drive, hence the name of the program, which stands for tape archiver), which can be located either on the local or on a remote machine.

tar Compress Useful Examples

The tar command is a powerful tool in Linux for archiving and compressing files. It is commonly used to package multiple files into a single archive, making it easier to store, transfer, or back up data. By combining tar with compression options like gzip (.gz) or xz (.xz), you can significantly reduce file sizes while maintaining their structure. In this article, we will explore useful examples of how to compress files and directories efficiently using tar.

Compress a Single File / Compress Multiple Files

Useful examples:

tar -czvf archive.tar.gz file.txt
  • -c → Create an archive
  • -z → Use gzip compression
  • -v → Verbose mode (shows files being processed)
  • -f → Specify archive file name
tar -czvf archive.tar.gz file1.txt file2.txt file3.txt

This will compress file1.txt, file2.txt, and file3.txt into archive.tar.gz.

Compress a Directory

tar -czvf archive.tar.gz my_directory/

This will recursively compress all files and subdirectories inside my_directory.

Exclude Specific Files or Directories

tar --exclude="cache/*" -czvf archive.tar.gz my_directory/

This will compress my_directory but exclude anything inside the cache/ subdirectory.

List Contents of a Compressed Archive

tar -tzvf archive.tar.gz

This will list all files inside archive.tar.gz without extracting them.

tar Extracting Files Useful Examples

The tar command is widely used in Linux for archiving files, but it is equally important for extracting them. Whether you need to unpack a backup, retrieve specific files from an archive, or extract compressed data, tar provides efficient options to handle different scenarios. In this article, we will go through useful examples of how to extract files and directories from tar archives, including handling .tar.gz, .tar.xz, and selective extraction.

To Unpack or Extract a tar File

tar -xvf zipped_file.tar

This command extracts files from a gzip-compressed .tar.gz file.

ADVERTISEMENT

Extract single File

tar -xvf zipped_file.tar file1.txt

You can extract specific files or directories by specifying their names.

ADVERTISEMENT

Extracting Files to a Specific Directory

tar -xvf zipped_file.tar -C /var/www/html

To extract files to a directory other than the current one, use the -C option.

Viewing the Contents of an Archive Before Extracting

tar -tf archive.tar

Explanation:

  • -t: Lists the contents of the archive.

This is useful for checking the files in the archive before extraction.

Preserving Permissions During Extraction

To ensure that file permissions and ownership are preserved during extraction, use the --preserve-permissions or --same-permissions option.

sudo tar -xf archive.tar --preserve-permissions

Explanation:

  • This ensures that extracted files retain their original permissions and ownership, which is especially useful when extracting system backups.

Using zmore command

The zmore command on Ubuntu is used to view compressed text files (usually with the .gz extension) directly in the terminal.

View Compressed File

zmore file1.gz

Search in the file Without Extracting

zmore file1.gz | grep "date"

Check How Many Lines is in the File

zmore file1.gz | wc -l

Please check other commands example on my blog.

About The Author

neo

See author's posts

ADVERTISEMENT
Previous Post

Nextcloud: A Two-Year User Experience Review

Next Post

WordPress: Installation on Ubuntu 22.04

neo

neo

Related Posts

10+ Useful Linux find Command Examples You Should Know
Commands

10+ Useful Linux find Command Examples You Should Know

Check Disk Usage on the Linux with du Command
Commands

Check Disk Usage on the Linux with du Command

Linux Process, List all Running Services with ps Command
Commands

Check Running Processes and Services in Linux via ps

Descripton for kill command on Ubuntu
Commands

Linux Process Management, kill Command

Linux Files Operation: chwon (Change Ownership of The Files)
Commands

Linux Files Operation: chown (Change Ownership of the Files)

Linux Files Operation: grep, Efficient Text Search
Commands

Linux Files Operation: grep, Efficient Text Search

Next Post
WordPress: Installation on Ubuntu 22.04

WordPress: Installation on Ubuntu 22.04

Recommended

Remove Snap Package from an Ubuntu Server

Remove Snap Package from an Ubuntu Server

Lesson 2: Linux Bash Variables

Lesson 2: Linux Bash Variables

Install Portainer on Ubuntu 24.04 Using Docker Compose

Install Portainer on Ubuntu 24.04 Using Docker Compose

FortiGate Country Address Object Generator – Block or Allow Access by Country

FortiGate Country Address Object Generator – Block or Allow Access by Country

View & Copy Image Metadata Online – Camera & GPS Info

View & Copy Image Metadata Online – Camera & GPS Info

Categories

  • Blog
  • Cloud
    • Private
  • Linux Tutorials
    • Bash Scripting Tutorials
    • Commands
    • Networking
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Solutions
    • Docker
  • Video Tutorials
    • MikroTik Videos
  • Web Tools
ADVERTISEMENT

DefenceDev Tutorials

defencedev Logo

Whether you’re just starting or looking to expand your skills, I hope you find useful information and engaging discussions here. Let me take you through my journey and the goals behind this space!

Follow Us

Recent News

Install Portainer on Ubuntu 24.04 Using Docker Compose

Install Portainer on Ubuntu 24.04 Using Docker Compose

FortiGate Country Address Object Generator – Block or Allow Access by Country

FortiGate Country Address Object Generator – Block or Allow Access by Country

  • Site Map
  • Privacy Policy
  • Facebook Page
  • Disclaimer
  • Contact
  • About Me

© 2025 defencedev.com - All rights reserved.

No Result
View All Result
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
    • Bash Scripts
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos
  • Web Tools

© 2025 defencedev.com - All rights reserved.