Suse & OpenSuse : Tips, Tricks, Tutorials, How Tos and Troubleshooting

Using the “date” command and it’s % options

Well, you can’t really get a date with this command but it is a very useful command to know for administrative tasks as well as for automatic documentation through scripting.

However, the date command’s options often baffles a lot of people (well, in my administering SuSE Linux class anyway) especially when they read about the formatting using the % symbol on the man pages.

Let me briefly extract what the man pages say;

NAME
    date – print or set the system date and time

SYNOPSIS
    date [OPTION] … [+FORMAT]
    date [-u|—utc|—universal] [MMDDhhmm[[CC]YY][.ss]]

DESCRIPTION
    … blah blah …

    FORMAT controls the output. The only valid option
    for the second form specifies Coordinated
    Universal Time.  Interpreted sequences are:

    %%    a literal %
    …
    %F    full date; same as %Y-%m-%d

I have seen many different attempts at trying to understand how to use the %F, e.g.

# date %F

or

# date –F

However, it is actually quite clear but somehow it is not the usual UNIX/LINUX command option format.  To get the date in the format 2009-04-17 (today’s date), you simply do

# date +%F
2009-04-17

It becomes obvious after you read the man page again.

RSS feed | Trackback URI

Comments »

No comments yet.

Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.