Each filename from standard input should be copied to backup/.
Run cp ITEM backup/ for every item; filenames contain no newlines.
Which xargs invocation is correct?
xargs -I REPLACE substitutes each input item at the specified marker, allowing the item to appear before a fixed destination argument.
Detailed explanation
xargs cp backup/Incorrect. The input items are appended after backup/, reversing cp's source and destination order.
Incorrect. The input items are appended after backup/, reversing cp's source and destination order.
xargs -I{} cp '{}' backup/Correct. Each input item replaces {}, producing cp ITEM backup/.
Correct. Each input item replaces {}, producing cp ITEM backup/.
xargs -n 1 backup/ cpIncorrect. It treats backup/ as a command and cp as an argument.
Incorrect. It treats backup/ as a command and cp as an argument.
xargs cp '{}' backup/Incorrect. Without -I, {} is not a replacement marker for ordinary xargs.
Incorrect. Without -I, {} is not a replacement marker for ordinary xargs.
Try it yourself
An example you can run in a temporary verification environment.
printf 'one
two
' | xargs -I{} printf '<%s>
' '{}'Expected result
<one>
<two>Key points
- -I defines a replacement marker
- Run once per input item
- Quote arguments to preserve boundaries
Notes
- Environment: GNU findutils 4.x
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.