Bird
Raised Fist0
Bash Scriptingscripting~10 mins

File download automation in Bash Scripting - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to download a file using curl.

Bash Scripting
curl https://example.com/file.txt [1] file.txt
Drag options to blanks, or click blank then click option'
A-d
B-O
C-L
D-o
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-O' saves the file with the remote name, not a custom name.
Using '-d' is for sending data, not downloading.
Using '-L' follows redirects but does not specify output file.
2fill in blank
medium

Complete the code to download a file and show progress bar with wget.

Bash Scripting
wget [1] https://example.com/file.zip
Drag options to blanks, or click blank then click option'
A--show-progress
B-q
C-b
D-O
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-q' hides output, so no progress is shown.
Using '-b' runs wget in background, no progress shown.
Using '-O' specifies output file, not progress.
3fill in blank
hard

Fix the error in the script to download multiple files listed in urls.txt using wget.

Bash Scripting
while read url; do
  wget [1] "$url"
done < urls.txt
Drag options to blanks, or click blank then click option'
A-c
B-b
C-q
D-i
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-i' expects a file input, but here URLs are read from a file already.
Using '-b' runs in background, not needed here.
Using '-q' suppresses output, not fixing errors.
4fill in blank
hard

Fill both blanks to create a script that downloads files from a list and logs output.

Bash Scripting
while read url; do
  curl [1] "$url" -o "$(basename "$url")" >> download.log 2>&1
  sleep [2]
done < urls.txt
Drag options to blanks, or click blank then click option'
A-s
B2
C5
D-L
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-L' follows redirects but does not silence output.
Using '2' seconds sleep might be too short for some servers.
Not using silent mode causes cluttered logs.
5fill in blank
hard

Fill all three blanks to create a robust download script with retries and timeout.

Bash Scripting
curl [1] --retry [2] --max-time [3] -O https://example.com/data.csv
Drag options to blanks, or click blank then click option'
A--retry-connrefused
B3
C30
D--silent
Attempts:
3 left
💡 Hint
Common Mistakes
Using '--silent' hides output but does not control retries or timeout.
Setting retries too high can cause long waits.
Timeout too low may abort downloads prematurely.

Practice

(1/5)
1. What is the main purpose of automating file downloads in bash scripting?
easy
A. To slow down the internet speed
B. To make files larger
C. To save time and reduce manual errors
D. To delete files automatically

Solution

  1. Step 1: Understand automation benefits

    Automating repetitive tasks like file downloads saves time and reduces mistakes.
  2. Step 2: Identify the correct purpose

    The main goal is efficiency and accuracy, not file size or deletion.
  3. Final Answer:

    To save time and reduce manual errors -> Option C
  4. Quick Check:

    Automation = Save time & reduce errors [OK]
Hint: Automation means doing tasks faster and safer [OK]
Common Mistakes:
  • Thinking automation changes file size
  • Confusing automation with file deletion
  • Assuming automation slows internet
2. Which of the following is the correct syntax to download a file using wget in bash?
easy
A. curl -download http://example.com/file.txt
B. download http://example.com/file.txt
C. fetch http://example.com/file.txt
D. wget http://example.com/file.txt

Solution

  1. Step 1: Recall wget command syntax

    The basic wget command to download a file is 'wget URL'.
  2. Step 2: Compare options

    Only wget http://example.com/file.txt uses the correct wget syntax; others use invalid commands.
  3. Final Answer:

    wget http://example.com/file.txt -> Option D
  4. Quick Check:

    wget URL = correct syntax [OK]
Hint: Use 'wget URL' to download files simply [OK]
Common Mistakes:
  • Using non-existent commands like 'download' or 'fetch'
  • Mixing curl options with wget
  • Forgetting to specify the URL
3. What will be the output of this bash command?
curl -O https://example.com/sample.txt
ls | grep sample.txt
medium
A. sample.txt
B. No output
C. curl: command not found
D. Error: file not found

Solution

  1. Step 1: Understand curl -O behavior

    The command downloads 'sample.txt' to the current directory.
  2. Step 2: Check the ls and grep output

    Listing files and filtering for 'sample.txt' will show the filename if download succeeded.
  3. Final Answer:

    sample.txt -> Option A
  4. Quick Check:

    curl -O downloads file, ls | grep shows filename [OK]
Hint: curl -O saves file; grep finds it in list [OK]
Common Mistakes:
  • Assuming curl prints file content
  • Expecting no output after download
  • Confusing curl errors with normal output
4. Identify the error in this script snippet for downloading a file:
curl -o https://example.com/data.csv
medium
A. URL is incorrect
B. Missing filename after -o option
C. curl cannot download CSV files
D. No error, script is correct

Solution

  1. Step 1: Check curl -o usage

    The '-o' option requires a filename to save the download.
  2. Step 2: Analyze the command

    The command provides URL but no filename after '-o', causing error.
  3. Final Answer:

    Missing filename after -o option -> Option B
  4. Quick Check:

    curl -o needs filename [OK]
Hint: Always give filename after curl -o [OK]
Common Mistakes:
  • Forgetting filename after -o
  • Thinking URL is wrong format
  • Believing curl can't download certain file types
5. You want to automate downloading multiple files listed in a text file named urls.txt. Which bash script snippet correctly downloads each file using wget?
hard
A. while read url; do wget "$url"; done < urls.txt
B. for url in urls.txt; do wget $url; done
C. wget -i urls.txt -O output.log
D. cat urls.txt | wget

Solution

  1. Step 1: Understand reading lines from file

    The 'while read url; do ... done < urls.txt' reads each line as a URL.
  2. Step 2: Check wget usage inside loop

    Using wget "$url" downloads each URL correctly.
  3. Step 3: Analyze other options

    'for url in urls.txt; do wget $url; done' treats filename as URL, 'wget -i urls.txt -O output.log' misuses -O option causing all files to overwrite as 'output.log', 'cat urls.txt | wget' pipes incorrectly.
  4. Final Answer:

    while read url; do wget "$url"; done < urls.txt -> Option A
  5. Quick Check:

    Loop reading lines + wget = correct [OK]
Hint: Use while read loop to process URLs line by line [OK]
Common Mistakes:
  • Using for loop directly on filename
  • Misusing wget options
  • Piping file content directly to wget
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard