Skip to content

Instantly share code, notes, and snippets.

@kanngard
Created November 12, 2024 21:28
Show Gist options
  • Save kanngard/aa071262236b40c867e75d0178a327c9 to your computer and use it in GitHub Desktop.
Save kanngard/aa071262236b40c867e75d0178a327c9 to your computer and use it in GitHub Desktop.
Bash script that copies the file in first argument to a new copy with current date and time as extension
#!/bin/bash
# Copies the file in first argument to a new copy with current date and time as extension. I usually create a backup copy of any file I will tamper to easily revert back to the old one.
# Usage:
# $jbc test.txt
# Copies test.txt into test.txt.yymmdd_HHMMSS, for instance test.txt.210704_112158
# Put in /usr/bin as jbc (just backup copy)
# Do chmod +x /usr/bin/jbc to make it executable
if [ -z "$1" ]
then
echo "Missing argument"
else
d=$(date +%y%m%d_%H%M%S)
echo "Copying $1 to $1.$d..."
cp $1 $1.$d
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment