Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Create a backup of a file with the timestamp before the extension
- function bkup {
- target=$1
- full_name=$(basename "$target")
- file_path=$(dirname "$target")
- file_extn="${full_name##*.}"
- file_name="${full_name%.*}"
- backup_file="${file_path}/${file_name}.${timestamp}.${file_extn}"
- if [[ ! -f $target ]]; then
- echo "It doesn't look like ${target} is a regular file"
- exit 1
- fi
- timestamp=$(date +%m.%d.%y.%s)
- echo -n "Backing up '${target}' to '${backup_file}'... "
- cp "${target}" "${backup_file}" &>/dev/null
- if [[ $? -gt 0 ]]; then
- echo "Error"
- else
- echo "Success"
- fi
- }
Advertisement
Add Comment
Please, Sign In to add comment