Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos shell脚本在日期删除_Macos_Bash_Shell_Cron - Fatal编程技术网

Macos shell脚本在日期删除

Macos shell脚本在日期删除,macos,bash,shell,cron,Macos,Bash,Shell,Cron,我可能会使用cron来运行上面的脚本,但我认为可能有更好的方法 因为我想包括这一部分 #!/bin/bash NOW=$(date +"%Y-%m-%d-%H-%M-%S") FILE="STUFF_2BeDeleted_$NOW.txt" echo "Writing txt data to STUFF_2BeDeleted_$NOW.txt file, please wait..." # rest of script find /path/to/directory/stuffzMovin/ -

我可能会使用cron来运行上面的脚本,但我认为可能有更好的方法 因为我想包括这一部分

#!/bin/bash
NOW=$(date +"%Y-%m-%d-%H-%M-%S")
FILE="STUFF_2BeDeleted_$NOW.txt"
echo "Writing txt data to STUFF_2BeDeleted_$NOW.txt file, please wait..."
# rest of script
find /path/to/directory/stuffzMovin/ -type f -mmin +10 -print0 | xargs -0 ls -ltr > /path/to/directory/STUFF_2BeDeleted_$NOW.txt
mv -v /path/to/directory/stuffzMovin/* /path/to/directory/.hiddenStuffz/
如何每两周实现一次(#rm-rf/path/to/directory/.hiddenStuffz)
只需将它写入另一个脚本,并在cron中运行它,或者我可以在一个脚本中实现这一切。

您可以使用您的脚本来实现这一点。在您的crontab中:

  • 第一行:把你的脚本
  • 第二行:在月日的“/bin/rm-rf/path/to/directory/.hiddenStuffz”行中加上1,15
当您使用cron时,应该注意可变环境

#rm -rf /path/to/directory/.hiddenStuffz