{"id":1174,"date":"2024-01-10T21:27:21","date_gmt":"2024-01-10T21:27:21","guid":{"rendered":"https:\/\/labiol.xyz\/?p=1174"},"modified":"2024-01-10T21:27:36","modified_gmt":"2024-01-10T21:27:36","slug":"script-to-copy-data-from-one-directory-to-another-and-at-the-same-time-remove-copied-files-after-30-days","status":"publish","type":"post","link":"https:\/\/www.labiol.xyz\/index.php\/2024\/01\/10\/script-to-copy-data-from-one-directory-to-another-and-at-the-same-time-remove-copied-files-after-30-days\/","title":{"rendered":"Script to copy data from one directory to another and at the same time remove copied files after 30 days."},"content":{"rendered":"\n<p>It is typical that we need to schedule (cron) operations on files for archiving or pre\/post &#8211; processing purpose. Below script is and example, can be use to simplify with customization of your example:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>#!\/bin\/bash\n\nsource_dir=&quot;11&quot;\ndest_dir=&quot;22&quot;\nlog_file=&quot;log.txt&quot;\nnow=$(date +%s)\n\necho &quot;$now START Files to move from $source_dir to $dest_dir&quot; &gt;&gt; $log_file\nfiles_to_move=$(find $source_dir -type f)\necho $files_to_move &gt;&gt; $log_file\nxargs -I{} -n 1 mv {} &quot;$dest_dir&quot; &lt;&lt;&lt; $files_to_move\necho &quot;$now END  move file&quot; &gt;&gt; $log_file\n\necho &quot;$now START Remove files older than 30 days&quot; &gt;&gt; $log_file\nremove_files=$(find $dest_dir -type f -mtime +30)\necho $remove_files &gt;&gt; $log_file\nxargs -I{} rm {} &lt;&lt;&lt; &quot;$remove_files&quot;\necho &quot;$now END -- Remove files&quot; &gt;&gt; $log_file<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>It is typical that we need to schedule (cron) operations on files for archiving or pre\/post &#8211; processing purpose. Below script is and example, can be use to simplify with customization of your example:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,2],"tags":[],"class_list":["post-1174","post","type-post","status-publish","format-standard","hentry","category-linux","category-vmware"],"_links":{"self":[{"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/posts\/1174","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=1174"}],"version-history":[{"count":1,"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/posts\/1174\/revisions"}],"predecessor-version":[{"id":1175,"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/posts\/1174\/revisions\/1175"}],"wp:attachment":[{"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=1174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=1174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=1174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}