I had a few technical glitches this morning, if you were wondering why today’s posts were late. Which is a bit suspicious, since these two are technically the last ones I have left to share from the D section. 😐
First up is date
, which ranks among some of my favorite command line tools. I saved it to the last mostly because I wanted to show a little more detail than my usual quick glance.

The key to understanding and loving this wonderful gift from coreutils is in the help flags. Most of the fun happens when you add formatting, but to start with, just this
date
will give you the current date and time, according to your machine’s clock.
Change it only slightly, and you get UTC time.
date -u
You can shift that information slightly, into the future or the past, by adding a -d
flag and specifying 10 minutes, 2 hours, 8 weeks or what have you.
Formatting is where the fun is though. Here’s just the date, in easy-read year-month-day format.
date +%F
The plus sign triggers the formatting sequence, the percent sign specifies the style. Unless I am mistaken, this is how the date is usually shown in America.
date +%D
In other words, month-slash-day-slash-year. Counterintuitive from my perspective, but hey, who am I to blow against the wind?
Here’s date and time on the same line, with a space separating them.
date +%F\ %H:%M:%S
And here’s the same thing on two different lines. You can jam a newline into date with the %n
format.
date +%F%n%H:%M:%S
Now let’s get really crazy. Write it all out like a sentence.
date +"Today is "%A", "%B\ %e", "%Y"."
And the current time.
date +"The time is "%-l:%M\ %p"."
This is fun to me. Stick the two together and you get the date and time all at once. Remember this when you’re fiddling with things like ticker.
date
isn’t just for your local machine though. The TZ variable can be fed through date to show time zones outside local.
TZ='Asia/Tokyo' date
Ta-da! Get fancy with that stuff:
TZ='Asia/Tokyo' date +"Japan time is now "%-l:%M\ %p".
Oh, you’re an Internet hero, are you?
TZ='Asia/Tokyo' date +"Japan time is now "%-l:%M\ %p" on "%A", "%B\ %e", "%Y"."
No, I don’t just sit and tinker with date
in my free time. Okay, actually, yes, I do. … 😐
If you interject date
into other commands, you can arrange files or commands to include the date in specific formats. Ergo,
mv testfile.txt `date +%F-%H:%M:%S`.txt
That’s most often the way I use date
; I like to arrange family photos and so forth by date and time. That includes screenshots. 😉
fbgrab -s 5 `date +%F-%H:%M:%S`-${HOSTNAME}-date.png
Sadly, beyond formatting and measuring out arbitrary lengths of time, date
can’t really handle much in the way of calculating time. For that I recommend dateutils.
I could go on for a long time, but by now you should get the picture. If you need more examples, check out the examples page straight from the coreutils site, or Wikipedia’s list of examples. The possibilities are endless. …
In the mean time I’m going to dig around and see if I can get that last post from the D section ready again. … 😉