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…