• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
The Electric Toolbox Blog

The Electric Toolbox Blog

Linux, Apache, Nginx, MySQL, Javascript and PHP articles

  • Applications
  • FCKEditor
  • Apache
  • Windows
  • Contact Us
Home / Showing seconds with ls on Linux and OSX

Showing seconds with ls on Linux and OSX

Using the “ls” command to list directory contents from the command line with the -l flag will include the date and time down to the minute, but not show the seconds. This post shows how to display the seconds as well with bash on Linux and OSX.

On Linux

Use one of the following, the second one effectively being a shorter version / synonym of the first one:

ls -l --time-style=full-iso
ls --full-time

The output of either of the above will be this:

total 0
-rw-r--r-- 1 chris chris 0 2016-03-31 12:01:10.000000000 +1300 foo.txt

If you don’t want the less than a second and timezone offset part, you can format the output yourself, e.g. like this:

ls -l --time-style=+"%Y-%m-%d %H:%M:%S"

The output of this is:

total 0
-rw-r--r-- 1 chris chris 0 2016-03-31 12:01:10 foo.txt

On OSX

None of the above will work on OSX, but there’s a flag available on OSX which isn’t on Linux which makes it all a lot easier: -T which you need to use with -l, for example:

ls -lT

And example output:

total 0
-rw-r--r--  1 chris  staff  0 31 Mar 12:01:10 2016 foo.txt

Versions used

The above examples were using:

Bash 4.2.37 on Debian 7.9 Wheezy

Bash 3.2.57 on OSX 10.10.5 Yosemite

Check Out These Related posts:

  1. ExpressVPN vs. IPVanish – Which is Better?
  2. Create a file in Linux
  3. Type casting with PHP
  4. Rename File Linux

Filed Under: Linux/Unix/BSD, OSX

Primary Sidebar

Categories

  • Apache
  • Applications
  • Article
  • Case Studies
  • Email Servers
  • FCKEditor
  • HTML And CSS
  • Javascript
  • Linux/Unix/BSD
  • Microsoft SQL Server
  • Miscellaneous Postings
  • MySql
  • Networking
  • Nginx Web Server
  • Offsite Articles
  • OSX
  • PHP
  • Quick Tips
  • RFC – Request for Comments
  • SilverStripe
  • VMWare
  • VPN
  • Windows
  • WordPress

Recent Posts

  • Vim Show Line Numbers
  • Add User To Group Linux
  • Chmod 777 Tutorial
  • How to Copy Directory Linux
  • Linux create user

Copyright © 2021. ElectricToolBox. All Rights Reserved.

  • Contact Us
  • Copyright Info
  • Privacy Policy
  • Sitemap