Using Bash Script
Create your first Bash script and run it.
We'll cover the following...
Bash script
Let’s create a Bash script that does our backup command. Here are the steps for doing that:
- Run the following command:
vim ~/photo-backup.sh
Bash script
-
Copy the following backup command:
#!/bin/bash (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)
-
Paste the command in the terminal.
-
Press the
esc
key on the keyboard and then type:x!
to save the file.
To quit without saving we can press the
ecs
key on the keyboard and then type:q!
.
- View the file created in the home directory with the
photo-backup.sh
name by:cat ~/photo-backup.sh
Now, we have ...