Everyday Guidebooks
Cover of The Linux How-To Guide to Text-Based Archives

Cybersecurity & IT

The Linux How-To Guide to Text-Based Archives

A Command-Line Guide to Packaging Files, Choosing Compression, Inspecting Contents, and Extracting Safely

by Todd Michael

Available now

Need to package a project, inspect an unfamiliar archive, or retrieve one file without unpacking everything? This hands-on guide makes Linux archive and compression commands approachable through practical examples you can try at the terminal.

Build a safe practice workspace, learn how tar, gzip, bzip2, xz, and zip fit together, and choose useful names and compression formats for everyday jobs. Follow worked examples to list contents, extract selected paths, preserve relevant file details, and troubleshoot common mistakes. You will also learn precautions for suspicious archive paths and why an isolated extraction directory matters.

Designed for beginners, junior administrators, and certification candidates, the book offers focused command-line practice rather than an exam cram or a promise of certification. If you are searching for linux how to books that explain not just what to type but why, start here and build a skill you can use on real systems.

Contents
  1. 1. Start with a Safe Practice Workspace
  2. 2. Archives, Compression, and File Names
  3. 3. Create Your First tar Archive
  4. 4. Inspect and Extract tar Contents
  5. 5. Compress Individual Files
  6. Prepare a Small Test File
  7. Compress with gzip
  8. Try bzip2 and xz
  9. Compare the Results Carefully
  10. Write Compressed Data to Standard Output
  11. Test Compressed Data
  12. Choose Options Deliberately
  13. Practice: Preserve, Test, and Restore
  14. 6. Combine tar with Compression
  15. 7. Work with zip Archives
  16. 8. Select Files and Shape Archive Paths
  17. 9. Inspect Before You Extract
  18. 10. Understand Permissions, Links, and Metadata
  19. 11. Choose Compression for the Job
  20. 12. Verify Packages and Avoid Common Errors
  21. 13. Package and Recover Realistic Projects
  22. Scenario 1: Hand off a project
  23. Scenario 2: Create a dated snapshot
  24. Scenario 3: Recover selected documents
  25. Apply the workflow to unfamiliar archives
  26. 14. Command-Line Practice and Reference
  27. Other Books by Todd Michael

Read a sample: 1. Start with a Safe Practice Workspace

A few archive commands can package an entire project, but a command entered from the wrong directory can package the wrong project just as easily. Extraction has a similar risk: files may appear in an unexpected location, or existing files may be replaced. Before working with archive formats, it is worth building a small workspace where mistakes are easy to spot and the contents are safe to discard.

In this chapter, you will create a practice directory, add a handful of sample files, and use basic shell commands to examine them. You will also learn how to read the command examples used throughout the book. The goal is not to memorize every option at once. It is to establish a reliable routine: know where you are, know which files a command will affect, and check the result.

The examples assume a typical Linux command-line environment with a shell such as Bash and common utilities available. You do not need administrator privileges. Use an ordinary user account, not the root account, for the exercises.

Open a terminal using the method provided by your Linux system. If you are connected to another machine through a remote shell, remember that the commands affect that machine’s files, not necessarily those on the computer in front of you.

Begin with:

bash pwd

The pwd command prints the shell’s current working directory. Your output might look like this:

text /home/morgan

Your user name and path will probably be different. The current working directory matters because many commands interpret a file name relative to it. A command that refers to notes.txt usually means the file named notes.txt in the current directory.

Next, list the visible entries in the current directory:

bash ls

The output depends on your account. You might see directories such as Documents or Downloads, or you might see very little. To include names beginning with a dot, use:

bash ls -a

Names beginning with a dot are commonly called hidden names. They are not secret or protected; ordinary ls output simply omits them unless asked to include them. The entries . and .. represent the current directory and its parent, respectively.

Avoid experimenting in a directory that contains files you care about. The next section creates a separate location under your home directory.

First, move to your home directory and confirm the change:

bash cd ~ pwd

The shell expands ~ to your home directory when it appears in this context. Your home directory is a convenient place for personal practice because your ordinary account normally has permission to create files there.

Now check whether the intended workspace name already exists:

bash ls -ld linux-archive-practice

If the command reports that it cannot access the name because it does not exist, create the directory:

bash mkdir linux-archive-practice

If it already exists, do not assume it is disposable or empty. Choose a different name, such as linux-archive-practice-2, after checking that name as well. Substitute your chosen name in the commands that follow.

The separate check matters because a practice directory should not silently merge with an existing collection of files. Even with a new directory, take a moment to confirm the location before adding anything:

bash cd linux-archive-practice pwd ls -a

The printed path should end in linux-archive-practice, or in the alternative name you selected. A newly created empty directory will normally show only . and .. with ls -a.

Treat this directory as disposable only if you have confirmed that it contains nothing you need. This book will use it as a parent for sample material and output. “Disposable” does not mean you should remove it without checking its contents first.

Create a project directory and a separate directory for results:

bash mkdir project output mkdir project/docs project/images

The first command creates two directories in the workspace. The second creates two directories inside project. Keeping source files and generated results apart makes it easier to see what an archive command reads and where its output goes.

Add a few plain-text files:

bash printf '%s\n' 'Archive practice project' > project/README.txt printf '%s\n' 'Review the handoff checklist.' > project/docs/notes.txt printf '%s\n' 'Draft version for practice.' > "project/docs/meeting notes.txt" printf '%s\n' 'Sample image description, not an image file.' > project/images/description.txt

These are deliberately simple files. They give you a predictable directory structure without requiring a download. The file with spaces in its name will help you practice quoting paths.

The printf command writes text to standard output. In these examples, > redirects that output into a file. Redirection can overwrite an existing file: if project/README.txt already existed, the first command would normally replace its contents. That is why you created and checked a new workspace before running these commands.

For a quick view of the project, run:

bash ls -R project

The -R option asks ls to list directories recursively. You should see README.txt, the docs and images directories, and the files inside them. To read one of the files, use:

bash cat project/docs/notes.txt

The output should be:

text Review the handoff checklist.

The sample project is now ready for later packaging exercises. The output directory should still be empty. You can check it with:

bash ls -a output

A path tells a command where to find a file or directory. An absolute path starts at the root directory, represented by /. For example, /home/morgan/linux-archive-practice/project is an absolute path on a system where that is the user’s home…

More Cybersecurity & IT

Cover of The White Hat Bible, Volume 1The White Hat Bible, Volume 1Available nowCover of The White Hat Bible, Volume 2The White Hat Bible, Volume 2Available nowCover of The White Hat Bible, Volume 3The White Hat Bible, Volume 3Available nowCover of The White Hat Bible, Volume 4The White Hat Bible, Volume 4Available nowThe White Hat Bible, Volume 5Available nowCover of The White Hat Pocket GuideThe White Hat Pocket GuideAvailable now

About Todd Michael

Todd Michael is an American author and the founder of ToddMichael.tv. He writes practical, plain-English books on money, health, preparedness, technology, games, humor and more.

About the author Todd Michael · Todd Michael’s author site

Part of the ToddMichael.tv network.