If you google how to append, say, current timestamp to the filename in Bash, almost every suggestion boils down to something really basic along the lines of mv $somefile $somefile_$(date +'Y%-%m-%d'). Technically, this is correct and, yet, this is not what was needed.

Most filenames have extensions that visually identify the files’ type and purpose. If you append a date to the end of the filename, you will effectively remove the filename extension. This is impractical, annoying, and can break things, as illustrated below.

What I really wanted was a new filename looking something like this: /tmp/testfile_2019-11-17.log.gz

Let’s imagine we have a file called unix_server_inventory.xlsx and we want to make a copy of it with the latest modification date appended to the filename. We want to preserve the .xlsx extension. But we also want the same command to work even if the filename has no extension. And here it is:

Here’s a similar example but the filename now comes with full path and the copy is created in the original directory with the last modification timestamp appended.
And another example of renaming multiple files, also by appending the last modification timestamp.

Trying to remember the syntax of these commands is probably impractical. A better solution would be to write a small helper script. Perhaps something like this:

Save it as /var/adm/bin/cpr.sh and then chmod 755 /var/adm/bin/cpr.sh && ln -s /var/adm/bin/cpr.sh /usr/bin/cpr. Syntax would be very basic: