I want add the date next to a filename ("somefile.txt"). For example: somefile_25-11-2009.txt or somefile_25Nov2009.txt or anything to that effect
Maybe a script will do or some command in the terminal window. I'm using Linux(Ubuntu).
Thanks in advance.
oh i almost forgot to add that the script or command should update the filename to a new date everytime you want to save the file into a specific folder but still keeping the previous files. So there would be files like this in the folder eventually: filename_18Oct2009.txt , filename_9Nov2009.txt , filename_23Nov2009.txt
a bit more convoluted solution that fully matches your spec
where first 'expr' extracts file name without extension, second 'expr' extracts extension
There's two problems here.
1. Get the date as a string
This is pretty easy. Just use the
date
command with the+
option. We can use backticks to capture the value in a variable.You can change the date format by using different
%
options as detailed on the date man page.2. Split a file into name and extension.
This is a bit trickier. If we think they'll be only one
.
in the filename we can usecut
with.
as the delimiter.However, this won't work with multiple
.
in the file name. If we're usingbash
- which you probably are - we can use some bash magic that allows us to match patterns when we do variable expansion:Putting them together we get:
And if we're less worried about readability we do all the work on one line (with a different date format):
You can use backticks.
Yields: