Linux for new users part 4 – dates

Continuing my series for those new to running Moodle on a linux server.

This month I’m going to look at how commands work in the Terminal.

If you remember last month, we opened a terminal (Ctrl+Alt+T), and displayed the date, using the very simple date command:

date

Then we added some parameters to the command:

date '+%A %W %Y %X'

You should see the difference in the display and format:

So what’s happening here?

Well, every command you type into the terminal has options you can add. In fact, even the very simple date command has over 40 options! Let’s start simple, try each command in your terminal as you read through here:

date +%c

Notice how the year appears in a more logical position?

You can add several options to the date at once. To see the name of the day (%A), the day of the month (%d) and the month name (%B), try this command:

date +%A%d%B

And you should get:

So, it worked, but it is a bit ugly eh? Not a problem, because you can include spaces as long as you wrap the entire format string in quotation marks. Note that the + goes outside the quotation marks.

date +"%A %d %B"

That looks much nicer !

And guess what, you are now using the Terminal and passing variables to commands! OK, so it’s only the date command, but this is exactly what you will be doing with ANY command in the CLI 🙂

It’s easy to add text to the format string, like this:

date +"Today is: %A %d %B"

There are quote a few options for displaying the date – try each of these one by one.

There is a VERY important lesson here. In fact, a VITAL lesson. Linux is case sensitive. So %c is NOT the same a %C. In the following examples note that the “c” and the “x” are lower case, but the “D” and the “F” are upper case. This is something you must recognise right now, and understand that when working on the command line the case you use for commands and operators is important.

%c
%D
%F
%x
  • %c prints the date and time in the format for your locale, including the timezone.
  • %D prints the date in mm/dd/yy format.
  • %F prints the date in yyyy-mm-dd format.
  • %x prints the date in the format for your locale.

Feel free to play around with these commands, maybe combining them in different orders?

More next month!

Stuart Mealor

Managing Director at HRDNZ
Stuart is interested in all things e-learning, with specific interests in Moodle, e-learning strategy, and business development.His experience in education over 30 years, MBA in International Business, and knowledge of e-learning systems implementation, together with graphic design background, give him a unique skill set for e-learning projects.

Latest posts by Stuart Mealor (see all)

Stuart Mealor

Stuart is interested in all things e-learning, with specific interests in Moodle, e-learning strategy, and business development. His experience in education over 30 years, MBA in International Business, and knowledge of e-learning systems implementation, together with graphic design background, give him a unique skill set for e-learning projects.

Add a reply or comment...

%d bloggers like this: