How to Show Full Timestamps, Including Seconds, with the ls Command

I’d say of all of the command-line applications I use, ls is in the top slot. So much so, that I have it wired up to run every time I change directories with cd.

Recently, I wanted to get some further insight to time a file was last modified. Easy enough, slap -l to get the “long” output, which includes the modification time:

/tmp
% ls -l
total 223M
-rw------- 1 josh wheel  44M Feb  7 21:30 50583da3-f07c-4740-9402-71afa8c34f25.bin
-rw------- 1 josh wheel 1.3M Feb  7 21:30 74868767-6b51-4a98-83d6-b3bf701fe401.bin
-rw------- 1 josh wheel 113M Feb  7 21:30 a71935ec-3723-4679-b1e8-ede780278592.bin
-rw------- 1 josh wheel 3.3M Feb  7 21:30 bb8cb8ee-760c-4f4f-90b9-8797ea198f52.bin
drwx------ 3 josh wheel   96 Feb  3 21:49 com.apple.launchd.TjKPOKQ5hK/
drwxrwxrwx 8 josh wheel  256 Feb  7 11:21 dumps/
-rw------- 1 josh wheel  61M Feb  7 21:30 e939f021-baa7-49b1-8077-2af60bb65c34.bin
prw------- 1 josh wheel    0 Feb  6 22:04 steam.pipe|
drwx------ 2 root wheel   64 Feb  7 23:34 tmp-mount-2sz7CF/
drwx------ 2 root wheel   64 Feb  7 18:55 tmp-mount-6ZrAbT/
drwx------ 2 root wheel   64 Feb  5 21:29 tmp-mount-Z7RpII/
drwx------ 2 root wheel   64 Feb  7 20:32 tmp-mount-g1hIWB/
drwx------ 3 josh wheel   96 Feb  4 20:04 tmux-501/
Zsh

Perfect! If you only want to see the hour and minute.

Second to none

Like most artfully crafted, the ls command will accept an additional argument that will let you set the style of the time being displayed. This can be utilized to display the full time, including seconds. This can also be used to swap out the human readable date (e.g. “Feb 7”) for a parser friendly date, in CCYY-MM-DD format.

The additional argument, --time-style is passed in with -l, and accepts short-hand values like long-iso or a fully defined formatting string. This is the same kind of formatting output string you could pass to date, don’t forget the + before the string:

/tmp
% ls -l --time-style=+'%Y-%m-%d %H:%M:%S'
total 223M
-rw------- 1 josh wheel  44M 2025-02-07 21:30:46 50583da3-f07c-4740-9402-71afa8c34f25.bin
-rw------- 1 josh wheel 1.3M 2025-02-07 21:30:47 74868767-6b51-4a98-83d6-b3bf701fe401.bin
-rw------- 1 josh wheel 113M 2025-02-07 21:30:44 a71935ec-3723-4679-b1e8-ede780278592.bin
-rw------- 1 josh wheel 3.3M 2025-02-07 21:30:47 bb8cb8ee-760c-4f4f-90b9-8797ea198f52.bin
drwx------ 3 josh wheel   96 2025-02-03 21:49:11 com.apple.launchd.TjKPOKQ5hK/
drwxrwxrwx 8 josh wheel  256 2025-02-07 11:21:04 dumps/
-rw------- 1 josh wheel  61M 2025-02-07 21:30:44 e939f021-baa7-49b1-8077-2af60bb65c34.bin
prw------- 1 josh wheel    0 2025-02-06 22:04:34 steam.pipe|
drwx------ 2 root wheel   64 2025-02-08 14:16:47 tmp-mount-1ssQj0/
drwx------ 2 root wheel   64 2025-02-07 23:34:12 tmp-mount-2sz7CF/
drwx------ 2 root wheel   64 2025-02-07 18:55:42 tmp-mount-6ZrAbT/
drwx------ 2 root wheel   64 2025-02-05 21:29:14 tmp-mount-Z7RpII/
drwx------ 2 root wheel   64 2025-02-07 20:32:51 tmp-mount-g1hIWB/
drwx------ 3 josh wheel   96 2025-02-04 20:04:38 tmux-501/
Zsh

If you’d prefer to always output the date/time from ls in a specific format, you can set an environment variable in our shell profile and always have the time style applied:

# CCYY-MM-DD HH:MM
export TIME_STYLE=long-iso

# CCYY-MM-DD HH:MM:SS
export TIME_STYLE=+'%Y-%m-%d %H:%M:%S'
Zsh
Josh Sherman - The Man, The Myth, The Avatar

About Josh

Husband. Father. Pug dad. Musician. Founder of Holiday API, Head of Engineering and Emoji Specialist at Mailshake, and author of the best damn Lorem Ipsum Library for PHP.


If you found this article helpful, please consider buying me a coffee.