Last active
January 1, 2016 12:28
-
-
Save ScreamingDev/8144355 to your computer and use it in GitHub Desktop.
Skeleton Bash Skript
This file contains hidden or 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/bash | |
| function Usage() | |
| { | |
| cat <<-ENDOFMESSAGE | |
| Find old files | |
| $0 [OPTION] PATH | |
| DESCRIPTION | |
| OPTION can be | |
| -m --mtime Modfied time in days (default: +180) | |
| -h --help Displays this help | |
| PATH is a path in which the files will be searched. | |
| AUTHOR | |
| Written by Mike Pretzlaw. | |
| REPORTING BUGS | |
| Report bugs to pretzlaw@gmail.com | |
| COPYRIGHT | |
| Nah. | |
| SEE ALSO | |
| find | |
| ENDOFMESSAGE | |
| exit 1 | |
| } | |
| function Die() | |
| { | |
| echo "$*" | |
| exit 1 | |
| } | |
| function GetOpts() { | |
| branch="" | |
| argv=() | |
| while [ $# -gt 0 ] | |
| do | |
| opt=$1 | |
| shift | |
| case ${opt} in | |
| -m|--mtime) | |
| MTIME="$1" | |
| shift | |
| ;; | |
| -h|--help) | |
| Usage;; | |
| *) | |
| if [ "${opt:0:1}" = "-" ]; then | |
| Die "${opt}: unknown option." | |
| fi | |
| argv+=(${opt});; | |
| esac | |
| done | |
| } | |
| # DEFAULT OPTIONS | |
| MTIME="+180" | |
| # CUSTOM OPTIONS | |
| GetOpts $* | |
| # ARGUMENTS | |
| WORKING_DIR=${argv[0]=.} | |
| echo | |
| read -p "Like to see old things? [y/n] " -n 1 -r | |
| echo | |
| if [[ $REPLY =~ ^[Yy]$ ]] | |
| then | |
| find ${WORKING_DIR} -mtime ${MTIME} | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment