Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
最終更新日からn日経過したファイルを削除
#!/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
You can’t perform that action at this time.