coreutils
[Top][All Lists]
Advanced

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

Re: stat(1) print formats


From: Ken Irving
Subject: Re: stat(1) print formats
Date: Sun, 23 Nov 2014 13:27:31 -0900
User-agent: Mutt/1.5.20 (2009-06-14)

On Fri, Nov 21, 2014 at 12:24:22PM -0500, David Braun wrote:
> ...
> 
> For this reason and to maintain backward compatibility maybe it would be
> better to introduce another format specifier (%L maybe) defined as
> producing an unadorned link value (no quotes or "->" stuff) or file name if
> not a symbolic link similar in formatting to %n. Alternatively a flag
> argument ('-l' perhaps) could be introduced that causes %N to produce the
> unadorned link value.

I copied the %N code in stat.c to create a new %L format as suggested
above, patch attached.

    ken@kimball:~/coreutils-hacks/coreutils/
    $ src/stat -c "%N" INSTALL 
    ‘INSTALL’ -> ‘gnulib/doc/INSTALL’
    
    $ src/stat -c "'%n' -> '%L'" INSTALL 
    'INSTALL' -> 'gnulib/doc/INSTALL'

Like %N, %L does nothing if the file is not a symlink:

    $ src/stat -c "%F %N" gnulib configure
    directory ‘gnulib’
    regular file ‘configure’

    $ src/stat -c "%F '%n' -> '%L'" gnulib configure
    directory 'gnulib' -> ''
    regular file 'configure' -> ''
    
I don't see much point in complaining if %L is used for non-symlinks,
but that could be done or a warning emitted.  The symlink value is
unconstrained, so an in-band message also makes no sense (the last
example would be poor practice since it makes the regular files look
like empty symlinks).
   
This was not my idea, so David should be attributed in the unlikely 
event that this patch is accepted.

Ken

Attachment: stat-patch
Description: Text document


reply via email to

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