Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

2 Answers 2

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.