General

Show Date And Time In The Terminal

Today’s article is a nice and easy one, where I show you how to show the date and time in the terminal. It seems like a nice and easy article to write when I’m not feeling well. I’ll try to not let my ailments hamper the article in any way. 

Normally, I’d have a few articles written ahead of time. This time, I only have one article written ahead of time and it’s my ’emergency’ article. I’m not doing that poorly, so I’ll write this one. I’m pretty dedicated to doing an article every other day.

Anyhow, as I said, this article will show you how to get the date and time from the terminal. You can actually get the time just from running uptime, but there’s more to it. Linux actually has a ‘date’ command, which is what we’ll be using for this exercise. The date command’s man page describes it like:

date – print or set the system date and time

We will only be using the date command to print the time in the terminal. There are easier ways to set and maintain the time. With NTP being common, you really shouldn’t have to worry much about keeping the time accurate enough on your system.

Why would you want to know the date and time? Not everyone uses a desktop environment with a GUI and a clock. You may need to know the system time when you’re working on it remotely. There are all sorts of reasons. In fact, I once wrote an entire article about finding your timezone in Linux.

Show Date And Time In The Terminal:

This article requires an open terminal, just like many other articles on this site. Just press CTRL + ALT + T and your default terminal should open.

Now, this is nice and obvious… With your terminal open, just type in:

date

You’ll get an output similar to this one:

~$ date
Sun 28 Nov 2021 06:04:18 PM EST

Tada! You’re done!

Just kidding! There’s more to it. If you want to show just the time, you can just use this command:

date "+%T"

If you want to show the date and have it formatted like we do in the US, you can use this command:

date +"%m-%d-%y"

Want to know the date 3 weeks ago? (You can also use days for this command)? Well then, you can try this command:

date --date='3 weeks ago'

How about if you want to know how many days into the year you are? Well, you can do that with:

date +%j

Those are about the most interesting ways to show the date and time in the terminal, at least the most interesting ways that I can think of at this moment in time. If you use the date command for anything else, let us know by leaving a comment!

Closure:

There you have it, yet another article! This one shows you how to show the date and time in the terminal, just in case you want to do that. It’s a nice and easy exercise and, as far as tools go, is one that’s at least easy to remember. It’s probably not the most important tool you can have in your toolbox, but at least it’s in there. (Please be gentle pointing out any errors, part of this article was written with the help of a heating pad.)

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

KGIII

Retired mathematician, residing in the mountains of Maine. I may be old and wise, but I am not infallible. Please point out any errors. And, as always, thanks again for reading.

Recent Posts

Update Python Packages (PIP)

We've had a run of Python packages recently and you can tell that I'm a…

2 days ago

Save A Command’s Output To A File (While Showing It In The Terminal)

The title is the best I can come up with to describe this exercise as…

4 days ago

Demystifying journalctl: A Comprehensive Guide to Linux System Logging

It was suggested that I write an article about journalctl, which seemed like a large…

6 days ago

Extract Text From Multiple File Types

Today we will have a fairly simple exercise as we're going to just use a…

1 week ago

Meta: I’ve Been At This For Three Years!

I have not done a meta article lately. I don't find them interesting to write…

1 week ago

How To: Disable CPU Cores

This is not something everyone is interested in doing but you might as well learn…

2 weeks ago