adding the date into a file name
Adding the date into a file name helps record system information or provides a backup based on date.
Using the year first allows for easier sorts when you have several files with the same name.
This command: ifconfig -a > network.`date +'%Y_%m_%d'`.txt
produces this: network.2014_07_23.txt
This command: ifconfig -a > `date +'%Y_%m_%d'`-network.txt
produces this: 2014_07_23-network.txt
--> more 2014_12_23-network.txt
lan0 Link encap:Ethernet HWaddr 11:11:11:11:11:11
inet addr:11.111.11.111 Bcast:11.111.11.111 Mask:111.111.111.111
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:58541560 errors:0 dropped:0 overruns:0 frame:0
TX packets:55809888 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:46141382968 (44003.8 Mb) TX bytes:55666523858 (53087.7 Mb)
Interrupt:16
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:196167 errors:0 dropped:0 overruns:0 frame:0
TX packets:196167 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:16439051 (15.6 Mb) TX bytes:16439051 (15.6 Mb)
You could create backup copies manually by typing:
cp /etc/passwd `date +'%Y_%m_%d'`-etc-passwd.txt
output: 2014_12_23-etc-passwd.txt
cp /etc/group `date +'%Y_%m_%d'`-etc-group.txt
output: 2014_12_23-etc-group.txt
cp /etc/hosts `date +'%Y_%m_%d'`-etc-hosts.txt
output: 2014_12_23-etc-hosts.txt
A script could be written to backup a list of files and it could be run periodically via a cronttab.
|