Skip to content

Commit 7877c50

Browse files
authored
Merge pull request #1773 from larsewi/clean-results
ENT-12600: clean-results: Documented script with comments
2 parents 1fde9ed + 43411e5 commit 7877c50

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

build-scripts/clean-results

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,30 @@
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

0 commit comments

Comments
 (0)