Created
April 17, 2015 21:12
-
-
Save LTGIV/bc26862d8b1db6067d82 to your computer and use it in GitHub Desktop.
Quick way to trash CakePHP v2 application cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
: <<'!COMMENT' | |
CakePHP Cache Flush v201504172014 | |
Louis T. Getterman IV (@LTGIV) | |
www.GotGetLLC.com | www.opensour.cc/programming/php/frameworks/cakephp/v2/cache/flush | |
Thanks: | |
http://stackoverflow.com/questions/15065010/how-to-do-for-each-file-using-find-in-shell-bash | |
http://stackoverflow.com/questions/1590297/shell-scripting-using-bash-with-xargs | |
http://www.cyberciti.biz/faq/linux-bash-delete-all-files-in-directory-except-few/ | |
!COMMENT | |
################################################################################ | |
SOURCE="${BASH_SOURCE[0]}" # Dave Dopson, Thank You! - http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in | |
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink | |
SCRIPTPATH="$( cd -P "$( dirname "$SOURCE" )" && pwd )" | |
SOURCE="$(readlink "$SOURCE")" | |
[[ $SOURCE != /* ]] && SOURCE="$SCRIPTPATH/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located | |
done | |
################################################################################ | |
SCRIPTPATH="$( cd -P "$( dirname "$SOURCE" )" && pwd )" | |
SCRIPTNAME=`basename "$SOURCE"` | |
PARENTPATH="$( cd "$(dirname "${SCRIPTPATH}/../../")" ; pwd -P )" | |
################################################################################ | |
cakeAppPath="${1-"$PARENTPATH/apps/MYAPP"}" | |
################################################################################ | |
# Delete all files except empty (for Git), .DS_Store (for OSX), and *.log | |
echo "[Deleting Files]" | |
find "$cakeAppPath/tmp" \ | |
-type f \ | |
-name "*" \ | |
-not -name "empty" \ | |
-not -name "*.log" \ | |
-not -name ".DS_Store" \ | |
-print0 \ | |
| xargs -0 rm -fv | |
echo; | |
# Truncate log files | |
echo "[Truncating Files]" | |
find "$cakeAppPath/tmp/logs" -type f -iname "*.log" -print0 | while IFS= read -r -d $'\0' line; | |
do | |
echo "$line" | |
echo -n '' > "$line" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment