handger.blogg.se

Copy file from one server to another in linux
Copy file from one server to another in linux











copy file from one server to another in linux

$ cp xyz dir1 dir2 dir3Ĭp: -r not specified omitting directory 'dir2'Īnother option is to use a for command like one of these to loop through the files: $ for file in file1 file2 file3 $ for file in `ls file?` Only the last directory in the list would get a copy of the file. If you tried a command like the one below, you’d also run into problems. $ echo file1 file2 file3 | xargs -n 2 cp dir1Ĭp: -r not specified omitting directory 'dir1'

copy file from one server to another in linux

Clearly something like the command below will not work. The cp command requires that the final string be the target directory and there’s no way to get xargs to rearrange the commands. One limitation of using xargs to run multiple commands is that the arguments you send to the command using echo will always be tacked to the end of the command that is run, so you can’t use the same technique to copy three files to a single directory. As a comparison, if you ran a command like this, you would see three arguments per line: $ echo Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec | xargs -n 3 The -n ensures that each command will use only one of the arguments provided by the echo command in each of the commands that xargs runs. The -v argument ensures that you will see a list of the files being copied. In this case, the xargs command uses the information you provide (the directory names) to compose each of the three commands required to copy the files to the three directories.

copy file from one server to another in linux

# single file to multiple dirs # multiple files to single dirĪnother option is to use the xargs command to copy your file to multiple directories: $ echo dir1 dir2 dir3 | xargs -n 1 cp -v myfile













Copy file from one server to another in linux