Often when working with shell scripts you’ll need to append a date or time stamp to a file name (e.g. archiving logs).
The following will generate the current date in the format
YYYYMMDD which is the most suitable format for chronologically sorting files.
Similarly the following will output the current time in the format
HH24MMSS (24 hour time)
Combining the two will give you a date-time stamp (this example adds a dash between the date and time to separate them).
You can use these commands in your shell scripts. For example, this will create an empty test file called
touch test.txt.`date +%Y%m%d-%H%M%S`