add a date suffix (or prefix) to your files when copying or archiving

By adding the date to your file, whether as a prefix or suffix, will aid in sorting files.  
As a prefix it'll sort more cleanly but will be less readable as the file names will be longer, if using a browser it might not display.

use it to make an archive copy of critical system files:

(fully resolving the commands in a script is recommended - use which to determine path: -->which cp /usr/bin/cp (YMMV)
  • /usr/bin/cp /etc/group /etc/group.`date +'%Y%m%d-%H'` (the -%H adds the hour - if much activity exists, add %M for minutes as well)
  • /usr/bin/cp /etc/passwd /etc/passwd.`date +'%Y%m%d-%H'`
  • /usr/bin/cp /etc/shadow /etc/shadow.`date +'%Y%m%d-%H'`
  • /usr/bin/cp /etc/resolv.conf /etc/resolv.conf.`date +'%Y%m%d-%H'`
  • /usr/bin/cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.`date +'%Y%m%d-$H'`
See examples and links below: embedded within a script to capture details by date: echo "gathering network info for `hostname`" > network.`date +'%Y_%m_%d'`.txt echo "==================================" >> network.`date +'%Y_%m_%d'`.txt date >> network.`date +'%Y_%m_%d'`.txt echo "==================================" >> network.`date +'%Y_%m_%d'`.txt ifconfig -a | grep Bcast >> network.`date +'%Y_%m_%d'`.txt ifconfig -a | grep HWaddr >> network.`date +'%Y_%m_%d'`.txt defined as a variable within a script: LOG=~/bin/LOGS/Lab_`date +'%Y_%m_%d'`.txt ; export LOG A script using date to move files around: http://johnmeister.com/linux/Scripts/filedate.sh.html

you could create a short "wrapper" script, e.g. "vicp.sh" :

vi vicp.sh #!/bin/bash # vicp.sh - created 2015-09-01 jm - wrapper script to copy files before and after edit /usr/bin/cp $1 $1.before-`date +'%Y%m%d-%H%M'` ################################################################################## # if desired, add an archive Directory path to copied file name, e.g. # uncomment the following 2 lines and comment out the line above this comment # mkdir BAK # /usr/bin/cp $1 BAK/$1.before-`date +'%Y%m%d-%H%M'` ################################################################################## /usr/bin/vi $1 /usr/bin/cp $1 $1.after-`date +'%Y%m%d-%H%M'` ################################################################################## # if desired, add an archive Directory path to copied file name, e.g. # uncomment the following 2 lines and comment out the line above this comment # /usr/bin/cp $1 BAK/$1.after-`date +'%Y%m%d-%H%M'` ################################################################################## /usr/bin/ls -l $1* /usr/bin/ls -l BAK/$1* make it executable and put it in your "bin" directory: ------------------------------------------------ --> chmod 744 vicp.sh ------------------------------------------------ --> which vicp.sh /home/luser/bin/vicp.sh ------------------------------------------------ (you could also drop the .sh, so you'd only have to type: vicp filename )
NOTES: ------------------------------------------------

date suffix easiest to sort and read

date +'%Y_%m_%d-%b' ------------------------------------------------ --> date +'%Y_%m_%d-%b' 2015_09_01-Sep ------------------------------------------------ --> echo "`date +'%Y_%m_%d-%b'`" 2015_09_01-Sep the system will sort from left to right numerically, then alphabetically... sorting first by year, then month (numeric value) and day works well, also by hour (H) and minute (M) ------------------------------------------------

read about the quotes from hell

NOTE: THE QUOTES and other SPECIAL CHARACTERS ARE VERY, VERY IMPORTANT! the first is the DOUBLE QUOTE (or Quotes): " - where there is ONE, there will be another ending that string! the second is a "tick" or "grave" or "accent" - where there is ONE, there will be another ending that string! - it is found under the ~ (tilde) under the key - it tells the shell to execute this string the third is a SINGLE QUOTE: ' - it is part of the command included in the executed string - where there is ONE, there will be another ending that string! the + (plus sign) is used by date to format the output, the output is encapsulated in the single quotes (') the % (percent sign) is used by the date command to display an attribute, e.g. %Y = year as 2015, %y = year as 15, see man date. the %Y provides 2015, the %m provides 09 for the month (%b - SEP), and %d for the date/day as 01. THE quotes in this STRING are correct in form and order, open and close: " / ` / ' then ' / ` / " NOTE: the underscore (_) or dash (-) are used ONLY to enhance readability, without them the date would read: 20150901Sep --> echo "`date +'%Y_%m_%d_%b-%b'`" 2015_09_01_Sep

using a single quote in place of double quote results in displaying the command string

THE quotes in this STRING are WRONG: if you use a single quote (') the command line treats it as a quote instead of a command, while the double quote (") would allow the tick/grave/accent (`) to tell the shell to execute the command within the quoted line. ------------------------------------------------ USE SINGLE QUOTES TO DISPLAY COMMAND STRING --> echo '`date +'%Y_%m_%d_%b'`' `date +%Y_%m_%d_%b`
------------------------------------------------ --> date +'%Y_%m_d%d' 2015_09_d01 ------------------------------------------------ --> date +'%Y_m%m_%d' 2015_m09_01 ------------------------------------------------ --> date +'ymd-%Y_%m_%d' ymd-2015_09_01 ------------------------------------------------ --> date +'%Y_%m_%d-%M' Y = 2015 (year), m = 09 (month in #), d = 01 (date in #), M = 39 (minutes) 2015_09_01-39 ------------------------------------------------ --> date +'%Y_%m_%d-%B' 2015_09_01-September ------------------------------------------------ --> date +'%Y_%m_%d-%b' 2015_09_01-Sep ------------------------------------------------

SEARCH and Navigation TOOL
Google     select a domain to search or visit.
(use back key to return )

johnmeister.com/jeep/sj

FULL SIZE JEEPS
JeepMeister
"Jeep is America's
only real sports car."
-Enzo Ferrari
JohnMeister.com- fotos LinuxMeister- CS
MeisterTech- Diesels FotoMeister.us- fotos
BibleTech- Bible Overview search the the internet
Everett weather - Seattle traffic - pollen count -
NEWS: BBC: Middle East - Israel - Spiegel
NASB/KJV/ES/D - SE Asian Missions - jihad - persecution info
e-books by john:

AMSOIL product guide,
AMSOIL web, or 1-800-956-5695
use customer #283461

Amsoil dealer since 1983

CAMERAS: Nikon Lumix Canon DSLRs Lenses
Computers: Toshiba Toughbook Apple Dell
BOOKS: Auto Repair Diesels BioDiesel
PARTS: Wagoneer J-truck Benz VW
books and computers


SJ - 1962-1991

XJ - 1984-2001

WJ - 1999-2004

KJ - 2002-2007

WK - 2005-2010

Find the recommended
AMSOIL synthetics
for your Jeep

CJ-10A - 1984-1986

Jeepsters

MJ - 1984-1992

Willys - 1946-1965

Other Jeeps (FC)