Bird
0
0

What does the command ls > output.txt do in a Linux shell?

easy📝 Conceptual Q1 of 15
Linux CLI - Pipes and Redirection
What does the command ls > output.txt do in a Linux shell?
AAppends the list of files and folders to output.txt without deleting existing content.
BDisplays the list of files and folders on the screen and saves it to output.txt simultaneously.
CSaves the list of files and folders in the current directory to output.txt, overwriting it.
DDeletes the output.txt file and lists files in the terminal.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the '>' operator

    The '>' operator redirects standard output to a file, overwriting its content.
  2. Step 2: Apply to the command 'ls > output.txt'

    This command runs 'ls' and writes its output to output.txt, replacing any existing content.
  3. Final Answer:

    Saves the list of files and folders in the current directory to output.txt, overwriting it. -> Option C
  4. Quick Check:

    Overwrite redirection = B [OK]
Quick Trick: Use '>' to overwrite file content, '>>' to append [OK]
Common Mistakes:
  • Confusing '>' with '>>' for appending
  • Thinking output shows on screen and file simultaneously
  • Assuming file is deleted without content

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes