LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   copy a directory into ... (https://www.linuxquestions.org/questions/linux-software-2/copy-a-directory-into-638740/)

tedtheinsane 04-29-2008 04:22 PM

copy a directory into ...
 
Hello,
How to copy a directory in all directories of a directory.

For exemple, I've a home directory, with 500 user directories approximatly.
And I want to copy one directory in all of these user directories.

Thank you for your help.

Ted

tredegar 04-29-2008 04:38 PM

Quote:

How to copy a directory in all directories of a directory.

For exemple, I've a home directory, with 500 user directories approximatly.
And I want to copy one directory in all of these user directories.
This question doesn't make any sense. Please provide better details.

Rustylinux 04-29-2008 04:47 PM

Quote:

Originally Posted by tedtheinsane (Post 3137055)
Hello,
How to copy a directory in all directories of a directory.

For exemple, I've a home directory, with 500 user directories approximatly.
And I want to copy one directory in all of these user directories.

Thank you for your help.

Ted

So let me get this straight. You have a home directory with 500 user directories so:

Home>
>user1
>user2
to
>user500

and you want to copy 1 directory inside each user's directory to somewhere else. For instance say there is a folder called Tempfolder in all the users directories you would only want to copy that directory to another location?

Or do you want to know the command to copy say user1's directory and all the sub directories in it?

forrestt 04-29-2008 04:59 PM

I was thinking tedtheinsane had a directory /something/here and wanted to copy that into each user's home directory so he would have:

/home/user1/here
/home/user2/here
.
.
.
/home/user500/here

Log in as root and run:
Code:

% tcsh
% cd /home
% foreach USER (`ls`)
foreach? cp -r /something/here $USER
foreach? chown -R $USER $USER/here
foreach? end
% exit

If that isn't what you were wanting, then please clarify.

HTH

Forrest

tedtheinsane 04-30-2008 02:34 AM

Hello,

Thank you for your replies, sorry for my bad english.

I try to explain my problem, with details.

I'm using ubuntu server edition 7.10.

the forrestt's reply is near my problem.

The context :

The directory tree is like this :
/home/a/anton/myspace
/home/a/alphablondy/myspace
/home/b/beettlejuice/myspace
.
.
.
/home/z/zimbawe/myspace

So, in /home/master, there is a directory called 'config' (/home/master/config)

What I want to do :

I want to copy the /home/master/config, in all users 's myspace.
to get this :
/home/a/anton/myspace/config
/home/a/alphablondy/myspace/config
/home/b/beettlejuice/myspace/config
.
.
.
/home/z/zimbawe/myspace/config

Due to the system context, I can use python, shell, or pearl.

Sorry for my english, I hope that my explanations are clear.
I'm linux beginner.

Thank you for your help.
Regards

forrestt 04-30-2008 09:21 AM

Code:

% tcsh
% cd /home
% foreach USER (`ls -d */*`)
foreach? cp -r /home/master/config $USER/myspace
foreach? setenv UN `echo $USER | awk -F\/ '{print $2}'`
foreach? chown -R $UN $USER/myspace/config
foreach? end
% exit

HTH

Forrest

tedtheinsane 05-01-2008 09:15 AM

thank you
 
Hello,

thank you for your help, I try it monday, (I'm on holiday).
Regards

ararus 05-01-2008 11:21 AM

Code:

#!/bin/sh

cd /home

for d in [a-z]; do  # [a-z] to skip "/home/master"
    for ud in d/*; do
        user=${u##*/}  # strip off "d/" (i.e. leave username)
        cp -a /home/master/config $ud/myspace

        # set owner:group from user's home dir
        chown -R $(stat -c "%U:%G" $ud) $ud/myspace/config
    done
done



All times are GMT -5. The time now is 03:48 AM.