sundot home page unix consulting in the uk and mainland europe (archives)
home | about sundot | unix | downloads | archives›date | archives›subject | external links

Keep permissions/ownership and add ISO datestamp when copying Unix files.

posted by hal 20030429 (archived) | permalink | path | initial version: 20030307

If you are not using a version control system like SCCS or CVS for tracking changing in configuration files, but instead are using the cp or mv commands then avoid blindly doing something like cp /etc/vsfstab /etc/vfstab.bak.
Instead use cp -p /etc/vfstab /etc/vfstab.20030307T1205 ( or to make sure you get the right time: cp -p /etc/vfstab /etc/vfstab.`date +%Y%m%dT%H%M` ).

this way you have a copy of the old /etc/vfstab with

And while I am it - here's some sample Solaris shell code to make it easier for you to script this. It's broken down in pieces to avoid clashing with SCCS control characters. Adding the "T" as a separator adds readability (and is also the correct separator to use according to the standard).

year=`date +%Y`
month=`date +%m`
day=`date +%d`
hour=`date +%H`
minute=`date +%M`
datestamp=$year$month${day}T${hour}$minute

cp -p myfile myfile.$datestamp

Creative Commons
 License Valid HTML 4.01! Valid CSS! Powered by Blosxom!
All content on this website is governed by a Creative Commons license.