mv statistics backup-xx && mkdir statistics
This would rename the existing
statistics directory to
backup-xx, and if that succeeds it would carry on to create a new
For a more atomic operation, consider creating a directory
statistics-001 (or similar, maybe by replacing
001 with today's date in a suitable format), and a symbolic link to it called
ln -s statistics-001 statistics
When you want to "rotate" this so that new data goes into a clean directory, create the directory first, then recreate the
statistics link to it:
ln -sf statistics-002 statistics
mv statistics-001 backup-001
This way, any program writing to the
statistics directory (i.e. the directory that this symbolic link points to) will never1 fail to find it.
If you need special permissions or ownership set on the directory that
statistics points to, set these before (re-)creating the link.
1Or rather, this way, the time that a program would be without a valid target directory is minimized as much as practically possible using standard Unix tools.