File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3838 " env-vars-echo" ,
3939 " env-vars-load" ,
4040 " find-symlinks-to-in" ,
41+ " folder-delete-items-older-than-days" ,
4142 " git-currentbranch" ,
4243 " git-localchanges" ,
4344 " git-remotechanges" ,
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ # ---------------------------------------------------------------------
4+ usage () {
5+ cat << EOT
6+
7+ ${0##*/ }
8+ Deletes files (only) within the given folder that have a
9+ modified time older than the optional second argument.
10+
11+ Usage:
12+ bin/${0##*/ } <path> [days]
13+
14+ \$ 1 = The root filesystem path to search. Will be
15+ provided to \` find\` .
16+ \$ 2 = Optional last modified age in days for files that should
17+ be kept. Files older than (today - \$ 2 eu days) will be
18+ deleted. Default = 30 days.
19+
20+ Environment Variables:
21+ (none)
22+
23+ EOT
24+
25+ exit ${1:- 0} # Exit with code 0 unless an arg is passed to the method.
26+ }
27+ if [ " $1 " = ' -h' ]; then
28+ usage
29+ fi
30+
31+ # Process command line args.
32+ if [ -n " $1 " ]; then
33+ SEARCH_PATH=$1
34+ else
35+ echo " !! No path provided. Aborting."
36+ usage 1
37+ fi
38+ if [ -n " $2 " ]; then
39+ AGE_DAYS=$2
40+ else
41+ AGE_DAYS=30
42+ fi
43+
44+
45+ find " ${SEARCH_PATH} " -type f -mtime +${AGE_DAYS} -print0 | xargs -0 rm -f
You can’t perform that action at this time.
0 commit comments