unset -f cwd function cwd() { declare dirname filename newfile if [[ ! -f "$1" ]]; then echo "No such file: ${1}"; return 1; fi if [[ $# -eq 1 ]]; then dirname="$(/usr/bin/dirname "${1}")" elif [[ $# -eq 2 ]]; then if [[ ! -d "$2" ]]; then echo "No such directory: ${2}"; return 1; fi dirname="${2%/}" else echo "argument error" return 1 fi #/bin/sleep 1 filename="$(/usr/bin/basename "${1}")" newfile="${dirname}/${filename}.$(/bin/date +%Y-%m-%d-%H.%M.%S)" #newfile="${dirname}/${filename}.$(/bin/date +%Z-%Y-%m-%d-%H.%M.%S)" /bin/cp -ip "${1}" "${newfile}" return 0 } cwd file cwd file dir
Never been to CodeSnippets before?
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)
cwd - copy with date (See related posts)
You need to create an account or log in to post comments to this site.
Related Posts
» fsinfo in date shell osx mac apple bash unix file create utility tool system info
» month & day in date shell osx mac bash unix day month cal
» "openterminal" contextual me... in shell osx mac bash unix terminal file folder open cd item menu automator contextual nano
» Changing the Finder "Open Wi... in awk shell osx mac bash unix finder file application open menu contextual lsregister duti with wsupdate
» open or cd to the directory ... in shell osx mac bash unix file open cd directory shortcut
» Delete carriage returns & ne... in shell osx mac bash vi unix vim file sed ed tr newline cr nl carriage return in_place
Snippets (source code soon to be available) developed by Peter Cooper and powered by Ruby On Rails