Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 4 down vote accepted

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]'

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

share|improve this answer
And if I want to put some text before the date. EX: my_text [date/time] – Alex Dec 19 '12 at 17:35
I find thank you very much – Alex Dec 19 '12 at 17:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.