summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Laska <jlaska@redhat.com>2011-05-12 11:46:30 -0400
committerJames Laska <jlaska@redhat.com>2011-05-12 11:46:30 -0400
commitca59d12f120ddd6eedf6425e08c3378de8507614 (patch)
tree6c32e1237d35e44868223e49d7f7adac13aeb028
parentc6b2a9c7fb0e5b48bc626aaa5072163b5c6c894a (diff)
downloadscripts-ca59d12f120ddd6eedf6425e08c3378de8507614.tar.gz
scripts-ca59d12f120ddd6eedf6425e08c3378de8507614.tar.xz
scripts-ca59d12f120ddd6eedf6425e08c3378de8507614.zip
compress_large_files: Add support for -mmin find option
-rwxr-xr-xcompress_large_files13
1 files changed, 10 insertions, 3 deletions
diff --git a/compress_large_files b/compress_large_files
index 5165a52..06faf11 100755
--- a/compress_large_files
+++ b/compress_large_files
@@ -14,7 +14,8 @@ usage() {
Where <options> include:
-d DIRECTORY - Specify directory to recurse
- -s MINSIZE - Minimum file size in MiB to compress
+ -s MINSIZE - Only compress files larger than MINSIZE
+ -a AGE - Only compress files modified more than AGE minutes ago (default 60)
-n - Don't make changes, just display
"
exit 1
@@ -27,11 +28,13 @@ COMPRESS_CMD="gzip -v --suffix ${COMPRESS_SUFFIX}"
# Process cmdline arguments
DRYRUN=0
MINSIZE=""
+MINAGE=60
COMPRESS_DIR=""
-while getopts "ns:d:h" options; do
+while getopts "ns:a:d:h" options; do
case $options in
n ) DRYRUN=1 ;;
s ) MINSIZE=$OPTARG ;;
+ a ) MINAGE=$OPTARG ;;
d ) COMPRESS_DIR=$OPTARG ;;
\?|h ) usage ;;
* ) usage ;;
@@ -41,9 +44,13 @@ done
# Validate input
test -z "${COMPRESS_DIR}" && error "Missing -d argument"
test -z "${MINSIZE}" && error "Missing -s argument"
+test -z "${MINAGE}" && error "Missing -a argument"
# Find files to compress using the supplied arguments
-find "${COMPRESS_DIR}" -type f -not -name "*${COMPRESS_SUFFIX}" -size +"${MINSIZE}"M |
+# - larger than MINSIZE Mib
+# - older than MINAGE minutes
+# - not already compressed
+find "${COMPRESS_DIR}" -type f -not -name "*${COMPRESS_SUFFIX}" -mmin +"${MINAGE}" -size +"${MINSIZE}"M |
while read line
do
if [ ${DRYRUN} -eq 1 ]; then