zsh-workers
 help / color / mirror / code / Atom feed
* zsh/stat: output file birth time under Linux
@ 2021-06-14 12:09 Vincent Lefevre
  2021-06-14 12:17 ` Stephane Chazelas
  2021-06-14 18:50 ` Phil Pennock
  0 siblings, 2 replies; 5+ messages in thread
From: Vincent Lefevre @ 2021-06-14 12:09 UTC (permalink / raw)
  To: zsh-workers

Could zsh/stat output birth time under Linux, like what stat from
the GNU coreutils does?

cventin:~> zstat foo
device  2053
inode   21542983
mode    33188
nlink   1
uid     1000
gid     1000
rdev    0
size    0
atime   1623671935
mtime   1623671926
ctime   1623671926
blksize 4096
blocks  0
link    

cventin:~> /usr/bin/stat foo
  File: foo
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 805h/2053d      Inode: 21542983    Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/vlefevre)   Gid: ( 1000/vlefevre)
Access: 2021-06-14 13:58:55.440586835 +0200
Modify: 2021-06-14 13:58:46.488605110 +0200
Change: 2021-06-14 13:58:46.488605110 +0200
 Birth: 2021-06-14 13:56:54.992843658 +0200

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: zsh/stat: output file birth time under Linux
  2021-06-14 12:09 zsh/stat: output file birth time under Linux Vincent Lefevre
@ 2021-06-14 12:17 ` Stephane Chazelas
  2021-06-14 19:47   ` Stephane Chazelas
  2021-06-14 18:50 ` Phil Pennock
  1 sibling, 1 reply; 5+ messages in thread
From: Stephane Chazelas @ 2021-06-14 12:17 UTC (permalink / raw)
  To: zsh-workers

2021-06-14 14:09:03 +0200, Vincent Lefevre:
> Could zsh/stat output birth time under Linux, like what stat from
> the GNU coreutils does?
[...]

+1

Adding corresponding glob qualifiers (filter and sort), and
to whereever mtime/atime/ctime are also used would also make
sense.

On Linux, you need the statx() API which has been relatively
recently added to the kernel (and even more recently to glibc,
not sure about other libcs). See
https://unix.stackexchange.com/questions/304779/is-there-still-no-linux-kernel-interface-to-get-file-creation-date/452058#452058

Other Unices including FreeBSD/macOS have had APIs for that for
a long time, I don't think there's much standardisation though.

-- 
Stephane


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: zsh/stat: output file birth time under Linux
  2021-06-14 12:09 zsh/stat: output file birth time under Linux Vincent Lefevre
  2021-06-14 12:17 ` Stephane Chazelas
@ 2021-06-14 18:50 ` Phil Pennock
  2021-06-14 20:05   ` Stephane Chazelas
  1 sibling, 1 reply; 5+ messages in thread
From: Phil Pennock @ 2021-06-14 18:50 UTC (permalink / raw)
  To: zsh-workers

On 2021-06-14 at 14:09 +0200, Vincent Lefevre wrote:
> Could zsh/stat output birth time under Linux, like what stat from
> the GNU coreutils does?

I think the tricky decision is what to do about setting an numerically
indexed array instead of printing or setting an associative array.

The indices match the traditional stat() return value indices, but for
extended fields there may be some severe portability concerns here.

IMO anything which associates a value with a label, so we can grep for
btime or index the -H assigned associated array by the string "btime"
should be good.  But, again IMO, we should not extend the results for
"-A".

Others might disagree and say that as long as we include the correct
indices for the "-l" option then it's possible to write portable code.
I worry though that people won't and it's too much of a foot-cannon.

-Phil


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: zsh/stat: output file birth time under Linux
  2021-06-14 12:17 ` Stephane Chazelas
@ 2021-06-14 19:47   ` Stephane Chazelas
  0 siblings, 0 replies; 5+ messages in thread
From: Stephane Chazelas @ 2021-06-14 19:47 UTC (permalink / raw)
  To: zsh-workers

2021-06-14 13:17:17 +0100, Stephane Chazelas:
[...]
> Other Unices including FreeBSD/macOS have had APIs for that for
> a long time, I don't think there's much standardisation though.
[...]

Looking at revision logs on FreeBSD and NetBSD, looks like it
was added in FreeBSD in 2002 while adding support for UFS2 FS,
and adapted shortly after in 2003 in NetBSD. They just extended
the stat() API there AFAICT.

Note Linux file systems have added support for a birth time a
long while ago, but no API to retrieve it until 2017 oddly
enough.

https://www.freebsd.org/cgi/man.cgi?query=stat&sektion=2&manpath=FreeBSD%2013.0-RELEASE%20and%20Ports

-- 
Stephane


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: zsh/stat: output file birth time under Linux
  2021-06-14 18:50 ` Phil Pennock
@ 2021-06-14 20:05   ` Stephane Chazelas
  0 siblings, 0 replies; 5+ messages in thread
From: Stephane Chazelas @ 2021-06-14 20:05 UTC (permalink / raw)
  To: zsh-workers

2021-06-14 14:50:19 -0400, Phil Pennock:
[...]
> I think the tricky decision is what to do about setting an numerically
> indexed array instead of printing or setting an associative array.
[...]

I agree. There's a risk users do things like:

zstat -nLA a -- *
printf 'File: %s\n dev: %s...\n target: %15$s\n' "$a[@]"

Or

while (( $#a )); do
  print -r -- $a[1] $a[4] ...
  shift 15 a
done

(though in practice those behave poorly when any of the
(l)stat()s fails, so users would be more likely to run zstat in
a loop).

Or:

zstat -LA s link
print -r target: $s[-1]

-- 
Stephane


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-06-14 20:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-14 12:09 zsh/stat: output file birth time under Linux Vincent Lefevre
2021-06-14 12:17 ` Stephane Chazelas
2021-06-14 19:47   ` Stephane Chazelas
2021-06-14 18:50 ` Phil Pennock
2021-06-14 20:05   ` Stephane Chazelas

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).