使用crontab移动(mv)文件

时间:2017-03-28 19:16:31

标签: crontab

我目前正在使用此功能删除特定文件夹中的文件。

25 * * * * /bin/rm -rf /var/www/website/current/integration/export/*

我希望它能够同时继续使用但不是删除它们我想将它们迁移到export_completed文件夹。那么我应该使用下面的语法,就是这样吗?

25 * * * * mv /var/www/website/current/integration/export/* /var/www/website/current/integration/export_completed/

2 个答案:

答案 0 :(得分:1)

是的,这是正确的。

如果mv不起作用,可能想使用/ bin / mv。

目录也必须存在。

答案 1 :(得分:1)

我绝对不是专家,但是rsync将是更好的选择IMO。这是MAN页面:http://linuxcommand.org/man_pages/rsync1.html

您要完成的内容的一个非常基本的实现将是下面的示例。请注意--remove-source-files的使用,以便您可以在同一命令中移动然后删除。当然,你可以删除它来保存源文件。

25 * * * * rsync --remove-source-files /var/www/website/current/integration/export/ /var/www/website/current/integration/export_completed/

这会将内的所有内容移动到'导出'文件夹到' export_completed'夹。不需要星号。 如果您想要包含“导出”功能。文件夹它的内容,只需删除这样的尾部斜杠

25 * * * * rsync --remove-source-files /var/www/website/current/integration/export /var/www/website/current/integration/export_completed/

阅读手册页以获取更多选项。 Rsync非常强大。

相关问题