在Linux或Unix系统中,可以使用以下脚本来删除指定目录中在某个时间之前的文件:
#!/bin/bash
# This script will remove all files from a directory that are older than a certain time
# Specify the directory you want to clean
DIRECTORY="/path/to/directory"
# Specify the number of days that a file must not have been modified in order to be deleted
DAYS=30
# Change to the directory you want to clean
cd $DIRECTORY
# Remove files older than $DAYS
find . -type f -mtime +$DAYS -exec rm {} \;
该脚本会将指定目录中最近修改时间早于 $DAYS
天的所有文件删除。可以将 DIRECTORY
和 DAYS
变量更改为需要的值,并在执行该脚本前确保具有适当的文件权限。
要运行该脚本,请在终端中导航至包含该脚本的目录,并使用以下命令运行脚本:
$ bash script-name.sh
其中 script-name.sh
是脚本的文件名。