Poor Technical Solution
Learn the problems we get when storing a Bash command in the history for the long term.
Saving our commands
Our following backup command became long and complex after applying all improvements:
(tar -cjf ~/photo.tar.bz2 ~/photo &&
echo "tar - OK" > results.txt ||
! echo "tar - FAILS" > results.txt) &&
(cp -f ~/photo.tar.bz2 ~/backup &&
echo "cp - OK" >> results.txt ||
! echo "cp - FAILS" >> results.txt)
Therefore, we should store it somewhere. Otherwise, we have to type the command in the terminal window each time. Typing is ultimately a bad idea because we can make a mistake or forget something.
Bash has an option to store frequently-used commands. The history file saves everything we executed in the terminal. The file is unique for each user and has the ~/.bash_history
path. When we press the “Ctrl+R” (or “control+R” in macOS) keystroke in the terminal window, Bash calls the quick ...