Linux Terminal Command: tar
The tar command is an essential tool in File Manipulation & Viewing. In this tutorial, we will explore what tar does, look at everyday examples, and cover advanced options to supercharge your command-line workflow.
Concept & Explanation
The tar command binds multiple files and directories into a single archive file, commonly called a ’tarball’. It can optionally compress archives using gzip or bzip2.
Common Options & Syntax
tar [options] [arguments]
Here are the most common flags used with tar:
- Simple Usage: Basic default commands.
- Detailed View: Shows diagnostic information.
- Advanced Actions: Can chain parameters for scripting.
1. Interactive Example (Simple)
Here is how most people run the command:
# Example
tar -cvf archive.tar ./files
What it does: Creates a tar archive (-c), showing file progress (-v), named ‘archive.tar’ (-f) from the ‘./files’ directory.
2. Power-User Example (Advanced)
For scripting and advanced diagnostics, use this configuration:
# Advanced
tar -xzvf archive.tar.gz -C /opt/destination
What it does: Extracts (-x) a gzipped archive (-z) into a target directory (-C) showing file logs.
⚙️ Warning & Common Pitfalls
[!WARNING] Always put the
-f(file) flag at the very end of your options block (e.g.-cvf) because the command expects the file name to immediately follow the-fflag.
🔗 Related Commands
Here are some related posts on cli_tty1 you might want to check out: