Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux commands to copy one file to many files

Tags:

linux

cp

Is there a one-line command/script to copy one file to many files on Linux?

cp file1 file2 file3 

copies the first two files into the third. Is there a way to copy the first file into the rest?

like image 543
user121196 Avatar asked Mar 03 '12 22:03

user121196


People also ask

How do I copy multiple files with the same name in Linux?

cp can copy a single file to a different filename (i.e. "rename" the destination), but there is no way to specify different filenames for multiple files. So the answer is no, cp can not rename when copying multiple files. -t is partcicularly useful when used with, e.g., ... | xargs cp -t destdir/ or find ...

How do I copy a file to another file in Linux?

The Linux cp command is used for copying files and directories to another location. To copy a file, specify “cp” followed by the name of a file to copy. Then, state the location at which the new file should appear. The new file does not need to have the same name as the one you are copying.

How do I copy a file to multiple directories in Linux?

The another way to copy files to multiple locations is by using echo , xargs and cp commands. As you already know, the cp command is used to copy the files and directories, and xargs command is used to build and execute command lines from standard input.

How do I copy a group of files in Linux?

cp (copy) - The cp command is used to copy files or directories in the Linux system. If we want to copy a file from a source directory and paste it into another destination directory then we have to use the cp command.


1 Answers

Does

cp file1 file2 ; cp file1 file3 

count as a "one-line command/script"? How about

for file in file2 file3 ; do cp file1 "$file" ; done 

?

Or, for a slightly looser sense of "copy":

tee <file1 file2 file3 >/dev/null 
like image 51
ruakh Avatar answered Sep 20 '22 15:09

ruakh