0

So I have 2 different Linux installations. One of them is Ubuntu and the second one is Kali.

When I run date command with no options/arguments on my Ubuntu install I get:

michal@ubuntu:~$ date
Thu 24 Mar 2022 07:56:23 PM CET

When I run date command with no options/arguments on my Kali install I get:

┌──(michal㉿kali)-[~]
└─$ date
Thu Mar 24 07:58:34 PM CET 2022

The locale setting is the same on both machines being: Ubuntu locale settings:

michal@ubuntu:~$ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

and Kali locale settings:

┌──(michal㉿kali)-[~]
└─$ locale
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

Why the date command output is different on both machines?

I want to PERMANENTLY change the Kali output, to be the same as my current Ubuntu output being:

michal@ubuntu:~$ date
Thu 24 Mar 2022 07:56:23 PM CET

Which file needs to be edited? Where are those settings?

I've tried to follow steps from this thread: How can I change the default date format (using LC_TIME)? but I don't understand what: "date's texinfo also explicitly recommends to set LC_TIME to C in order to produce locale independent output." means.

2
  • 1
    Are they both running the same date (coreutils) version? I see a similar difference on two Ubuntu systems between coreutils 8.28 and 8.30 (the 8.28 version doesn't appear to honor the format shown by locale -c d_t_fmt unless I add the +%c specifier explicitly) Mar 24 at 20:47
  • 1
    The last bit in your question means setting the LC_TIME variable, like LC_TIME=C date (which only changes it temporarily for that command).
    – Panki
    Mar 24 at 21:46

1 Answer 1

1

You can tell date how it should format its output:

%%   a literal %
  %a   locale's abbreviated weekday name (e.g., Sun)
  %A   locale's full weekday name (e.g., Sunday)
  %b   locale's abbreviated month name (e.g., Jan)
  %B   locale's full month name (e.g., January)
  %c   locale's date and time (e.g., Thu Mar  3 23:05:25 2005)
  %C   century; like %Y, except omit last two digits (e.g., 20)
  %d   day of month (e.g., 01)
  %D   date; same as %m/%d/%y
  %e   day of month, space padded; same as %_d
  %F   full date; like %+4Y-%m-%d
  %g   last two digits of year of ISO week number (see %G)
  %G   year of ISO week number (see %V); normally useful only with %V
  %h   same as %b
  %H   hour (00..23)
  %I   hour (01..12)
  %j   day of year (001..366)
  %k   hour, space padded ( 0..23); same as %_H
  %l   hour, space padded ( 1..12); same as %_I
  %m   month (01..12)
  %M   minute (00..59)
  %n   a newline
  %N   nanoseconds (000000000..999999999)
  %p   locale's equivalent of either AM or PM; blank if not known
  %P   like %p, but lower case
  %q   quarter of year (1..4)
  %r   locale's 12-hour clock time (e.g., 11:11:04 PM)
  %R   24-hour hour and minute; same as %H:%M
  %s   seconds since the Epoch (1970-01-01 00:00 UTC)
  %S   second (00..60)
  %t   a tab
  %T   time; same as %H:%M:%S
  %u   day of week (1..7); 1 is Monday
  %U   week number of year, with Sunday as first day of week (00..53)
  %V   ISO week number, with Monday as first day of week (01..53)
  %w   day of week (0..6); 0 is Sunday
  %W   week number of year, with Monday as first day of week (00..53)
  %x   locale's date representation (e.g., 12/31/99)
  %X   locale's time representation (e.g., 23:13:48)
  %y   last two digits of year (00..99)
  %Y   year
  %z   +hhmm numeric time zone (e.g., -0400)
  %:z  +hh:mm numeric time zone (e.g., -04:00)
  %::z  +hh:mm:ss numeric time zone (e.g., -04:00:00)
  %:::z  numeric time zone with : to necessary precision (e.g., -04, +05:30)
  %Z   alphabetic time zone abbreviation (e.g., EDT)

In your case the command would be as following:

date +"%a %d %b %Y %r %Z"

By setting an alias, you can change the behavior of the date command:

alias date='date +"%a %d %b %Y %r %Z"'

You can put the alias in your ~/.bashrc to make the change permanent for your current user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.