|
|||||||||
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Copy single file to multiple directories
Please help - I need to copy a single file to multiple directories.
Dir structure: Parent_Directoy Filename1 Child_Directory1 Child_Directory2 Child_Directory3 Child_Directory4 .... So I need to copy Filename1 to all of the Child_Directories. Currently I do it one by one via cp Filename1 Child_Directory1/ cp Filename1 Child_Directory2/ .... |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Create a file (dirfile) containing a list of the directories you want to copy to, one per line
and then use a simple shell script to batch copy the file i.e. #! /bin/sh while read DIR do cp file $DIR done < dirlist |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
Quote:
Code:
find <parent directory> -type d -exec cp <parent directory>/<Filename1> {}/ \;If you have other junk in the parent dir but a pattern that matches all subdirs (eg Child_Directory*), you can do this (bourne/ksh/bash): Code:
for subdir in <parent directory>/<pattern> ; do cp <parent directory>/<Filename1> ${subdir}/ ; done |
| Sponsored Links | ||
|
![]() |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Copy files/directories excluding multiple paterns | ajayyadavmca | Shell Programming and Scripting | 0 | 04-25-2012 02:23 AM |
| Copy files from multiple directories into one directory without overwriting them | shoaibjameel123 | Shell Programming and Scripting | 1 | 08-27-2011 05:14 AM |
| Copy one folder to multiple directories | GamGom | Shell Programming and Scripting | 5 | 03-25-2011 11:10 AM |
| rsync multiple directories into single directory on remote | wreckedred | Shell Programming and Scripting | 1 | 01-31-2011 05:58 PM |
| copy multiple files in different directories | ken2834 | UNIX for Dummies Questions & Answers | 3 | 03-25-2007 02:35 PM |
|
|