LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Copying a Directory into Another Directory with Subdirectories (https://www.linuxquestions.org/questions/linux-newbie-8/copying-a-directory-into-another-directory-with-subdirectories-422261/)

oadvantage 03-06-2006 04:41 PM

Copying a Directory into Another Directory with Subdirectories
 
I am delving into Linux.

I want to copy the directory rss into a directory called doc_roots.

Inside of doc_roots are 100's of subdirectories where rss needs to be.

do I use cp? What is the command to install it into every subdirectory within doc_roots?

Thank you!

leonscape 03-06-2006 04:51 PM

So you want to copy the rss directory to all the sub directories of doc_roots?

like this:-

Code:

doc_roots
  |_sub1
  |  |_rss
  |_sub2
  |  |_rss
  ...


oadvantage 03-06-2006 05:18 PM

yes, I need the new RSS to overwrite ALL of the old ones,but there is only one file I need in there.

For example.

The new rss has 3 files
a
b
c

The old has
a
b
c
d

When I over write them will D still remain in the directory since it is not present in the new version of will it be replaced?

leonscape 03-06-2006 05:25 PM

D will still remain, when you copy the directory, it will only replace the files in the old one, it doesn't delete the old directory first and then write the new one. If you want something to do that you'd need a script something like

Code:

#!/bin/sh
SRC=path/to/rss
DST=path/to/doc_roots

cd $DST
dirlist=( `ls -Qd */` )
numdirs=${#dirlist[@]}
for (( i=0; i < numdirs; i++)); do
    currdir=${dirlist[i]}
    cd currdir
    rm -rf rss
    cp -r $SRC ./
done

although that is just a quick example, and may not actually work properly or you.

oadvantage 03-06-2006 05:27 PM

ok thank you!!!

I will try it


All times are GMT -5. The time now is 12:06 PM.