Copy one folder to multiple directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy one folder to multiple directories
# 1  
Old 03-24-2011
Question Copy one folder to multiple directories

Hello,

I have a small question and i hope someone can help me, if i have 200 domains directories in my server under this directory
Quote:
/var/www/
something like
Quote:
/var/www/domain1.com
/var/www/domain2.com
/var/www/domain3.com
/var/www/domain4.com
/var/www/domain5.com
/var/www/domain6.com
now how i can copy one folder i have to this directories?

Thank You
# 2  
Old 03-24-2011
Best bet is to tar up your directory to a file

Code:
tar cvf /path/to/mydir.tar  ./mydir

Then extract the tar into each domain directory:
Code:
for dir in /var/www/domain*
do
     cd $dir
     printf "Extracting to $dir.."
     tar xf /path/to/mydir.tar
     echo
done

# 3  
Old 03-24-2011
Question

Thank you Chubler_XL for replay
I can do that in one job for all domains? not per each domain.
# 4  
Old 03-24-2011
Code:
cd /var/www
find . -type d -a -name "domain*" | xargs -i cp /path/to/your/file/foo.txt {}

this will cp the foo.txt to all subdirs.
# 5  
Old 03-24-2011
Quote:
Originally Posted by GamGom
Thank you Chubler_XL for replay
I can do that in one job for all domains? not per each domain.
The script I posted will do it for all domains (perhaps I should have worded my post more carefully).

If you tar up your directory and type the script as it is above and hit enter you will see:

Code:
$ for dir in /var/www/domain*
>do
>    cd $dir
>    printf "Extracting to $dir.."
>    tar xf /path/to/mydir.tar
>    echo
>done
Extracting to /var/www/domain1.com...
Extracting to /var/www/domain2.com...
Extracting to /var/www/domain3.com...
Extracting to /var/www/domain4.com...
Extracting to /var/www/domain5.com...
Extracting to /var/www/domain6.com...
... and so on ...

[code]
# 6  
Old 03-25-2011
Quote:
Originally Posted by GamGom
Hello,

I have a small question and i hope someone can help me, if i have 200 domains directories in my server under this directory
something like
now how i can copy one folder i have to this directories?

Thank You

This is very small and interesting one .
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to copy particular files from a multiple directories and paste in a new directory?

Dear all I have a multiple directories, say for example org1, org2, org3 ..... org100 and each directory having a file namely dnaG.fasta. I need to copy all the dnaG.fasta file from each directory and paste in another directory fastconcatg. Therefore, my script has to copy dnaG.fasta file from... (5 Replies)
Discussion started by: dineshkumarsrk
5 Replies

2. UNIX for Dummies Questions & Answers

copy file using unix in multiple directories

Hi All Genious, I want to copy a file name XYZ .In a directory /HOME/dir/IXOS1/dir1 which contain multiple directories named not in pattern want to copy the XYZ in all of the directories available on path /HOME/dir/IXOS1/dir1 . Thanks in advance . (2 Replies)
Discussion started by: mumakhij
2 Replies

3. Shell Programming and Scripting

Copy files/directories excluding multiple paterns

my directory structure is like below: basedir\ p.txt q.htm r.java b\ abc.htm xyz.java c\ p.htm q.java rst.txt my requirement is i want to copy all the files and directories... (0 Replies)
Discussion started by: ajayyadavmca
0 Replies

4. Shell Programming and Scripting

Copy files from multiple directories into one directory without overwriting them

I have several directories and all those directories have .dat files in them. I want to copy all those .dat files to one directory say "collected_directory" The problem is I don't want to overwrite files. So, if two file names match, I don't want the old file to be overwritten with a new one. ... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

5. UNIX for Dummies Questions & Answers

Copy multiple files with space to folder

Please help , I am in an urgent need, Please help nawk '{for(i=1;i<=NF;i++){printf("%s\n",$i)}}' filename | sed 's/.*com//' | nawk '/pdf/ {printf("F:%s\n",$0)}' | while read line; do mv $line /images/; done the above script works for without spaces but,My path is also having some space... (3 Replies)
Discussion started by: umapearl
3 Replies

6. Shell Programming and Scripting

Find files of type within folder copy multiple results to different folders

Ok question number two: I'd like to search a directory for multiple file types (rar, txt, deb) and depending on what's found, copy those files to folders named Rar, TextFiles, and Debs. I'm looking for speed here so the faster the script the better. I want it to be a function that I pass 1 argument... (4 Replies)
Discussion started by: DC Slick
4 Replies

7. UNIX for Advanced & Expert Users

Auto copy for files from folder to folder upon instant writing

Hello all, I'm trying to accomplish that if a file gets written to folder /path/to/a/ it gets automatically copied into /path/to/b/ the moment its get written. I thought of writing a shell script and cron it that every X amount of minutes it copies these files over but this will not help me... (2 Replies)
Discussion started by: Bashar
2 Replies

8. UNIX for Dummies Questions & Answers

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... (2 Replies)
Discussion started by: kthatch
2 Replies

9. UNIX for Dummies Questions & Answers

copy multiple files in different directories

I have a report file that is generated every day by a scheduled process. Each day the file is written to a directory named .../blah_blah/Y07/MM-DD-YY/reportmmddyy.tab I want to copy all of this reports to a separate directory without having to do it one by one. However, if I try cp... (3 Replies)
Discussion started by: ken2834
3 Replies

10. Shell Programming and Scripting

Create Folder in Multiple Directories

Hi, I am trying to figure out how to have a folder created in multiple directories. For example /home is where we have over 1500 staff members directories, the staff members name is the name of directory under /home. I need to have a folder called "Desktop" created in every staff members directory.... (15 Replies)
Discussion started by: Stud33
15 Replies
Login or Register to Ask a Question