不断search文件整天? batch file?
我想知道我将如何实现这一目标? 我想不断循环一个目录,如果存在的文件删除它?
我可以在bash脚本中做到这一点,或者我需要使用像nodejs的东西吗?
谢谢!
这是你正在寻找的:
首先做:
1)你告诉脚本search一些文件,然后如果存在,删除它们
您可以在下面input如下脚本的文件:
#!/bin/bash LIST_FILE=" /path/to/file1 /path/to/file2 /path/to/file3 /path/to/file4 " for file in $LIST_FILE do if [ -a $file ];then rm -rf $file echo $file is removed fi done
2)删除find
命令创build的所有文件
find /path/to/files >> /path/to/LIST
然后运行脚本并通过说./script.sh
调用它
#!/bin/bash LIST_FILE=/path/to/LIST for file in $LIST_FILE do if [ -a $file ];then rm -rf $file echo $file is removed fi done
在查找文件的同时,您可以使用脚本:
#!/bin/bash SLEEP_SECS=5 TARGET_FILE="filename" while [ 1 ]; do find /path/to/file -type f -name "$TARGET_FILE" -exec rm {} \; sleep $SLEEP_SECS done
TARGET_FILE可以更改为通配符,例如“* .jpg”。 这将遍历/path/to/file
下的所有目录以查找该文件。 在这个例子中,脚本每5秒运行一次。