CloudsArk
Commands Linux

tar create and extract Explained

Understand what tar create and extract means, how to break it down, and when to use it safely.

tar create and extract Explained

Introduction

This article explains a common tar usage that administrators and learners often need to understand clearly.

What This Command Means

The command performs this specific task with tar:

tar -czf backup.tar.gz /etc

Breaking Down the Command

  • tar is the command being run.
  • The options or arguments decide the behavior.
  • The final value is the target, such as a file, process, service, package, host, URL, or directory.

Practical Examples

tar -czf backup.tar.gz /etc
tar -tf logs.tar
tar -tf app-backup.tar.gz | head

Example output:

srv/app/
srv/app/app.conf
srv/app/bin/start.sh

When to Use It

Use tar when you need to bundle files for backup, transfer, or deployment. Add compression when the archive must be smaller for storage or network transfer.

Common Mistakes

  • Forgetting -f before the archive filename.
  • Extracting an archive in the wrong directory and scattering files.
  • Assuming tar compression is enabled unless you specify an option such as -z.

Safer Alternatives

Inspect before changing state when possible:

tar -tf app-backup.tar.gz | head

For wider changes, test on a small target before using the command broadly.

Summary

Understanding tar create and extract is about knowing what each part does and checking the final state after running it.