Bird
0
0

You want to rename multiple files by adding a prefix old_ to all .txt files in the current directory using a script. Which approach correctly uses mv inside a loop?

hard📝 Application Q9 of 15
Linux CLI - File and Directory Operations
You want to rename multiple files by adding a prefix old_ to all .txt files in the current directory using a script. Which approach correctly uses mv inside a loop?
Afor f in *.txt; do mv "$f" "old_$f"; done
Bmv *.txt old_*.txt
Cfor f in old_*.txt; do mv "$f" "$f"; done
Dmv old_*.txt *.txt
Step-by-Step Solution
Solution:
  1. Step 1: Understand batch renaming with mv

    To rename multiple files, loop over them and rename each individually.
  2. Step 2: Analyze options

    for f in *.txt; do mv "$f" "old_$f"; done loops over all .txt files and renames each by adding prefix old_.
  3. Final Answer:

    for f in *.txt; do mv "$f" "old_$f"; done -> Option A
  4. Quick Check:

    Loop + mv per file = batch rename [OK]
Quick Trick: Use for loop with mv to rename multiple files [OK]
Common Mistakes:
MISTAKES
  • Trying to mv multiple files with wildcards in one command
  • Looping over wrong filenames
  • Not quoting variables causing errors with spaces

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes