Bash scripts to take incremental backups of your file and compare the current version of a file with the latest backed up version of the same file.
From: Amit
Date: Wed Mar 18 2026 - 06:28:16 EST
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Bash scripts to take incremental backups of your file and compare the
current version of a file with the latest backed up version of the
same file.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------
mybackup.sh
-------------------
#!/bin/bash
# Author: Amit Choudhary
# Email: amitchoudhary0523 AT gmail DOT com
#
# Description: Bash script to take incremental backups of your file.
#
# NOTE: Change the location of 'backup_dir' as per your needs.
#
# Example usage: ./mybackup.sh myfile.c
#
backup_dir=~/backups
date=`date "+%Y-%m-%d-%H-%M-%S"`
set -x
cp $1 $backup_dir/$1.$date
-------------------------------------------------------------------
compare_file_with_lastest_backed_up_version.sh
-------------------------------------------------------------------
#!/bin/bash
# Author: Amit Choudhary
# Email: amitchoudhary0523 AT gmail DOT com
#
# Description: Bash script to compare the current version of a file with the
# latest backed up version of the same file (the latest backed up
# version of the file was made using the bash script -
# 'mybackup.sh').
#
# NOTE: Change the location of 'backup_dir' as per your needs.
#
# Example usage: ./compare_file_with_lastest_backed_up_version.sh myfile.c
#
backup_dir=~/backups
ls -tr -1 $backup_dir/$1.*
last=`ls -tr -1 $backup_dir/$1.* | tail -n 1`
echo
set -x
diff -u $last $1
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------