Created
August 28, 2013 10:04
-
-
Save valvallow/6364404 to your computer and use it in GitHub Desktop.
最終更新日からn日経過したファイルを削除
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
#!/bin/sh | |
usage () | |
{ | |
echo 'usage: '`basename "$0"` '[-h|-d] days target-directory' | |
echo ' options: ' | |
echo ' -h : show this help' | |
echo ' -d : force delete' | |
exit; | |
} | |
if [ "$#" -le 1 ] ; then | |
usage | |
fi | |
while getopts hd OPT | |
do | |
case $OPT in | |
"h" ) usage ;; | |
"d" ) FORCE_DELETE="TRUE" ; shift ; | |
esac | |
done | |
TARGET_DIR_PATH=`realpath "$2"` | |
TARGET_FILE_LIST=`find "$TARGET_DIR_PATH" -mtime +"$1"` | |
for TARGET_FILE in "$TARGET_FILE_LIST" | |
do | |
echo "$TARGET_FILE" | |
if [ "$FORCE_DELETE" = "TRUE" ]; then | |
rm -rf $TARGET_FILE | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment