nerdexam
CompTIA

XK0-004 · Question #449

A virtual machine logs al limes using UTC The systems administrator would like to have one script that outputs times that are in the Amenca/Chicago time zone. Which of the following would the administ

The correct answer is D. timedatect1 set-timezone "America/Chicago" $$ date >> mylog.txt. The timedatectl command sets the system timezone so that subsequent date commands in a script output timestamps in the desired local timezone.

System Management

Question

A virtual machine logs al limes using UTC The systems administrator would like to have one script that outputs times that are in the Amenca/Chicago time zone. Which of the following would the administrator MOST likely use in the script to accounts.

Options

  • Aecho 'env TZ=America/Chicago date' >> mylog.-xt
  • Bhwclock --localtime ?-mylog.txt
  • Cdate -d 'Tz="America/Chicago" now' >> mylog.txt
  • Dtimedatect1 set-timezone "America/Chicago" $$ date >> mylog.txt

How the community answered

(47 responses)
  • A
    4% (2)
  • B
    17% (8)
  • C
    6% (3)
  • D
    72% (34)

Why each option

The timedatectl command sets the system timezone so that subsequent date commands in a script output timestamps in the desired local timezone.

Aecho 'env TZ=America/Chicago date' >> mylog.-xt

This command writes a literal string to a file rather than executing any command, producing no actual date output in the log.

Bhwclock --localtime ?-mylog.txt

hwclock --localtime reads the hardware clock in local mode but does not produce formatted, timezone-specific output suitable for appending to a log file.

Cdate -d 'Tz="America/Chicago" now' >> mylog.txt

Embedding a timezone inside the date -d argument string in this format is not valid GNU date syntax; the TZ variable must be set in the shell environment before the command, not nested inside the -d date string.

Dtimedatect1 set-timezone "America/Chicago" $$ date >> mylog.txtCorrect

timedatectl set-timezone configures the system's active timezone to America/Chicago, after which the date command will format output using that zone. Chaining these operations in a script and redirecting to a log file produces timezone-correct timestamps without requiring manual TZ variable exports on every invocation.

Concept tested: Linux timezone configuration with timedatectl for script output

Source: https://man7.org/linux/man-pages/man1/timedatectl.1.html

Topics

#timezone#TZ variable#date command#timedatectl

Community Discussion

No community discussion yet for this question.

Full XK0-004 Practice