Skip to content

Commit

Permalink
✨ cp-date: make a backup with last modified date in copy fname
Browse files Browse the repository at this point in the history
  • Loading branch information
WillForan committed Nov 13, 2024
1 parent 67bea4f commit 449c627
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cp-date
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
usage() { echo -e "Make copy of file with last change date at end.\nUSAGE: $0 myfile # makes myfile.YYYY-MM-DD"; }
[[ $# -eq 0 || $* =~ ^-+h ]] && usage && exit 1
while [ $# -gt 0 ]; do
infile="${1:?file to copy}"; shift
[ ! -r "$infile" ] && warn "Bad file: '$infile'" && continue

newname=$infile.$(find "$infile" -printf '%CF')
[ -r "$newname" ] && warn "$newname aleady exists!. remove and rerun to replace" && continue

dryrun cp "$infile" "$newname"
done

0 comments on commit 449c627

Please sign in to comment.