Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

Linux Command to Copy Multiple Files?

Status
Not open for further replies.

emaq

Member level 4
Joined
Sep 17, 2015
Messages
78
Helped
0
Reputation
0
Reaction score
1
Trophy points
1,288
Activity points
2,001
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.
 

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
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
 

If there is no path in the destination file names, they should go to the current directory.
 

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.
 

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?
 

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
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top