0
0
Bash Scriptingscripting~30 mins

File download automation in Bash Scripting - Mini Project: Build & Apply

Choose your learning style9 modes available
File download automation
📖 Scenario: You work in an office where you often need to download files from the internet. Doing this manually every time wastes time. Automating file downloads with a simple script can save you effort and avoid mistakes.
🎯 Goal: You will create a bash script that downloads a list of files from given URLs automatically. The script will check if the files already exist before downloading to avoid duplicates.
📋 What You'll Learn
Create a bash array variable with exact URLs
Create a variable for the download folder path
Use a for loop to iterate over the URLs
Check if the file already exists before downloading
Use wget command to download files
Print the download status for each file
💡 Why This Matters
🌍 Real World
Automating file downloads saves time and reduces errors when you need to get many files regularly from the internet.
💼 Career
Many IT and DevOps roles require scripting to automate repetitive tasks like downloading files, making this skill valuable for efficiency and reliability.
Progress0 / 4 steps
1
Set up the list of file URLs
Create a bash array called file_urls with these exact URLs: https://example.com/file1.txt, https://example.com/file2.txt, and https://example.com/file3.txt.
Bash Scripting
Need a hint?

Use parentheses () to create a bash array and double quotes "" around each URL.

2
Create the download folder variable
Create a variable called download_folder and set it to downloads (a folder name).
Bash Scripting
Need a hint?

Use = without spaces to assign the folder name as a string.

3
Write the loop to download files if missing
Write a for loop using url as the iterator to go through file_urls. Inside the loop, extract the filename from the URL using basename. Then check if the file $download_folder/$filename exists. If it does not exist, use wget to download the file into $download_folder. If it exists, print "File $filename already exists."
Bash Scripting
Need a hint?

Use mkdir -p to create the folder if it does not exist. Use basename to get the filename from the URL.

4
Print a final message after downloads
Add a echo command after the loop to print exactly: All downloads complete.
Bash Scripting
Need a hint?

Use echo to print the message exactly as shown.