Skip to content
Advertisement

“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

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement