#50 Setting the System Date

Conciseness is the heart of Unix and has clearly affected its evolution in quite a dramatic manner. However, there are some areas where this zeal for succinctness can drive a sysadmin batty. One of the most common annoyances in this regard is the format required for resetting the system date, as shown by the date command:

usage: date [[[[[cc]yy]mm]dd]hh]mm[.ss]

Trying to figure out all the square brackets can be baffling, without even talking about what you do or don't need to specify. Instead, a shell script that prompts for each relevant field and then builds the compressed date string is a sure sanity saver.

The Code

 #!/bin/sh # setdate - Friendly front end to the date command. # Date wants: [[[[[cc]yy]mm]dd]hh]mm[.ss] ...

Get Wicked Cool Shell Scripts now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.