21

--full-time is a handy little option for ls but it doesn't work when used in a batch file.

ls -al --full-time when used at the command prompt yields a an expanded date and time:

2012-01-16 18:56:00.000000000

used in a bash script I got this:

ls: illegal option -- - usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]

is there any way around this.

C0ppert0p
  • 634
  • 2
  • 7
  • 23
  • Want to show us your script? I'm not having any problems with that command in a bash file. – aqua Mar 08 '13 at 04:37
  • 1
    I wish I knew a way to format `ls` datetimes (I'd rather see ISO-8601). Apple's BSD manual for `ls` seems to offer nothing for formatting datetimes, other than changing timezone and sorting by datetime rather than alpha. https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/ls.1.html – 2540625 Aug 12 '14 at 05:29

3 Answers3

35

for native ls command, option -T seems to be the alternative of --full-time, and it expands to seconds, example as below:

>$  ls -lT
-rw-r--r--   1 raison staff     197 Feb 14 09:12:56 2013 1.c
-rw-r--r--   1 raison staff    1174 Mar  8 09:34:49 2013 1.s
-rw-r--r--   1 raison staff     993 Feb  5 14:44:09 2013 1.x86.s
Peixu Zhu
  • 2,111
  • 1
  • 15
  • 13
5

The BSD (Mac OS X) version of ls (installed as /usr/bin/ls) does not support the --full-time option.

The GNU version of ls does support --full-time. I have the GNU ls installed in a different directory (/usr/gnu/bin/ls).

  • Are you sure that you have GNU ls on your machine at all?
  • If so, are you sure your PATH includes the directory where it is installed ahead of /usr/bin when you run scripts?
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
2
$ uname -rs
Darwin 11.4.2
$ ls -al --full-time
ls: illegal option -- -
usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]

Are you sure your ls isn't actually gls installed by homebrew?

phs
  • 10,687
  • 4
  • 58
  • 84