Bird
0
0

How can you use xargs to run a command on each line of a file list.txt that contains multiple words per line, treating each line as a single argument?

hard📝 Application Q9 of 15
Linux CLI - Pipes and Redirection
How can you use xargs to run a command on each line of a file list.txt that contains multiple words per line, treating each line as a single argument?
Axargs -n 1 < list.txt command
Bxargs -L 1 < list.txt command
Cxargs -d '\n' -n 1 < list.txt command
Dxargs -I {} command {} < list.txt
Step-by-Step Solution
Solution:
  1. Step 1: Understand argument grouping by line

    -L 1 tells xargs to read one line per command, treating the entire line as a single argument, preserving spaces.
  2. Step 2: Compare with other options

    -n 1 splits by whitespace; -d '\n' -n 1 splits by newline but still splits words; -I {} replaces placeholders but splits input.
  3. Final Answer:

    xargs -L 1 < list.txt command -> Option B
  4. Quick Check:

    Run command per line as single arg = -L 1 [OK]
Quick Trick: -L 1 runs command once per input line as single arg [OK]
Common Mistakes:
  • Using -n 1 splits words, not lines
  • Confusing -I or -d with line grouping as single arg

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes