unix

Removing Leading Zero in Date Format

The date command allows us to display the current date and time.

$ date
Sun May 26 01:16:25 +08 2019

Most importantly, we can format the date and time using specifications from strftime. Now, assume we want a format like 26/5.

$ date '+%d/%m'
26/05

Notice that %m yielded 05 instead of 5. This is because the values for %m are 01 - 30. So, to remove the leading zero, we need to do %-m. The same goes for %-d.

$ date '+%-d/%-m'
26/5

More from Less

The less command actually accepts a lot of configuration options. For instance, less -F <file> will make the pager quit if the file can be displayed within one screen. We can also do export LESS='-F' so specific options apply to all less commands. That way, other commands that use less like git and man will also benefit from the environment variable. Use man less to read more about all the different kind of options you can use to make less more. Here is a nice article that covers some interesting options.