Read a sample: 1. A Safe Place to Practice
A rename can be as small as changing draft.txt to report.txt. The command may take only a moment, but it still raises useful questions: Are you in the directory you think you are? Does the source exist? Is the proposed destination already in use? Afterward, did the file end up where you expected?
This book builds a habit of answering those questions before and after a change. You do not need to memorize a long list of commands at the outset. You need a place to experiment, a few sample items, and a repeatable way to check your work.
In this chapter, you will create a practice directory under your home directory, add files and folders, and inspect what you made. You will also learn the four-part workflow used throughout the book: inspect, preview, apply, and verify. The first exercises focus on preparation rather than renaming. That preparation is a skill in its own right.
Open a terminal on a Linux system where you have permission to create files in your home directory. Depending on your setup, that might be a graphical terminal application, a virtual machine, or a remote shell session. The examples use a conventional shell and common Linux commands.
A terminal displays a prompt when it is ready for a command. The prompt can include your username, computer name, or current directory, but its appearance varies. In the examples that follow, commands appear in code blocks without a prompt. Type the command itself and press Enter; do not type any surrounding explanatory text.
For example:
bash
pwd
The command pwd prints the current working directory: the location the shell uses as its starting point for relative paths. Your result might look like this:
text
/home/lee
Your actual output will probably be different. That is expected. What matters is that you notice the location before issuing commands that create or change files.
A terminal session can be left in a directory from an earlier task. Rather than assuming where you are, check. When you intend to work in your home directory, you can return there and confirm your location:
bash
cd
pwd
The cd command changes the shell’s current working directory. Used without an argument in this example, it takes you to your home directory. The following pwd reports where you are now.
Your home directory is a convenient starting point because it normally contains your personal files and is writable by your account. It is not a dumping ground for experiments, however. To keep practice material separate from everything else, you will put it in a clearly named directory.
From your home directory, run:
bash
mkdir rename-practice
The command mkdir creates a directory. Here, rename-practice is the name of the new directory. If the command succeeds, it will usually print nothing. Silence is not proof that every assumption was correct, so inspect the result:
bash
ls -ld rename-practice
The ls command lists information about files and directories. With -l, it uses a longer listing format. The -d option asks it to list the directory itself rather than its contents. You should see an entry whose name ends in rename-practice.
If mkdir reports that the directory already exists, do not assume it is empty or disposable. It may contain work from an earlier session. Inspect it, or choose a different, unused name such as rename-practice-new and use that name consistently in the following commands. Do not delete an existing directory merely to make the example work.
Now enter your new workspace and confirm the location:
bash
cd rename-practice
pwd
The printed path should end with the name of the directory you created. In the remainder of this chapter, commands that create sample items assume that rename-practice is your current working directory.
This workspace is disposable in the sense that you will fill it with practice material, not irreplaceable documents. It is still a real directory on a real filesystem. Commands run there can affect its contents, and a command using another path can affect items outside it. Keeping practice separate reduces risk; it does not make every command harmless.
Before creating anything, list the workspace:
bash
ls -la
The -a option includes names that begin with a dot, often called hidden names. In a newly created directory, the listing will normally include . and ... The first refers to the current directory; the second refers to its parent directory. They are useful path components, not sample files you need to create.
You may also see other entries if you are reusing a directory. If so, stop and decide whether you are in the workspace you intended. A practice area is easiest to reason about when you know what was there before you began.
The distinction between a filename and a path will receive a fuller treatment in Chapter 2. For now, think of a filename as the name of an item within a directory, and a path as the directions used to find it. In the command ls -ld rename-practice you ran from your home directory, the name rename-practice was interpreted relative to that current location. After you entered it, the same name by itself would refer to an item inside the workspace, not to the workspace you just entered.
That change in interpretation is why pwd is such a useful first check. The text you type matters, but so does the directory from which you type it.