Exercise: Bash Features
Explore and practice advanced Bash features including command chaining with logical operators, file copying, archiving, deleting, and logging outcomes. Understand how to write clean, multi-line Bash commands to manage file operations effectively.
Practice
Write the command that implements the following algorithm:
-
Copy the
/usr/share/doc/bash/READMEfile to the home directory. -
Archive the copied
~/READMEfile.
- Delete the copied
~/READMEfile.
Each step takes place only if the previous one succeeds. We write the result of each step to the log file result.txt.
Solution
Let’s implement the algorithm step by step. The first action is to copy the README file to the user’s home directory like so:
cp /usr/share/doc/bash/README ~
We use the && operator and the echo ...