Kali-Linux
在我的 Kali Linux 中永久更改“日期”命令的輸出格式
所以我有 2 個不同的 Linux 安裝。其中之一是 Ubuntu,第二個是 Kali。
當我
date
在我的 Ubuntu 安裝上執行沒有選項/參數的命令時,我得到:michal@ubuntu:~$ date Thu 24 Mar 2022 07:56:23 PM CET
當我
date
在我的 Kali 安裝上執行沒有選項/參數的命令時,我得到:┌──(michal㉿kali)-[~] └─$ date Thu Mar 24 07:58:34 PM CET 2022
兩台機器上的區域設置相同: Ubuntu
locale
設置: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=
和卡利
locale
設置:┌──(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=
為什麼
date
兩台機器上的命令輸出不同?我想永久更改 Kali 輸出,與我目前的 Ubuntu 輸出相同:
michal@ubuntu:~$ date Thu 24 Mar 2022 07:56:23 PM CET
需要編輯哪個文件?這些設置在哪裡?
我嘗試按照此執行緒中的步驟操作: 如何更改預設日期格式(使用 LC_TIME)? 但我不明白什麼: “
date
的 texinfo 還明確建議將 LC_TIME 設置為 C以產生與語言環境無關的輸出。” 方法。
你可以告訴
date
它應該如何格式化它的輸出:%% 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)
在您的情況下,命令如下:
date +"%a %d %b %Y %r %Z"
通過設置別名,您可以更改
date
命令的行為:alias date='date +"%a %d %b %Y %r %Z"'
您可以將別名放入您的文件中
~/.bashrc
,以使更改對目前使用者永久生效。