{"id":4225,"date":"2011-09-22T15:35:53","date_gmt":"2011-09-22T19:35:53","guid":{"rendered":"http:\/\/g33kinfo.com\/info\/?p=4225"},"modified":"2011-09-22T15:35:53","modified_gmt":"2011-09-22T19:35:53","slug":"copy-1-file-to-multiple-cpanel-directories","status":"publish","type":"post","link":"https:\/\/g33kinfo.com\/info\/copy-1-file-to-multiple-cpanel-directories\/","title":{"rendered":"Copy one file to multiple directories"},"content":{"rendered":"<p>Had a client ask to copy a file to multiple public_html directories, came across this little bash script which worked beautifully: <\/p>\n<p><code><br \/>\ntouch copy.sh<br \/>\nvim copy.sh<br \/>\n<\/code><br \/>\nadd this to file, modifying the name of the file to be copied (in this case, test.php)<br \/>\n<code><br \/>\n#\/bin\/bash<br \/>\nfor file in $(find \/home\/* -name public_html -type d)<br \/>\ndo<br \/>\ncp test.php ${file}<br \/>\ndone<br \/>\n<\/code><br \/>\nonce the file is created, make it executable<br \/>\n<code><br \/>\nchmod +x copy.sh<br \/>\n<\/code><br \/>\nNow, just run it as you would any other script<br \/>\n<code><br \/>\nsh copy.sh<br \/>\n<\/code><\/p>\n<p>There is also a method provided by <a href=http:\/\/www.cyberciti.biz\/tips\/linux-unix-shell-batch-copy.html target=\"_blank\" rel=\"noopener noreferrer\">cyberciti.biz<\/a> which works very well also.<\/p>\n<p>Someone also mentioned &#8220;what if you want to remove those same files?&#8221;<br \/>\nThe safest way would be to first run a backup of the account and then use a bash command like so;<br \/>\n<code><br \/>\nfind \/home\/*\/public_html\/ -type f -name \"test.php\" -exec rm -i {} \\;<br \/>\n<\/code><br \/>\nThis will locate the test.php file in all of the public_html directories and prompt you to allow or deny the delete<\/p>\n<p><code><br \/>\n[root@host.domain.com] home >> find \/home\/*\/public_html\/ -type f -name \"test.php\" -exec rm -i {} \\;<br \/>\nrm: remove regular file `\/home\/user1\/public_html\/test.php'? y<br \/>\nrm: remove regular file `\/home\/user2\/public_html\/test.php'? y<br \/>\nrm: remove regular file `\/home\/user2\/public_html\/test\/dir1\/test.php'? n<br \/>\nrm: remove regular file `\/home\/user2\/public_html\/test\/dir2\/test.php'? n<br \/>\nrm: remove regular file `\/home\/user3\/public_html\/test.php'? y<br \/>\nrm: remove regular file `\/home\/user4\/public_html\/test.php'? y<br \/>\nrm: remove regular file `\/home\/user5\/public_html\/test.php'? y<br \/>\nrm: remove regular file `\/home\/user6\/public_html\/test.php'? y<br \/>\nrm: remove regular file `\/home\/user7\/public_html\/test.php'? y<br \/>\nrm: remove regular file `\/home\/user8\/public_html\/test.php'? y<br \/>\nrm: remove regular file `\/home\/user9\/public_html\/test.php'? y<br \/>\nrm: remove regular file `\/home\/user10\/public_html\/test.php'? y<br \/>\n<\/code><\/p>\n<p>This should work for small amounts of accounts searched. If you have a large amount of files with the same name, you may be able to use the -mtime tag to limit the search even further.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Had a client ask to copy a file to multiple public_html directories, came across this little bash script which worked beautifully: touch copy.sh vim copy.sh add this to file, modifying the name of the file to be copied (in this case, test.php) #\/bin\/bash for file in $(find \/home\/* -name public_html -type d) do cp test.php&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/g33kinfo.com\/info\/copy-1-file-to-multiple-cpanel-directories\/\">Read More<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-4225","post","type-post","status-publish","format-standard","hentry","category-cli"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Copy one file to multiple directories - Linux Shtuff<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/g33kinfo.com\/info\/copy-1-file-to-multiple-cpanel-directories\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Copy one file to multiple directories - Linux Shtuff\" \/>\n<meta property=\"og:description\" content=\"Had a client ask to copy a file to multiple public_html directories, came across this little bash script which worked beautifully: touch copy.sh vim copy.sh add this to file, modifying the name of the file to be copied (in this case, test.php) #\/bin\/bash for file in $(find \/home\/* -name public_html -type d) do cp test.php... Read More\" \/>\n<meta property=\"og:url\" content=\"https:\/\/g33kinfo.com\/info\/copy-1-file-to-multiple-cpanel-directories\/\" \/>\n<meta property=\"og:site_name\" content=\"Linux Shtuff\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/fb.me\/g33kinf0\" \/>\n<meta property=\"article:author\" content=\"https:\/\/fb.me\/g33kinf0\" \/>\n<meta property=\"article:published_time\" content=\"2011-09-22T19:35:53+00:00\" \/>\n<meta name=\"author\" content=\"g33kadmin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/drsinger1111\" \/>\n<meta name=\"twitter:site\" content=\"@drsinger1111\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/copy-1-file-to-multiple-cpanel-directories\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/copy-1-file-to-multiple-cpanel-directories\\\/\"},\"author\":{\"name\":\"g33kadmin\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"headline\":\"Copy one file to multiple directories\",\"datePublished\":\"2011-09-22T19:35:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/copy-1-file-to-multiple-cpanel-directories\\\/\"},\"wordCount\":170,\"publisher\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"articleSection\":[\"CLI\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/copy-1-file-to-multiple-cpanel-directories\\\/\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/copy-1-file-to-multiple-cpanel-directories\\\/\",\"name\":\"Copy one file to multiple directories - Linux Shtuff\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#website\"},\"datePublished\":\"2011-09-22T19:35:53+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/copy-1-file-to-multiple-cpanel-directories\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/g33kinfo.com\\\/info\\\/copy-1-file-to-multiple-cpanel-directories\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/copy-1-file-to-multiple-cpanel-directories\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Copy one file to multiple directories\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#website\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/\",\"name\":\"Linux Shtuff\",\"description\":\"Because I have CRS Syndrome...\",\"publisher\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\",\"name\":\"g33kadmin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"contentUrl\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"width\":512,\"height\":512,\"caption\":\"g33kadmin\"},\"logo\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\"},\"description\":\"I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com\\\/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....\",\"sameAs\":[\"https:\\\/\\\/thelinuxreport.com\",\"https:\\\/\\\/fb.me\\\/g33kinf0\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/drsinger1111\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Copy one file to multiple directories - Linux Shtuff","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/g33kinfo.com\/info\/copy-1-file-to-multiple-cpanel-directories\/","og_locale":"en_US","og_type":"article","og_title":"Copy one file to multiple directories - Linux Shtuff","og_description":"Had a client ask to copy a file to multiple public_html directories, came across this little bash script which worked beautifully: touch copy.sh vim copy.sh add this to file, modifying the name of the file to be copied (in this case, test.php) #\/bin\/bash for file in $(find \/home\/* -name public_html -type d) do cp test.php... Read More","og_url":"https:\/\/g33kinfo.com\/info\/copy-1-file-to-multiple-cpanel-directories\/","og_site_name":"Linux Shtuff","article_publisher":"https:\/\/fb.me\/g33kinf0","article_author":"https:\/\/fb.me\/g33kinf0","article_published_time":"2011-09-22T19:35:53+00:00","author":"g33kadmin","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/drsinger1111","twitter_site":"@drsinger1111","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/g33kinfo.com\/info\/copy-1-file-to-multiple-cpanel-directories\/#article","isPartOf":{"@id":"https:\/\/g33kinfo.com\/info\/copy-1-file-to-multiple-cpanel-directories\/"},"author":{"name":"g33kadmin","@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"headline":"Copy one file to multiple directories","datePublished":"2011-09-22T19:35:53+00:00","mainEntityOfPage":{"@id":"https:\/\/g33kinfo.com\/info\/copy-1-file-to-multiple-cpanel-directories\/"},"wordCount":170,"publisher":{"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"articleSection":["CLI"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/g33kinfo.com\/info\/copy-1-file-to-multiple-cpanel-directories\/","url":"https:\/\/g33kinfo.com\/info\/copy-1-file-to-multiple-cpanel-directories\/","name":"Copy one file to multiple directories - Linux Shtuff","isPartOf":{"@id":"https:\/\/g33kinfo.com\/info\/#website"},"datePublished":"2011-09-22T19:35:53+00:00","breadcrumb":{"@id":"https:\/\/g33kinfo.com\/info\/copy-1-file-to-multiple-cpanel-directories\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/g33kinfo.com\/info\/copy-1-file-to-multiple-cpanel-directories\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/g33kinfo.com\/info\/copy-1-file-to-multiple-cpanel-directories\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/g33kinfo.com\/info\/"},{"@type":"ListItem","position":2,"name":"Copy one file to multiple directories"}]},{"@type":"WebSite","@id":"https:\/\/g33kinfo.com\/info\/#website","url":"https:\/\/g33kinfo.com\/info\/","name":"Linux Shtuff","description":"Because I have CRS Syndrome...","publisher":{"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/g33kinfo.com\/info\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547","name":"g33kadmin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","url":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","contentUrl":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","width":512,"height":512,"caption":"g33kadmin"},"logo":{"@id":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif"},"description":"I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com\/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....","sameAs":["https:\/\/thelinuxreport.com","https:\/\/fb.me\/g33kinf0","https:\/\/x.com\/https:\/\/twitter.com\/drsinger1111"]}]}},"_links":{"self":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts\/4225","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/comments?post=4225"}],"version-history":[{"count":0,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts\/4225\/revisions"}],"wp:attachment":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/media?parent=4225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/categories?post=4225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/tags?post=4225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}