Linux Hack of The Week #1: Date/Time Straight From the Command Line

Everyone here at Automox is a Linux user. Most of us started on Unix, I cut my teeth on Solaris 2.4, and our CTO (Mark Manes) used Slackware first. Over the years we have all discovered some handy tricks. We are going to post a weekly Linux tip starting with some date manipulation tricks.

cal  : Displays the calendar on the command line.
Yes your phone has a calendar, and your desktop for that matter. But having the calendar on the command line is handy so you don’t have to switch out of the terminal.

 

ntpdate : Set system time over network.
NTP or Network Time Protocol runs on UDP/123 and allows you machine to set it’s time over NTP. The syntax is ntpdate <timeServer> , i.e. ntpdate time.nist.gov. When you are done, set up ntpd to continually set your time over the network.

date : display the date on the command line
The date command has almost infinite uses. Obviously checking the date, but then adding it to log file, adding to filenames, etc.


Running date with no options prints the day.
Running date with +(format) prints the date in a specific format.Then adding it to an echo statement can be really handy for logs.


The date can be formatted in any number of ways. Simply run man date to see the options.

Thanks for reading and we will be back next week with another Linux tip!



Subscribe to Our Newsletter

Stay up to date on all things patch management

Reduce your threat surface by up to 80%

Make all of your corporate infrastructure more resilient by automating the basics of cyber hygiene.