LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-29-2008, 05:22 PM   #1
tedtheinsane
LQ Newbie
 
Registered: Dec 2006
Location: kernel 2.6
Distribution: Fedora, ubuntu
Posts: 10

Rep: Reputation: 0
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
 
Old 04-29-2008, 05:38 PM   #2
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Testing"
Posts: 6,111

Rep: Reputation: 413Reputation: 413Reputation: 413Reputation: 413Reputation: 413
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.
 
Old 04-29-2008, 05:47 PM   #3
Rustylinux
Member
 
Registered: Mar 2006
Posts: 177

Rep: Reputation: 30
Quote:
Originally Posted by tedtheinsane View Post
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?
 
Old 04-29-2008, 05:59 PM   #4
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
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
 
Old 04-30-2008, 03:34 AM   #5
tedtheinsane
LQ Newbie
 
Registered: Dec 2006
Location: kernel 2.6
Distribution: Fedora, ubuntu
Posts: 10

Original Poster
Rep: Reputation: 0
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

Last edited by tedtheinsane; 04-30-2008 at 03:35 AM.
 
Old 04-30-2008, 10:21 AM   #6
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
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
 
Old 05-01-2008, 10:15 AM   #7
tedtheinsane
LQ Newbie
 
Registered: Dec 2006
Location: kernel 2.6
Distribution: Fedora, ubuntu
Posts: 10

Original Poster
Rep: Reputation: 0
thank you

Hello,

thank you for your help, I try it monday, (I'm on holiday).
Regards
 
Old 05-01-2008, 12:21 PM   #8
ararus
Member
 
Registered: Mar 2008
Location: UK
Distribution: Slackware
Posts: 56

Rep: Reputation: 15
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy Directory Structure Only ronin1 Linux - Newbie 10 06-08-2013 07:23 AM
Copy directory execlude directory linux2man Linux - General 3 12-12-2006 08:52 AM
How do I copy from one directory to another in Terminal? beatupbilly Linux - Newbie 2 08-02-2006 02:58 AM
How to copy one directory to another directory thru PHP? green_njk Programming 1 01-06-2006 07:55 AM
copy files from directory to directory without subfile ALInux Linux - General 2 06-03-2005 12:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration