zsh-users
 help / color / mirror / code / Atom feed
* Extract CTIME in zsh 4.2.3?
@ 2005-08-21 20:01 Timothy Luoma
  2005-08-21 20:11 ` Shawn Halpenny
  0 siblings, 1 reply; 9+ messages in thread
From: Timothy Luoma @ 2005-08-21 20:01 UTC (permalink / raw)
  To: zsh-users


I have a list of files, I'd like to extract the ctime from the files,  
preferably in yyyy-mm-dd format.

I can't figure out any way to do that.  Is it possible?

TjL
zsh version 4.2.3 on Mac OS X



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

* Re: Extract CTIME in zsh 4.2.3?
  2005-08-21 20:01 Extract CTIME in zsh 4.2.3? Timothy Luoma
@ 2005-08-21 20:11 ` Shawn Halpenny
  2005-08-22  4:44   ` Timothy Luoma
  2005-08-22  5:27   ` Timothy Luoma
  0 siblings, 2 replies; 9+ messages in thread
From: Shawn Halpenny @ 2005-08-21 20:11 UTC (permalink / raw)
  To: zsh-users

On 8/21/05, Timothy Luoma <lists@tntluoma.com> wrote:
> 
> I have a list of files, I'd like to extract the ctime from the files,
> preferably in yyyy-mm-dd format.
> 
> I can't figure out any way to do that.  Is it possible?
> 
> TjL
> zsh version 4.2.3 on Mac OS X

If you can load the zsh/stat module, this is very easy:

zmodload zsh/stat
stat -F '%Y-%m-%d' +ctime filename

-- 
Shawn Halpenny


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

* Re: Extract CTIME in zsh 4.2.3?
  2005-08-21 20:11 ` Shawn Halpenny
@ 2005-08-22  4:44   ` Timothy Luoma
  2005-08-22  5:27   ` Timothy Luoma
  1 sibling, 0 replies; 9+ messages in thread
From: Timothy Luoma @ 2005-08-22  4:44 UTC (permalink / raw)
  To: Shawn Halpenny; +Cc: zsh-users


On Aug 21, 2005, at 4:11 PM, Shawn Halpenny wrote:

>> I have a list of files, I'd like to extract the ctime from the files,
>> preferably in yyyy-mm-dd format.
>>
>> I can't figure out any way to do that.  Is it possible?
>
> If you can load the zsh/stat module, this is very easy:
>
> zmodload zsh/stat
> stat -F '%Y-%m-%d' +ctime filename

Thanks for the reply.

I may have my terminology wrong... I'm looking for the created date,  
the date the file was first made, regardless of when it was last  
opened or modified.

'stat' seems to change when the file is touch(1)ed

I can still see the created date in Finder, so I assume it has to be  
stored SOMEWHERE.

TjL


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

* Re: Extract CTIME in zsh 4.2.3?
  2005-08-21 20:11 ` Shawn Halpenny
  2005-08-22  4:44   ` Timothy Luoma
@ 2005-08-22  5:27   ` Timothy Luoma
  2005-08-22 15:21     ` Bart Schaefer
  2005-08-22 15:24     ` Shawn Halpenny
  1 sibling, 2 replies; 9+ messages in thread
From: Timothy Luoma @ 2005-08-22  5:27 UTC (permalink / raw)
  To: zsh-users

I've found a solution, but this will only work with Tiger (Mac OS X  
version 10.4.x)...

http://developer.apple.com/macosx/spotlight.html

kMDItemFSCreationDate            The date an item's file was created.

kMDItemContentCreationDate    The date an item's content was created.

The first tells you when the file was first created.  The second  
tells you when content was added to it (this is probably identical in  
most circumstances)

This is how you get to it:

$  mdls FILENAME |\
     grep "^kMDItemContentCreationDate"

kMDItemContentCreationDate      = 2005-08-20 00:47:41 -0400


     And this is how I'd get just the date:

