I want to change the behavior of the command date (possibly by setting some proper environment variable) such that it returns its output as if it was invoked as
date --iso-8601=seconds
- Is that possible and how does one accomplish this?
- If one applies the searched-for trick, would it resrict the usage of the command date or would it still be possible to override my desired default behavior?
bash
"alias
es" are the answer. Here's a snippet from my~/.bash_aliases
:The one you want is the last,
tsiso
.Aliases make
date
, among other commands, much more useful. Readman date;info date
and you can do almost anything withdate
.I found another way solving this problem and the similar one for ls:
Add the following lines to the end of
/etc/bash.bashrc
:In order to work for
ls
, you have to log out and log on again.However, if you do it like this particular formatting e.g. to the second, you can't use any other formatting option for
date
any more to override it. It would be rejected as giving more than one formatting option. You can overcome this by prepending a backslash in order tounalias
the commanddate
, e.g.:\date -Ihours
.Still then you have to
unalias
the commanddate
in any script you use. Problems may arise if you use scripts written by someone esle unaware ofdate
being modified!It would be nice if
date
would either also honourTIME_STYLE
or just take the last option for each category if more than one is given. Then this would work seamless... Alas, things are different now!