我正在编写一个脚本来删除超过1周的一些构建工件.
这些文件的名称形式为artifact-1.1-200810391018.exe.
如何仅删除大于1周的文件,不包括日期时间戳结束时的小时和分钟时间?
目前它正在删除目录中的所有文件.
#!/bin/sh NIGHTLY_LOCATIONS=( "/foo" "/bar" ) ARTIFACT_PREFIX="artifact-*-" NUM_TO_KEEP=7 for home in $(seq 0 $((${#NIGHTLY_LOCATIONS[@]} - 1))); do echo "Removing artifacts for" ${NIGHTLY_LOCATIONS[$location]} for file in `find ${NIGHTLY_LOCATIONS[$location]} -name "$ARTIFACT_PREFIX*"`; do keep=true for day in $(seq 0 $((${NUM_TO_KEEP} - 1))); do date=`date --date="$day days ago" +%Y%m%d` echo $(basename $file ".exe") " = " $ARTIFACT_PREFIX$date if [ "$(basename $file ".exe")" != "$ARTIFACT_PREFIX$date" ]; then keep=false fi done if [ !$keep ]; then echo "Removing file" rm -f $file fi done done
VonC.. 7
你的意思是,有些东西:
find /path/to/files -name "artifact*" -type f -mtime +7 -exec rm {} \;
?
你的意思是,有些东西:
find /path/to/files -name "artifact*" -type f -mtime +7 -exec rm {} \;
?