Copying the files in to multiple location using shell script

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copying the files in to multiple location using shell script
# 1  
Old 12-17-2018
Copying the files in to multiple location using shell script

Hi All,

i'm trying to copy the 1.txt files (sample files) in to different path location using the below command.
But it is not copying the files , when i tried for single location able to copy the file.
can any one please assist here.

Please find the below path :-
Code:
/ckr_mkr1/licencekey

file name: 1.txgt

source location : /ckr_mkr1/licencekey/1.txt
Destination location : /ckr_mkr5*/licencekey/1.txt (eg : ckr_mkr3, ckr_mkr4,ckr_mkr5.....ckr_mkr40)

i tried the below command ..but it is not copying in destination location .
using the find commmand
Code:
 find . -type f -name "1.txt" -exec cp "{}" -nR /ckr_mkrlive*/licencekey/

using the copy command
Code:
cp -nr /ckr_mkr*/licencekey/


Moderator's Comments:
Mod Comment DON'T hijack answered and ready to close treads. Open a new one.
Please use CODE tags as required by forum rules!

Last edited by RudiC; 12-17-2018 at 04:33 AM.. Reason: Moved to own new thread. Added CODE tags.
# 2  
Old 12-17-2018
Copying several files to one target directory can be done with cp. Not what you want to do - cp to several targets in one go. You'd need a loop, or e.g.

Code:
echo ckr_mkr3 ckr_mkr4 ckr_mkr5 ckr_mkr40 | xargs -n1 echo cp /p/t/f/1.txt
cp /p/t/f/1.txt ckr_mkr3
cp /p/t/f/1.txt ckr_mkr4
cp /p/t/f/1.txt ckr_mkr5
cp /p/t/f/1.txt ckr_mkr40

where /p/t/f is the "path to file". Supply full target paths if necessary. You could use any other means to provide the targets on stdin, like a file, or an ls command, ...
# 3  
Old 12-17-2018
Quote:
Originally Posted by venkat918
i'm trying to copy the 1.txt files (sample files) in to different path location using the below command.
But it is not copying the files , when i tried for single location able to copy the file.

source location : /ckr_mkr1/licencekey/1.txt
Destination location : /ckr_mkr5*/licencekey/1.txt (eg : ckr_mkr3, ckr_mkr4,ckr_mkr5.....ckr_mkr40)

Code:
find . -type f -name "1.txt" -exec cp "{}" -nR /ckr_mkrlive*/licencekey/

using the copy command
Code:
cp -nr /ckr_mkr*/licencekey/

The find command provides a list of files/directories according to some criteria. To use it you must do it the other way round, i.e. let it provide a list of directories to copy a fixed file to, like this:

Code:
find /start/dir -type d -name "<name-pattern>" -exec cp /a/fixed/file.txt {} \;

If you have a list of files you want to copy you can do that by enclosing the command in a loop:

Code:
for filetocopy in /some/where/* ; do
     find /start/dir -type d -name "<name-pattern>" -exec cp "$filetocopy" {} \;
done

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script for connecting multiple servers and then copying 30 days old files

Shell script for connecting multiple servers and then copying 30 days old files from those server . HI , I have 6 multiple servers pla1,pla2,pla3,pla4,pla5,pla6 1. These six servers have common shared mount point /var/share 2. Running script from /var/share to connect these servers.I... (1 Reply)
Discussion started by: rcroyal88
1 Replies

2. UNIX for Beginners Questions & Answers

List all files and copying to different location

Hello All, I want to copy all files from the list below to a path /qa0/repo/AS/CPY (lnx17:qa0:/qa0/repo/AS>) ls -lrt | grep 'Feb 14' -rw-rw-r-- 1 Ks1 qa0 39 Feb 14 20:11 HHH.dat -rw-rw-r-- 1 Ks1 qa0 32 Feb 14 20:11 HHH1.dat -rw-rw-r-- 1 Ks1 qa0 29 Feb 14 20:11... (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

3. Shell Programming and Scripting

Copying files from various folders to similar folder structure in another location

Hi, I need to write a script the has to copy the files from folders and subfolders to the same folder structure located in another location. Ex: mainfolder1 file1,file2,file3 subfolder1(file1,etc) subfolder2(file1,etc) to another folder location of same folder structure. rsync is not... (7 Replies)
Discussion started by: Raji Perumal
7 Replies

4. Shell Programming and Scripting

Help with copying the list of files from one location to other location

A) I would like to achive following actions using shell script. can someone help me with writing the shell script 1) Go to some dir ( say /xyz/logs ) and then perform find operation in this dir and list of subdir using find . -name "*" -print | xargs grep -li 1367A49001CP0162 >... (1 Reply)
Discussion started by: GG2
1 Replies

5. Shell Programming and Scripting

Help with copying files using shell script

I want to write a shell script to copy a list of files from one directory to another. And while copying it should change the first character of the filename to uppercase and others to lowercase.Below is what i have tried so far. for file in "$@" do if then ufile=`echo $file | sed... (5 Replies)
Discussion started by: vishal.desai
5 Replies

6. Shell Programming and Scripting

Copying files from windows shared location to linux box

Hi, i am new to shell scripting. i have a requirement to copy the files from a windows shared location( vendor will place the files here) to Linux server( my Informatica will pick the files from this location). Files should be loaded in the order in which they were placed in windows box.(Based on... (1 Reply)
Discussion started by: Haari
1 Replies

7. Shell Programming and Scripting

Files copying - [ Listed files alone. ] - Shell script

Hi All, I am doing this for svn patch making. I got the list of files to make the patch. I have the list in a file with path of all the files. To Do From Directory : /myproject/MainDir To Directory : /myproject/data List of files need to copy is in the file: /myproject/filesList.txt ... (4 Replies)
Discussion started by: linuxadmin
4 Replies

8. Shell Programming and Scripting

Shell Script for Copy files from one location to another location

Create a script that copies files from one specified directory to another specified directory, in the order they were created in the original directory between specified times. Copy the files at a specified interval. (2 Replies)
Discussion started by: allways4u21
2 Replies

9. UNIX for Dummies Questions & Answers

copying files from one location to another based on a list

I have a text list of about 3,000 file names (image files), which exist on a server and that I want to copy over to another location. I understand the Unix cp code, but what's the string to have it copy multiple files based on an external list? Many thanks! (4 Replies)
Discussion started by: rebornhonest
4 Replies

10. Shell Programming and Scripting

copying files and Renaming them + shell script

Hi, I have a problem. I have some text files in a folder. The names can be like: emp.txt emp1.txt emp3.txt 32emp4.txt What i need is i have to copy all the files which have "emp" string in their filename to a different folder and those file names... (7 Replies)
Discussion started by: pathanjalireddy
7 Replies
Login or Register to Ask a Question