I am saving a stream in my HDD. I'd like to copy the file periodically into a subfolder backup such that the older versions of the the file are not deleted.

Simply put

  1. Assume the original file is somefolder/data.
  2. The first backup should be somefolder/backup/data.1
  3. The second backup should be somefolder/backup/data.2
  4. This process should continue in an interval of t minutes/seconds

How do I go about doing this?

2 Answers 2


oneline bash command finally did the trick

while : ; do cp -vt ./backup/ --backup=numbered -- data; sleep 5; done

The only qualm for this seems to be it saves the backups as data.~n~


Basic, adapt as necessary:

while true; do
  while ((x>1)); do
      echo mv somefolder/backup/data.$((x-1)) somefolder/backup/data.$x
  cp somefolder/data somefolder/backup/data.1
  sleep 60
  • this overwrites the older files such that there are only 2 backups at any given point of time
    – 3l4ng
    May 6, 2014 at 8:21
  • I assumed you did not want infinite backups (?). I've modified the answer to include a loop where x control the number of backups.
    – bain
    May 6, 2014 at 10:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .