Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a backup directory if it does not exist.
Bash Scripting
if [ ! -d [1] ]; then mkdir -p /backup fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong directory path.
Forgetting the exclamation mark to negate the condition.
✗ Incorrect
The script checks if the /backup directory exists. If not, it creates it using mkdir -p.
2fill in blank
mediumComplete the code to copy all files from /data to the backup directory.
Bash Scripting
cp -r /data/* [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Copying to the wrong directory.
Forgetting the -r flag for directories.
✗ Incorrect
The cp command copies all files and folders from /data to /backup recursively.
3fill in blank
hardFix the error in the code to archive the backup directory into a tar.gz file.
Bash Scripting
tar -czf [1] /backup Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong file extension like .zip or .gz alone.
Omitting the -z flag for compression.
✗ Incorrect
The tar command with -czf creates a compressed tar.gz archive. The file should end with .tar.gz.
4fill in blank
hardFill both blanks to check if the backup archive exists and print a success message.
Bash Scripting
if [ -f [1] ]; then echo [2] fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for wrong file name.
Printing failure message on success check.
✗ Incorrect
The script checks if the backup.tar.gz file exists and prints a success message if true.
5fill in blank
hardFill all three blanks to create a timestamped backup filename and archive the backup directory.
Bash Scripting
timestamp=$(date +[1]) backup_file=[2]_$timestamp.tar.gz tar -czf [3] /backup
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong date format string.
Not using the variable for the archive filename.
Hardcoding the archive filename instead of using timestamp.
✗ Incorrect
The date command formats the timestamp, backup_file uses it in the name, and tar archives using that filename.