It is rare that you want to write something without later wanting to be able to read it back. One common way of organizing files that are generated regularly is by time stamp. If you want to add a timestamp to a file name, you can do so using the date command.
In order for the filenames to sort in the right order, you want the name to go from largest unit to smallest.
Here is an example that creates a filename-suitable string formed Year->second. I remove all unnecessary formatting characters.
date --rfc-3339=seconds | sed -E -e 's! |-|:!!g' |
date --rfc-3339=seconds | sed -E -e 's! |-|:!!g'
The date command reads the current date/time on the local system. –rfc-3339=seconds produces output that looks like this:
$ date --rfc-3339=seconds
2021-11-03 10:57:14-04:00 |
$ date --rfc-3339=seconds
2021-11-03 10:57:14-04:00
In order to keep the regular expression concise inside the sed command, the -E switch tells it to use extended regular expressions, including the alternation character ‘|’ . Thus, the regex ‘ |-|:’ matches a space, a dash, and a colon.