Bird
0
0

You want to run longtask in background but also save its output to log.txt. Which command is correct?

hard📝 Application Q9 of 15
Linux CLI - Process Management
You want to run longtask in background but also save its output to log.txt. Which command is correct?
Alongtask > log.txt & 2>&1
Blongtask & > log.txt
Clongtask > log.txt 2>&1 &
Dlongtask &> log.txt
Step-by-Step Solution
Solution:
  1. Step 1: Redirect output before backgrounding

    Output redirection must happen before & to capture output properly.
  2. Step 2: Analyze options

    longtask > log.txt 2>&1 & correctly redirects stdout and stderr to log.txt and backgrounds the command. longtask & > log.txt places & before redirection, which is invalid. longtask > log.txt & 2>&1 misplaces redirection. longtask &> log.txt redirects both streams but runs in foreground without trailing &.
  3. Final Answer:

    longtask > log.txt 2>&1 & -> Option C
  4. Quick Check:

    Redirect output before & to save logs [OK]
Quick Trick: Redirect output before & to save logs [OK]
Common Mistakes:
  • Placing & before redirection
  • Misordering redirection
  • Using invalid syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes