Pender and Hollywood, where for art thou?
Not postin’, that’s where.
Here’s a wonderful little utility I coded for Unix systems yesterday that compresses the crap out of every file in a folder. You pass in the directory as parameter 1, and you can optionally pass in a second parameter to say how many days of data back you do NOT want to compress. I call it bzipdir!
Syntax: ./bzipdir /the/directory/duh 14
That will compress everything in /the/directory/duh that is older than 14 days, so all your current stuff stays not compressed.
FYI, I can’t get stupid wordpress to properly format this crap without having to do a pile of manual work. ugh.
Here tis!!
#!/bin/ksh
# Pender 20060719 - Bzip2 files individually in a directory passed in as a parameter
if [ $# -lt 1 ];then
print "Missing required parameter."
print "Usage: bzipdir (directory to bzip files individually) [days]"
print "Example: ./bzipdir /home/orleans/dbadmin/whatever/dir 60"
exit 1
elif [ $# -gt 2 ];then
print "Too many parameters."
print "Usage: bzipdir (directory to bzip files individually) [days]"
print "Example: ./bzipdir /home/orleans/dbadmin/whatever/dir 60"
exit 1
fi
dir=$1
days=${2:-0}
print "Directory to bzip files individually: $dir"
if [ $days -eq 0 ];then
for curfile in `ls -l $dir | grep ^- | awk -F" " '{print $9}'`;do
print "curfile: $curfile"
bzip2 $dir/$curfile
if [ $? -ne 0 ];then
print "Error!"
print "bzip2ing $dir/$curfile failed"
exit 1
fi
done
elif [ $days -gt 0 ];then
find $dir -name "*" -mtime +$days -prune -type f -print -exec bzip2 "{}" \;
if [ $? -ne 0 ];then
print "Error!"
print "bzip2ing $dir/$curfile failed"
exit 1
fi
fi
exit 0