bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH]: ls: add --user-format option for user defined format


From: Jim Meyering
Subject: Re: [PATCH]: ls: add --user-format option for user defined format
Date: Fri, 21 Nov 2008 23:41:00 +0100

Paul Eggert <address@hidden> wrote:
> Jim Meyering <address@hidden> writes:
>>   - is it worthwhile to add a --printf option to ls?
>>       I don't like the --user-format name)
>>
>>   - if so, should it use use a find -printf-compatible format string
>>       or one compatible to stat --printf?  Either way, it'll need a few
>>       extensions.
>
> I think it's worthwhile (as long as someone else does it :-) but I'm
> afraid that neither find's nor stat's printf options are up to ls's main
> task, which is to generate nice output for humans.
>
> ls is pretty good about lining up columns, even when the column data is
> unexpectedly wide, whereas 'find' and 'stat' are not.  I would expect
> that a -printf option to 'ls' would normally autoadjust column widths,
> but neither 'find' nor 'stat' does that now.

Thanks for replying.
So far, enough of the feedback has been in favor
of adding the option that I think we can agree that *some*
new option will be added.  Now only the form is up for debate.

I've been thinking about being able to specify the field
width for such columns.  We may have to use a special character
to say "use the automatically-computed minimum".  E.g., if %p
denotes the name, a format of "%p" would print just the name,
with no padding, while "%20p" would use a 20-column-wide field,
and "address@hidden" would use the minimum width for all strings considered.

> I don't see a strong need to maintain absolute compatibility with find
> -printf or with stat -printf.  Obviously we shouldn't be gratuitously
> compatible, but we might as well do it 'right' for 'ls', propagating any
> improvements to 'stat'.  (find -printf is not standardized by POSIX, so
> there's not a huge portability issue there.)
>
> I just now looked at the documentation for stat -printf and find
> -printf.  The stat documentation is easier to read, and has some
> features that I'd expect people would find useful (e.g., quoting file
> names with funny characters).  The find documentation has some fancy
> features for time stamp formatting, which I couldn't figure out from the
> documentation; I suggest cleaning that up in 'ls', for example, by
> having a --time-format=FORMAT option that specifies the time format in a
> strftime-like way.

Actually, that's nearly what find's format specifiers let you do.
But find's approach is more general (albeit more obscure) in that it
lets you format atime, ctime, and mtime independently.  For example,
to print the atime in seconds-since-the-epoch (with fractional part),
ctime's %F (date-only), and the mtime's %T (time-only):

  $ find . -maxdepth 0 -printf '%p %A@ %CF %TT\n'
  . 1204905873.0000000000 2008-11-21 18:08:35.0000000000

note that find has to use something other than 's' for
seconds-since-epoch, because this is a printf format string
that must honor %s (argument string) substitutions.
Obviously, ls wouldn't have that constraint, so it _could_ use 's'.

The %A %T %C prefixes are fine if you're just doing one directive
at a time, but for general use, I find that notation too obtuse.
Something like '%{name} %{atime:%s.%N} %{ctime:%F} %{mtime:%T}\n'
seems cleaner.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]