2

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 1

4

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).

1
  • And if I want to put some text before the date. EX: my_text [date/time]
    – Alex
    Dec 19, 2012 at 17:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .