Success Message
Part of the Fundamentals section of Coddy's Terminal journey — lesson 79 of 82.
Challenge
EasyLet's complete the backup script by adding a final success message that summarizes what was backed up.
Modify backup.sh to:
- Keep all the existing code from the previous lesson
- After the "Files copied successfully" message, add a final summary line
- Print:
Backup complete: [source_dir] -> [backup_dir]
Run the script and enter documents when prompted. Your output should look like:
Backing up: documents
Created backup folder: backup_20240115_143052
Files copied successfully
Backup complete: documents -> backup_20240115_143052The timestamp in your output will be different based on the current date and time.
Congratulations! You've built a complete backup script that:
- Prompts the user for a source directory
- Creates a timestamped backup folder
- Copies all files to the backup
- Provides clear feedback at each step
Hint: Add
echo "Backup complete: $source_dir -> $backup_dir"at the end of your script to display the final summary message.
Try it yourself
cat > backup.sh << 'EOF'
#!/bin/bash
echo "Enter folder to backup:"
read folder
echo "Backing up: $folder"
timestamp=$(date +%Y%m%d_%H%M%S)
backup_dir="backup_$timestamp"
mkdir "$backup_dir"
echo "Created backup folder: $backup_dir"
cp "$folder"/* "$backup_dir"/
echo "Files copied successfully"
EOF
chmod +x backup.sh
echo "documents" | bash backup.shAll lessons in Fundamentals
4Directories
Create A DirectoryCopy A DirectoryMove And Rename A DirectoryDelete A DirectoryRecap - Directory Operations7File Content
Head And TailWord CountSort CommandUnique CommandGrep BasicsGrep With FlagsRecap - Text Detective2Navigation
Print Working DirectoryList FilesChange DirectoryAbsolute vs Relative PathsHome And Root DirectoryRecap - Find Your Way8Redirection
Standard OutputOverwrite To A FileAppend To A FileStandard InputStandard ErrorRecap - Log Builder11Permissions
Understanding PermissionsReading PermissionsChmod With NumbersChmod With SymbolsFile OwnershipRecap - Lock It Down14Backup Script Project
Project OverviewGetting The Source Path6Wildcards And Patterns
The Star WildcardThe Question Mark WildcardBracket WildcardsCombining WildcardsRecap - Selective Operations9Piping
What Is A PipeChaining Two CommandsChaining Multiple CommandsPipe With GrepRecap - Data Pipeline