Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to copy a README.txt file from /root into every /home/{USER}/public_html dir using CLI?

share|improve this question

migrated from stackoverflow.com Jun 27 '12 at 20:38

This question came from our site for professional and enthusiast programmers.

up vote 2 down vote accepted

Use (assuming BASH):

pushd /home;
for file in ./*; do
    cp /root/README.txt /home/$file/public_html/
    chown $file /home/$file/public_html/README.txt
    # this is a cheat, assuming that every user's name equals his home directory
done;
popd
share|improve this answer
    
That covers the copying, but doesn't get to the chown part of the question. – killermist Jun 27 '12 at 22:11
    
@killermist I updated the answer to include chown as well. – H2CO3 Jun 28 '12 at 5:32
    
That looks like what I would have used as a pragmatic solution. Though, yes, that is definitely a cheat and may do the wrong case for some users/dirs. – killermist Jun 28 '12 at 13:40

Shell independent, you can use "find" as in...

find /home -name public_html -maxdepth 2 -exec cp /root/README.html {} \;
share|improve this answer

You must log in to answer this question.