copy a file to multiple directories with *

 [root@webmail mnt]# echo /home/*/public_html/ | xargs -n 1 cp -v read.html

‘read.html’ -> ‘/home/korbceramic/public_html/read.html’

‘read.html’ -> ‘/home/serverfix/public_html/read.html’

‘read.html’ -> ‘/home/suntouchpolypack/public_html/read.html’

‘read.html’ -> ‘/home/vabopaliya/public_html/read.html’

[root@webmail mnt]# cd /home/korbceramic/public_html/


reminder this will replace the prev file and copy newer ones

While copying file to 2-3 directories, you can do it easily with multiple commands. But think, if you have to copy this to large number of directories at a time. For example, I have a WHM/cPanel server with large number of account and want to place a file to each accounts public_html directory. We can do this in single command as:

echo /home/*/public_html/ | xargs -n 1 cp -v ~/tecadmin.txt 

[output]
'/root/tecadmin.txt' -> '/home/user1/public_html/tecadmin.txt'
'/root/tecadmin.txt' -> '/home/rahul/public_html/tecadmin.txt'

Comments

Popular posts from this blog

cpanel exam CPSP Answers

How to install zimbra collaboration suite 8.8.11 on CentOS 7

awstats installation