2

I have websites folders in my /home directory of centos 7. i want to copy robot.txt and favicon.ico file in all websites directories.

Websites directory structure are as following:

/home/domain.com/public_html
/home/domain2.com/public_html

I want command which copy robot.txt and favicon in all websites public_html directory from /root/robots.txt and /root/favicon.ico and if file already available on the destination folder then the command will overwrite file.

Many Thanks

2
  • Possible duplicate of Copy and overwrite a file in shell script Commented Jan 1, 2016 at 10:51
  • @hotzst It's not like that question. This question is about how to loop over different source directories. Commented Jan 1, 2016 at 11:22

2 Answers 2

1

You can use find too.

find /home -type d -name public_html -exec cp /root/robots.txt /root/favicon.ico {} \;
Sign up to request clarification or add additional context in comments.

Comments

0

Just use a simple for loop that processes each directory.

for dest in /home/domain*.com/public_html
do
    cp /root/robots.txt /root/favicon.ico $dest
done

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.