使用 crontab 移动 (mv) 文件
Move (mv) files with 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/
是的,没错。
如果 mv 不起作用,可能要使用 /bin/mv。
目录也必须存在。
我绝对不是专家,但是 rsync
是 IMO 更好的选择。这是手册页: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' 中的所有内容移动到 'export_completed' 文件夹。不需要星号。
如果你想包含 'export' 文件夹 和 它的内容,只需像这样删除尾部斜杠
25 * * * * rsync --remove-source-files /var/www/website/current/integration/export /var/www/website/current/integration/export_completed/
阅读手册页了解更多选项。 rsync 真的很强大。
我目前正在使用它从特定文件夹中删除文件。
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/
是的,没错。
如果 mv 不起作用,可能要使用 /bin/mv。
目录也必须存在。
我绝对不是专家,但是 rsync
是 IMO 更好的选择。这是手册页: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' 中的所有内容移动到 'export_completed' 文件夹。不需要星号。 如果你想包含 'export' 文件夹 和 它的内容,只需像这样删除尾部斜杠
25 * * * * rsync --remove-source-files /var/www/website/current/integration/export /var/www/website/current/integration/export_completed/
阅读手册页了解更多选项。 rsync 真的很强大。