Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

I made an alias of the date command to display date in the following format:


using this command:

alias date = date +"%Y.%m.%d.%H.%M.%S"

Everything works great, except I want to remove the leading zeroes from the output.

There is no way to make it happen by changing the format. I think it can be done only by piping the output to other commands like sed and awk.

The OS I am running is Ubuntu 12.04.2 LTS.

share|improve this question
There are no trailing zeroes in your example (well, unless you count the 0 in the 10 minutes past the hour, but removing that changes meaning of the timestamp). I take it you mean leading zeroes (zeroes at the beginning of each date component), in which case if you are using a GNU userland @j883376's answer will likely be useful. Otherwise, please specify your environment (userland tools are not the same in all Unix-like OSes, and not even all tools might be available on all such OSes). – Michael Kjörling Jun 14 '13 at 7:25
yes, the title was wrong, though the post was correct, sorry for confusion. – easl Jun 14 '13 at 7:33
No worries. As a general rule, though, it is always good to specify your environment. OS X is different from OpenBSD is different from AIX is different from GNU. By specifying your environment, you don't risk getting answers which won't be of any use to you (like, say, answers suggesting using Linux's /proc when you are trying to solve a problem on OS X). – Michael Kjörling Jun 14 '13 at 7:40
Just a remark: Be aware that removing leading zeros makes it harder to sort by those dates, if you ever need to. – Dubu Jul 4 '14 at 7:18
up vote 20 down vote accepted

As per the GNU date manpage:

   By default, date  pads  numeric  fields  with  zeroes.   The  following
   optional flags may follow '%':

   -      (hyphen) do not pad the field

Therefore you can do

alias date = date +"%Y.%-m.%-d.%-H.%-M.%-S"

and receive

share|improve this answer

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.