How to echo date and time like this [day-month-year/hour-minutes-seconds] including "[" and "/". I also need to redirect it in a file. Thanks
1 Answer
Look at date --help
:
Usage: date [OPTION]... [+FORMAT]
and it gives a list of date format specifiers.
To get the format you want (assuming you want local time, and all fields padded with zeroes, 24-hour time), use the format specifier [%d-%m-%Y/%H-%M-%S]
. That is, run
username@host:/path$ date '+[%d-%m-%Y/%H-%M-%S]'
[19-12-2012/17-16-16]
To redirect to a file, use standard shell redirection (date '+[%d-%m-%Y/%H-%M-%S]' > filename
to overwrite the file, or date '+[%d-%m-%Y/%H-%M-%S]' >> filename
to append).
-
And if I want to put some text before the date. EX: my_text [date/time]– AlexDec 19, 2012 at 17:35