เปลี่ยนรูปแบบวันที่ / เวลาอย่างถาวรสำหรับ ls


2

เมื่อฉันทำ ls -l ฉันเข้าใจ

-rw-------  1 nifle None  17K Jul 15 01:48 .bash_history
-rwxr-xr-x  1 nifle None 1.2K Feb  9  2010 .bash_profile*
-rwxr-xr-x  1 nifle None 3.7K Mar 22 10:03 .bashrc*
-rwxr-xr-x  1 nifle None 3.7K Feb  9  2010 .bashrc~*
drwxr-xr-x+ 1 nifle None    0 Mar  6 17:31 .cpan/
drwxr-xr-x+ 1 nifle None    0 Jan  3  2011 .emacs.d/
 <snip>

ฉันจะได้รับรูปแบบวันที่และเวลาได้อย่างไร YYYY-MM-DD HH:MM insted?

คำตอบ:


11

สมมติว่า GNU ls จาก info ls "Formatting file timestamps":

`--time-style=STYLE'
     List timestamps in style STYLE.  The STYLE should be one of the
     following:

...

`long-iso'
      List ISO 8601 date and time in minutes, e.g., `2002-03-30
      23:45'.  These timestamps are shorter than `full-iso'
      timestamps, and are usually good enough for everyday work.
      This style is equivalent to `+%Y-%m-%d %H:%M'.

...

   You can specify the default value of the `--time-style' option with
the environment variable `TIME_STYLE'; if `TIME_STYLE' is not set the
default style is `locale'.

ดังนั้นใส่ต่อไปนี้ในของคุณ .bashrc หรือ .bash_profile และคุณพร้อมแล้ว:

export TIME_STYLE=long-iso

เพิ่มข้อมูลอีกเล็กน้อยในคำตอบของคุณ
Nifle

สิ่งนี้ดูเหมือนจะเป็นอันตรายบนเซิร์ฟเวอร์ที่มีสคริปต์ที่กำหนดเองจำนวนมากซึ่งขึ้นอยู่กับเอาต์พุตของ "ls" ... :-( ok สคริปต์ผิดปกติแน่นอน .. แต่ระวังผลที่อาจเกิดขึ้นได้
JDC

โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.