$  mdls FILENAME |\
     awk -F" " '/kMDItemFSCreationDate/{print $3}'

  2005-08-20

If there's a more portable way to get this to work, I'd like to learn  
about it, but this will work for now.

TjL


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

* Re: Extract CTIME in zsh 4.2.3?
  2005-08-22  5:27   ` Timothy Luoma
@ 2005-08-22 15:21     ` Bart Schaefer
  2005-08-22 18:44       ` SOLVED (more or less) " Timothy Luoma
  2005-08-22 15:24     ` Shawn Halpenny
  1 sibling, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2005-08-22 15:21 UTC (permalink / raw)
  To: zsh-users

On Aug 22,  1:27am, Timothy Luoma wrote:
}
} I've found a solution, but this will only work with Tiger (Mac OS X  
} version 10.4.x)...
} 
} kMDItemFSCreationDate            The date an item's file was created.

In other words, what you're looking for is some record of the inode
creation time, rather than the inode change time which is what the
stat ctime refers to.

Unfortunately this information simply does not exist on many kinds of
filesystems for OSs whose names have an N in the middle and an X at
the end.  (If I write such an OS sometime, I'll call it ANIMAX.  You
read it here first.)
 
} If there's a more portable way to get this to work, I'd like to learn  
} about it, but this will work for now.

On filesystems derived (as in code was taken, not just inspired by like
the linux ext filesystems) from BSD's FFS, I *think* you can get this
with "ffsinfo -i N" where N is the inode number (which you have to get
some other way, e.g. with stat).  It's called the "birth time".  Please
note, though, that I may be entirely wrong -- the man page for ffsinfo
doesn't say what data is dumped, and I don't have a BSDish system handy
to try it.


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

* Re: Extract CTIME in zsh 4.2.3?
  2005-08-22  5:27   ` Timothy Luoma
  2005-08-22 15:21     ` Bart Schaefer
@ 2005-08-22 15:24     ` Shawn Halpenny
  2005-08-22 15:35       ` DervishD
  1 sibling, 1 reply; 9+ messages in thread
From: Shawn Halpenny @ 2005-08-22 15:24 UTC (permalink / raw)
  To: zsh-users

On 8/22/05, Timothy Luoma <lists@tntluoma.com> wrote:
> I've found a solution, but this will only work with Tiger (Mac OS X
> version 10.4.x)...

Ahh, it wasn't clear you wanted the create-time.  In Unix (and any
sufficiently Unix-like operating system) the "ctime" for a file is the
last time there was a change to the file's inode and is generally
portable.  Not all Unixes keep track of the create-time for a file, so
any mechanism to retrieve it is almost certainly non-portable.

-- 
Shawn Halpenny


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

* Re: Extract CTIME in zsh 4.2.3?
  2005-08-22 15:24     ` Shawn Halpenny
@ 2005-08-22 15:35       ` DervishD
  2011-07-26 15:24         ` skullnobrains
  0 siblings, 1 reply; 9+ messages in thread
From: DervishD @ 2005-08-22 15:35 UTC (permalink / raw)
  To: Shawn Halpenny; +Cc: zsh-users

    Hi Shawn and Timothy :)

 * Shawn Halpenny <paxunix@gmail.com> dixit:
> On 8/22/05, Timothy Luoma <lists@tntluoma.com> wrote:
> > I've found a solution, but this will only work with Tiger (Mac OS X
> > version 10.4.x)...
> Ahh, it wasn't clear you wanted the create-time.  In Unix (and any
> sufficiently Unix-like operating system) the "ctime" for a file is the
> last time there was a change to the file's inode and is generally
> portable.  Not all Unixes keep track of the create-time for a file, so
> any mechanism to retrieve it is almost certainly non-portable.

    In fact, it is not present in SUS. Probably it is present only
for a few filesystems, so it has to be retrieved in a non-portable
way. Under Linux, I don't recall now of any filesystem that
implements creation time for entries. It's not an operating system
problem, is a filesystem problem. Even in the case you can write
code for some UNIX flavour to retrieve that data, it will only work
for some particular filesystem. The VFS on top of that will only
store the st_atime, st_mtime and st_ctime values in the metadata.

    Another solution will be to create a dotfile or something like
that when creating the file whose creation date you want to obtain,
and make sure the file contents of that dotfile (or associated file,
whatever you call it) doesn't change. Then the st_mtime of the
associated file will be the creation time of the 'real' file. Not a
very clean solution, but...

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...


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

* SOLVED (more or less) Re: Extract CTIME in zsh 4.2.3?
  2005-08-22 15:21     ` Bart Schaefer
