CalcGuy
CalcGuy

Reputation: 319

"xargs -a file" to copy files to a folder

I am tring to use xargs -a to read the contents of a file that has a list of filenames in it.

My directory working in looks like:

backups
file1.bak
file2.bak
file3.bak
bakfiles.txt

File name with filenames in it: bakfiles.txt

bakfiles.txt contents:

file1.bak
file2.bak
file3.bak

So essentially I'm trying to copy file1.bak,file2.bak,file3.bak into the folder backups. But using the contents of bakfiles.txt to do so.

I tried:

xargs -a bakfiles.txt | cp {} backups

But I get the error:

cp: cannot stat `{}': No such file or directory

I should mention i also tried:

xargs -a bakfiles.txt cp {} backups

And get the error:

cp: target `file3.bak' is not a directory

Upvotes: 7

Views: 14555

Answers (2)

Marichyasana
Marichyasana

Reputation: 3154

This works for me on Windows 7 using mks toolkit version of 'xargs'

cat bakfiles.txt | xargs -I '{}' cp '{}' backups/'{}'

Upvotes: 12

CalcGuy
CalcGuy

Reputation: 319

From the following link i figured it out:

https://superuser.com/questions/180251/copy-list-of-files

Heres the command:

xargs -a bakfiles.txt cp -t backups

Upvotes: 4

Related Questions