Managing archived files is a common task in Linux. This article, the first of a two-part series, explores five powerful command-line archive tools, detailing their features and usage with examples.
1. The tar
Command: A Versatile Archiving Utility
tar
, originally a Tape Archiving Program, is the standard UNIX/Linux archiving tool. It's evolved into a versatile utility capable of handling various archive formats. Key options include:
-
-A
: Append to existing archives. -
-c
: Create a new archive. -
-d
: Compare archive contents with the filesystem. -
-j
: bzip2 compression. -
-r
: Append files to an existing archive. -
-t
: List archive contents. -
-u
: Update an existing archive. -
-x
: Extract files from an archive. -
-z
: gzip compression. -
--delete
: Delete files from an archive.
Creating a tar
archive:
tar -zcvf archive_name.tar.gz /path/to/directory
Extracting a tar
archive:
tar -zxvf archive_name.tar.gz
For more comprehensive examples, refer to our guide on Tar Command Examples in Linux.
2. shar
(Shell Archive): A Self-Extracting Legacy Tool
shar
creates self-extracting archives. While a legacy tool, it's noteworthy for its plain-text format. However, its executable nature presents a potential security risk. Key options include:
-
-o
: Specify output archive filename. -
-l
: Limit output size without splitting. -
-L
: Limit output size and split the archive. -
-n
: Specify archive name in the header. -
-a
: Automatically generate headers.
Creating a shar
archive:
shar file_name.extension > file_name.shar
Extracting a shar
archive:
unshar file_name.shar
Note: -o
is required with -l
or -L
; -n
is required with -a
.
3. ar
(Archiver): Primarily for Object Files
ar
is used for creating and manipulating archives, especially binary object file libraries. While it can handle other archive types, tar
has largely superseded it. Its primary use today is managing static library files. Key options include:
-
-d
: Delete members from the archive. -
-m
: Move members within the archive. -
-p
: Print specific archive members. -
-q
: Quick append. -
-r
: Insert file members. -
-s
: Add an index to the archive. -
-a
: Add files to existing archive members.
Creating an ar
archive:
ar cr libmylib.a file1.o file2.o
Extracting an ar
archive:
ar x libmylib.a
4. cpio
(Copy In and Out): A General-Purpose Archiver
cpio
is a versatile archiving tool used by RPM and in Linux kernel initramfs. It's also important in Apple's Installer (as pax
). Key options include:
-
-0
: Null-terminated filenames. -
-a
: Reset access times. -
-A
: Append to an archive. -
-b
: Byte swapping. -
-d
: Create directories as needed.
Creating a cpio
archive:
ls | cpio -ov > archive.cpio
Extracting a cpio
archive:
cpio -idv
5. gzip
: Compression and Decompression
gzip
is a popular compression utility, often used with tar
to create .tar.gz
or .tgz
archives. It also supports file concatenation. Key options include:
-
--stdout
or--to-stdout
: Output to standard output. -
--decompress
or--uncompress
: Decompress a file. -
-d
: Decompress a file. -
-f
: Force compression or decompression.
Creating a gzip
compressed archive (using tar
):
tar -cvzf archive_name.tar.gz /path/to/directory
Extracting a gzip
compressed archive:
gunzip archive_name.tar.gz # then tar -xvf archive_name.tar
Note: Data recovery from corrupted .gz
files is difficult. Multiple backups are recommended.
Conclusion:
This part introduced five essential Linux command-line archive tools. Part 2 will cover five more. Stay tuned for more Linux tips and tricks!
The above is the detailed content of 5 Must-Know Linux Command Line Archive Tools – Part 1. For more information, please follow other related articles on the PHP Chinese website!

This guide details how to configure automatic service restarts in Linux using systemd, enhancing system reliability and minimizing downtime. System administrators often rely on this functionality to ensure critical services, such as web servers (Apa

As Linux users, we often rely on commonly used commands ls, grep, awk, sed and find to complete the work. But Linux has a large number of lesser-known commands that can save time, automate tasks and simplify workflows. This article will explore some underrated but powerful Linux commands that deserve more attention. rename – efficient batch rename files The rename command is the savior when you need to rename multiple files at once. Without using loops containing mv, rename allows you to easily apply complex renaming patterns. Change all .txt files to .log. rename 's/\.txt$/\.log/' *

Linux systems provide various system services (such as process management, login, syslog, cron, etc.) and network services (such as remote login, email, printer, web hosting, data storage, file transfer, domain name resolution (using DNS), dynamic IP address allocation (using DHCP), and so on). Technically, a service is a process or group of process (usually known as a daemon) that runs continuously in the background, waiting for incoming requests (especially from the client). Linux supports different ways to manage services (start, stop, restart, enable automatic startup at system startup, etc.), usually through a process or service manager. Almost all modern Linux distributions now use the same

Run Windows Software and Games on Linux with CrossOver 25 Running Windows applications and games on Linux is now easier than ever, thanks to CrossOver 25 from CodeWeavers. This commercial software solution lets Linux users run a wide variety of Wind
![pCloud - The Most Secure Cloud Storage [50% Off Offer]](https://img.php.cn/upload/article/001/242/473/174580357418126.jpg?x-oss-process=image/resize,p_40)
Secure Your Data with pCloud: A Comprehensive Guide to Linux Installation pCloud, a leading secure cloud storage service, provides a robust platform for managing your files and data. This guide details the installation process on Linux systems. About

MangoHud: A powerful tool for real-time monitoring of Linux gaming performance MangoHud is a powerful and lightweight tool designed for gamers, developers, and anyone who wants to monitor system performance in real time. It acts as an overlay for Vulkan and OpenGL applications, displaying important information such as FPS, CPU and GPU usage, temperature, etc. This article will explore the functions, working principles and usage of MangoHud, and provide step-by-step instructions for installing and configuring MangoHud on Linux systems. What is MangoHud? MangoHud is an open source project available on GitHub and aims to provide a simple and customizable way to monitor

Managing archived files is a common task in Linux. This article, the first of a two-part series, explores five powerful command-line archive tools, detailing their features and usage with examples. 1. The tar Command: A Versatile Archiving Utility t

This guide explores various methods for comparing text files in Linux, a crucial task for system administrators and developers. We'll cover command-line tools and visual diff tools, highlighting their strengths and appropriate use cases. Let's assum


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
