Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

Linux Command to Copy Multiple Files?

emaq

Member level 2
Joined
Sep 17, 2015
Messages
50
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
519
In CentOS, I want to copy a rubric.docx file to multiple files with names such as F20161368.docx, F20161981.docx, F20161983.docx... from a list of names in a MS Excel or text file.

Please help with a command or script to do that.
 

std_match

Advanced Member level 4
Joined
Jul 9, 2010
Messages
1,083
Helped
409
Reputation
818
Reaction score
404
Trophy points
1,363
Location
Sweden
Activity points
8,263
Code:
cat destination_file_list.txt | xargs -n 1 cp source_file
Edit: the "-T " option for cp isn't needed, so I removed it.
 
Last edited:
  • Like
Reactions: emaq

    emaq

    points: 2
    Helpful Answer Positive Rating

emaq

Member level 2
Joined
Sep 17, 2015
Messages
50
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
519
Code:
cat destination_file_list.txt | xargs -n 1 cp source_file
Edit: the "-T " option for cp isn't needed, so I removed it.
Where the files have been copied?... I couldn't find them!
I used the following command...
cat /home/user/Desktop/temp/list.txt | xargs -n 1 cp /home/user/Desktop/temp/rubric.docx
 

std_match

Advanced Member level 4
Joined
Jul 9, 2010
Messages
1,083
Helped
409
Reputation
818
Reaction score
404
Trophy points
1,363
Location
Sweden
Activity points
8,263
If there is no path in the destination file names, they should go to the current directory.
 

dick_freebird

Advanced Member level 5
Joined
Mar 4, 2008
Messages
6,726
Helped
1,982
Reputation
3,968
Reaction score
1,799
Trophy points
1,393
Location
USA
Activity points
53,934
If it were me, I'd get the file list as plain text from
"wherever", and edit it into a shell script with vi / vim.
Then run it.

:1,$s/^/cp \/home\/user\/Desktop\/temp\/rubric.docx &/

would make

F20161983.docx

into

cp /home/user/Desktop/temp/rubric.docx F20161983.docx


and all the other lines in the file, similarly.


I'm sure there's an elegant way to do it but I'd rather
get it done that figure out pipes and whatnot. You could
probably do a foreach x( {list} ) or something. But I find
it easier to work on a script in a text editor, than to get
100.00% correct command line typed out, first try.
 

emaq

Member level 2
Joined
Sep 17, 2015
Messages
50
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
519
If there is no path in the destination file names, they should go to the current directory.
the command worked... thanks. However, the files created have no extension. How to have .docx extension of the copied files?
 

std_match

Advanced Member level 4
Joined
Jul 9, 2010
Messages
1,083
Helped
409
Reputation
818
Reaction score
404
Trophy points
1,363
Location
Sweden
Activity points
8,263
the command worked... thanks. However, the files created have no extension. How to have .docx extension of the copied files?
The file names will be exactly as in the "destination_file_list.txt".

If the file names in the list don't have the .docx extension, you can add it with the "sed" command:

Code:
cat destination_file_list.txt | sed "s/$/\.docx/" | xargs -n 1 cp source_file
 

Toggle Sidebar

Part and Inventory Search


Welcome to EDABoard.com

Sponsor

Sponsor

Design Fast


×
Top