Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

1 Answer 1

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.