Date/Time

System time and timezone information.

Enumerate

Date/Time Info

date

Display the current date and time

date +"%Y-%m-%d %H:%M:%S %Z"

Custom format: YYYY-MM-DD HH:MM:SS TZ

hwclock

Displays hardware clock time (if different from system time).

hwclock --show

Displays the hardware clock time.

timedatectl

Displays current timezone and other time-related settings.

ntpq -p

Displays current NTP synchronization status.

uptime

Shows system uptime and load averages.

date +%s

Current Epoch Time (Seconds from January 1, 1970).

cal

Displays a calendar for the current month.

Timezone Info

cat /etc/timezone

Displays the system's timezone (Debian-based systems).

ls /usr/share/zoneinfo

Lists available timezones.

timedatectl list-timezones

Lists all timezones (systemd systems).

date +%Z

Shows the timezone abbreviation.

zdump /etc/localtime

Shows the timezone based on the /etc/localtime file.

TZ='America/New_York' date

Displays date/time info for specified timezone without changing system settings.

Modify

date --set="2024-02-04 15:30:00"

Sets system time and date.

sudo date --set="2024-02-04 15:30:00"

Sets system time and date with admin privileges.

hwclock --set --date="2024-02-04 15:30:00"

Sets hardware clock time (requires root access).

timedatectl set-timezone <timezone>

Sets timezone (e.g., "America/Los_Angeles").

sudo hwclock --systohc

Writes system time to hardware clock.

sudo hwclock --hctosys

Reads hardware clock time and sets system time.

ntpdate pool.ntp.org

Synchronizes time with a public NTP server.

systemctl start ntpd

Starts the NTP daemon for automatic synchronization.

Time-based Commands

timeout <seconds> <command>

Runs a command with a time limit.

watch -n <seconds> <command>

Repeatedly executes a command, showing output.

File Locations

/usr/share/zoneinfo

Timezone information directory.

/etc/timezone

Stores the system's default timezone (Debian-based systems).

/etc/localtime

A symlink or copy of the timezone information file from /usr/share/zoneinfo.

/etc/sysconfig/clock

Stores timezone settings on some Linux distributions (e.g., Red Hat-based systems).

/etc/sysconfig/timezone

Stores timezone settings on some Linux distributions (e.g., Red Hat-based systems).

Last updated

Was this helpful?