File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33. ` dirname " $0 " ` /functions
44. version
55
6- (cd " ${BASEDIR} /../../../output/${SCHEDULER} " && find . -mindepth 1 -maxdepth 1 -type d -and -not -name ' .*' -printf ' %T@ %f\n' | sort -n | head -n-5 | awk ' {print $2}' | xargs --no-run-if-empty rm -rf) || true
6+ # This script is designed to clean up old directories, specifically keeping the
7+ # five most recently modified ones.
8+
9+ # `$SCHEDULER` is defined in the build-remote script and expands to
10+ # `$PROJECT-$BRANCH-localbuild`
11+
12+ # The `find` command does the following:
13+ # `-mindepth 1` it won't go into sub-subdirectories
14+ # `-maxdepth 1` it won't list the current directory itself
15+ # `-type d` restrict the search to only directories
16+ # `-and -not -name '.*'` exclude dot files (e.g. `.git`, `.cache`)
17+ # `-printf '%T@ %f\n'` print last modification timestamp and filename
18+ #
19+ # Example output from above: `1678886400 dir_name_A`
20+ #
21+ # The `sort` command sorts the output numerically `-n` from oldest to newest
22+ #
23+ # The `head` removes the five newest directories `-n-5`
24+ #
25+ # The `awk` command extracts only the filename
26+ #
27+ # The `xargs` puts each line as the argument of `rm -rf` to remove the remaining
28+ # files
29+
30+ (cd " ${BASEDIR} /../../../output/${SCHEDULER} " && \
31+ find . -mindepth 1 -maxdepth 1 -type d -and -not -name ' .*' -printf ' %T@ %f\n' | \
32+ sort -n | head -n-5 | awk ' {print $2}' | xargs --no-run-if-empty rm -rf) || true
You can’t perform that action at this time.
0 commit comments