Tag Archives: date

tcat: Just quickly, because it’s fun

I wanted to squeeze tcat in today, not just because I have a string of task managers that will otherwise monopolize the week, but also because it’s fun.

2014-05-17-6m47421-tcat

tcat saves you the stress of splicing date and cat, and working out the funky sequence to divide them with a tab character.

The help pages promise that tcat does absolutely nothing other than stream data through, and prepend it with a time stamp. So far, it has kept that promise for me.

tcat will let you wrangle the stamp format, in the same way you would might use the date command alone. Together that allows you to pipe any kind of output you like, through tcat and get the same information, just stamped.

Nifty, huh? 😀

saydate and saytime: Hear for yourself

I’m going to lump saydate and saytime into one post, partly because they’re obvious cousins, but also because me showing them here doesn’t do a lick of good.

2014-04-16-g60-125nr-saydate

Both are primarily audio gimmicks, and as you can guess, one speaks the date through your speakers, and the other the time.

Unfortunately both are also somewhat out of date — saydate in particular is a decade old — and my luck with ancient audio programs is less than perfect.

I will give you a hint though: For the Debian version of saydate — which is hiding in the squeeze repos — you’ll want to install alsa-oss and start it like this:

aoss saydate -w

For saytime, you’ll need to make sure sox is installed, but I can’t guarantee that will work either, since my Arch version of sox didn’t like the options saytime was passing to it.

As a side note, saytime is apparently only in Russian, even if the flag options are available in English.

And other than that, all I can say is … you’ll have to hear them for yourself.

date: The possibilities are endless

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.

2013-10-17-lv-r1fz6-date

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. … 😉

dateutils: Making everything better

I want to look over the standard date utility out of coreutils soon, but that will be a rather complex adventure, a la dmesg or top.

For now, I have dateutils to show, which is going to make some people in the audience very very happy indeed.

2013-09-29-v5-122p-dateutils

dateutils isn’t one tool, it’s about a half-dozen, each set up to manage dates and conversions quickly and seamlessly.

dateutils comes with tools that can easily find the difference between two times, add or subtract set amounts of time to dates, skim through lists to pick out specific dates, navigate backwards or forwards to a set date given a starting time, convert between calendars, generate sequences of dates or times and skip particular ones, compare dates in the shell, and a lot of other things.

dateutils alone is something you’ll probably want if you work with files or timestamped data at all; I’ve already put it to good use helping organize personal photos that I know were taken with the wrong date set on the camera.

That’s just the first example I could think of. If you have the slightest interest, you owe it to yourself to check this one out. It could conceivably save you immense time and effort.

A gold smilie for dateutils: 😀