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

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

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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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