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)

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

You need to create an account or log in to post comments to this site.