Skip to content

Chapter 7 of 7

Archiving, Compression, and Automation

Combining many files into a single archive and then compressing them is a common task. tar is the traditional Unix archiver: tar -cvf archive.tar dir creates an archive (the c is "create", v is "verbose", f names the file), and tar -xvf archive.tar extracts it. Adding -z runs the archive through gzip on the fly, producing a .tar.gz file. For standalone compression, gzip file produces a .gz file and gunzip file.gz reverses the operation. ZIP archives, common when interoperating with Windows, are handled by unzip file.zip to extract and zip archive.zip files to create.

Automation is where the command line truly shines. The crontab system runs scheduled jobs in the background. crontab -e opens your personal cron table for editing, where each line follows the format * * * * * command to specify minute, hour, day of month, month, and day of week. Cron then runs the command at the matching times, making it perfect for routine backups, log rotations, and report generation.

For more elaborate automation, you can write Bash scripts. A script begins with a shebang line such as #!/bin/bash so the kernel knows which interpreter to use. After writing your commands in a file, make it executable with chmod +x script.sh and run it with ./script.sh. Inside scripts you can use variables, loops, and conditional statements, allowing you to package complex sequences of commands into reusable, parameterized tools. Together, archives, compression, scheduling, and scripting turn the Linux CLI from an interactive prompt into a powerful platform for reliable, repeatable system administration.

All chapters
  1. 1Introduction to the Linux Command Line
  2. 2Navigating and Managing the Filesystem
  3. 3Inspecting and Editing Files
  4. 4Permissions, Searching, and Data Flow
  5. 5Processes, Resources, and Shell Customization
  6. 6Networking and Package Management
  7. 7Archiving, Compression, and Automation

Drill it

Reading is not remembering. These come from the Linux Command Line deck:

Q

What is the Linux command line interface (CLI)?

The Linux CLI is a text-based interface for interacting with the operating system using commands entered via a terminal emulator, allowing users to perform task...

Q

What is a shell in Linux?

A shell is a program that interprets commands entered into the CLI, processes them, and communicates with the kernel; common shells include Bash (Bourne Again S...

Q

How do you open a terminal in Linux?

Use keyboard shortcuts like Ctrl+Alt+T on Ubuntu or search for 'Terminal' in the applications menu; it launches a shell session for command execution.

Q

What does the <code>pwd</code> command do?

The pwd (Print Working Directory) command displays the absolute path of the current working directory, helping users confirm their location in the filesystem.