@ 2005-08-22 18:44       ` Timothy Luoma
  0 siblings, 0 replies; 9+ messages in thread
From: Timothy Luoma @ 2005-08-22 18:44 UTC (permalink / raw)
  To: zsh-users


Yes, from my extensive testing of one FreeBSD system, one Linux  
(Gentoo) system, and one OS X system, there does not seem to be a  
consistent way of getting this information.

'stat' on OS X does not seem to store the created date.  That killed  
the best chance for compatibility right there.

There are a couple of different ways to get it in OS X.

Tiger:
     mdls "${FILES}" | awk -F'"' '/kMDItemContentType /{print $2}'

gives me

     2005-08-20


If developer tools are installed:

     /Developer/Tools/GetFileInfo "${FILES}" |  awk -F' ' '/created: / 
{print $2}'

gives me

     08/20/2005

which isn't the format I wanted, so I'm sticking with 'mdls' for now.


Thanks to all who responded!

TjL



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

* Re: Extract CTIME in zsh 4.2.3?
  2005-08-22 15:35       ` DervishD
@ 2011-07-26 15:24         ` skullnobrains
  0 siblings, 0 replies; 9+ messages in thread
From: skullnobrains @ 2011-07-26 15:24 UTC (permalink / raw)
  To: zsh-users



>     In fact, it is not present in SUS. Probably it is present only
> for a few filesystems, so it has to be retrieved in a non-portable
> way. Under Linux, I don't recall now of any filesystem that
> implements creation time for entries. It's not an operating system
> problem, is a filesystem problem. Even in the case you can write
> code for some UNIX flavour to retrieve that data, it will only work
> for some particular filesystem. The VFS on top of that will only
> store the st_atime, st_mtime and st_ctime values in the metadata.

actually GNU/linux is definitely the only unix-like OS where you are likely to
be unable to retrieve a file's ctime.

"stat -f %c FILE" should be portable on any BSD os, including macosx and
probably on any solaris distribution as well.

you will need to use the "date" command in order to format the date as stat will
return a timestamp. each system is likely to implement shorthands to retrieve
the date in human readable form but in a less likely portable way.

the shell you are using will probably make no difference as stat is usually
either not a builtin or is system-dependant, but you can use `which stat` if you
want to make sure the builtin will not be used.

this is very sad, and i'd like to make clear i'm not looking forwards to start a
flame war, but if you are running linux trying to make something portable, you
probably should forget about using the shell, and switch to something like perl.
on the other hand ls + sed is more than likely to be portable under any OS, but
what you will retrieve in linux will probably not be the actual ctime of the file


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

end of thread, other threads:[~2011-07-26 15:45 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-21 20:01 Extract CTIME in zsh 4.2.3? Timothy Luoma
2005-08-21 20:11 ` Shawn Halpenny
2005-08-22  4:44   ` Timothy Luoma
2005-08-22  5:27   ` Timothy Luoma
2005-08-22 15:21     ` Bart Schaefer
2005-08-22 18:44       ` SOLVED (more or less) " Timothy Luoma
2005-08-22 15:24     ` Shawn Halpenny
2005-08-22 15:35       ` DervishD
2011-07-26 15:24         ` skullnobrains

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).