Bird
0
0

Which command should you use inside the script?

hard📝 Application Q8 of 15
Linux CLI - Linux Basics and Terminal
You want to write a Bash script that lists all files in the current directory that have the extension .txt and saves the list to a file named textfiles.txt. Which command should you use inside the script?
Als *.txt > textfiles.txt
Bls *.txt >> textfiles.txt
Ccat *.txt > textfiles.txt
Decho *.txt > textfiles.txt
Step-by-Step Solution
Solution:
  1. Step 1: Understand the goal

    You want to list filenames ending with .txt, not their contents, and save that list to a file.
  2. Step 2: Choose correct command

    ls *.txt > textfiles.txt lists matching files and overwrites the output file. >> appends, which is not needed here. cat outputs file contents, not names. echo *.txt expands filenames but may not handle many files well.
  3. Final Answer:

    ls *.txt > textfiles.txt -> Option A
  4. Quick Check:

    List files with ls and redirect output [OK]
Quick Trick: Use ls with > to save file list, not contents [OK]
Common Mistakes:
  • Using cat instead of ls
  • Appending instead of overwriting
  • Using echo which may misbehave

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes