coreutils
[Top][All Lists]
Advanced

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

stat(1) print formats


From: David Braun
Subject: stat(1) print formats
Date: Fri, 21 Nov 2014 12:24:22 -0500

I'd like to argue that the output from the %N format from the stat(1)
command is flawed for several reasons.

1. The use of left and right quotes is counter to tradition and complicates
any shell post processing of the output. All shells that I'm familiar with
use paired quotes (left, right or double). Mixing them become difficult to
deal with.
2. The use of quotes only occurs for the %N format and is only necessary
because of the "xxx -> yyy" result because of the possibility of special
characters in either of the xxx or yyy portions.

If instead %N merely produces the link value (the yyy part) without quotes
(as for the %n format) then the user of the stat command has the option of
formating the result any why she wants - almost.

Assume for the examples below that the following two files exist

$ ls -l
total 0
lrwxrwxrwx 1 vrams vrams 11 2014-11-21 11:34 LinkToFile -> regularFile
-rw-r--r-- 1 vrams vrams  0 2014-11-21 11:34 regularFile


The current behavior of the stat command will produce the following


$ stat -c "file(%n) link(%N)" regularFile
file(regularFile) link(`regularFile')

$ stat -c "file(%n) link(%N)" LinkToFile
file(LinkToFile) link(`LinkToFile' -> `regularFile')


but if %N instead just produced the unadorned link value the result would be

$ stat -c "file(%n) link(%N)" regularFile
file(regularFile) link(regularFile)

$ stat -c "file(%n) link(%N)" LinkToFile
file(LinkToFile) link(regularFile)


If the user wanted to use quotes instead of parens as above she could

$ stat -c "file = '%n'    link = '%N'" regularFile
file = 'regularFile'    link = 'regularFile'

$ stat -c "file = '%n'    link = '%N'" LinkToFile
file = 'LinkToFile'     link = 'regularFile'


or even reproduce the current behavior (almost) with

$ stat -c "file = '%n' link = '%n' -> '%N'" LinkToFile
file = 'LinkToFile'    link = 'LinkToFile' -> 'regularFile'


I say "almost" because the above example applied to regularfile will produce

$ stat -c "file = '%n' link = '%n' -> '%N'" regularFile
file = 'regularFile'    link = 'regularFile' -> 'regularFile'


Which is different than current behavior and is difficult to differentiate
from an self referencing symbolic link (you can create them but not use
them for much).

(You'll also notice I have gotten rid of that annoying left/right quoting
... garbage in the above - paired quotes are much easier to deal with.)

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.

Or as yet another alternative, since '-t' has no current effect when '-c'
is used to format output, maybe it could serve to modify the output of %N
to be the unadorned link value.

By the way - there doesn't seem to be any documentation for the output
resulting from the use of '-t'.

Dave


reply via email to

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