Question

My file includes:

a.txt b.txt
c.txt d.txt
e.txt f.txt

Want to do cp a.txt b.txt , cp c.txt d.txt, cp e.txt f.txt

What is the quick oneliner to do this ? I try cat file | xargs -I{} cp {}. but it does not work since it treats the whole thing as one argument.

Was it helpful?

Solution

Please don't call your file file!

cat list | xargs -n 2 cp

Here the switch -n 2 is crucial: it tells xargs to use at most 2 arguments per line.

OTHER TIPS

Why not a regular loop?

while read -r file1 file2 ; do
  cp -- "$file1" "$file2";
done < file
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top