With programs like stat you see access, modify and change, but with Finder on macOS there is a "Date Added" field. Can I get the "Date Added" for a file or directory displayed in the Terminal, like stat can display the Modify date?
-
@Christopher Thank you for your answer, but no, for me these are two seperate things. If I move a folder created in 2013 to another directory, the added date in Finder will be 21 February 2019 (today), but your commands return the date when it was originally created in 2013.DisplayName– DisplayName2019-02-21 13:17:55 +00:00Commented Feb 21, 2019 at 13:17
1 Answer
Some candidates include the following. File times are exposed in metadata, and mdls is "metadata list". When used with the -raw option, output from mdls contains fields separated with an NUL character. e.g. as follows.
# The creation date which should not change.
mdls -raw -name kMDItemFSCreationDate $filename
The stat command behaves differently. Results from four versions of two shells using the command, stat -f $filename, follow.
/usr/local/bin/zsh(5.7.1 via Homebrew) producesstat: missing file descriptor./usr/local/bin/bash(5.0.2(1) via Homebrew) producestesting.txt./bin/zsh(5.3 included with macOS) producesstat: missing file descriptor./bin/bash(3.2.57(1) include with macOS producestesting.txt.
However, by using the full path to stat, the command completes as expected in each version of both shells. An example that produces all times found with stat follows.
/usr/bin/stat -f "Access (atime): %Sa%nModify (mtime): %Sm%nChange (ctime): %Sc%nBirth (Btime): %SB" testing.txt
The command produces output such as the following result from the command above.
Access (atime): Feb 21 10:46:41 2019
Modify (mtime): Feb 21 10:46:21 2019
Change (ctime): Feb 21 10:46:21 2019
Birth (Btime): Feb 21 10:22:17 2019
This was an interesting question, and I hope to receive more insight on the cause of the disparity.
-
1
zshhas astatbuiltin (predates both BSDstatand GNUstat), but it's not activated (in its default build) unless you runzmodload zsh/stat(maybe you have that in your~/.zshrc). Even then you can always runcommand statinstead ofstatto get the OS'sstat.Stéphane Chazelas– Stéphane Chazelas2019-02-21 17:11:02 +00:00Commented Feb 21, 2019 at 17:11 -
@StéphaneChazelas Yes - the
statbuiltin was loaded! Thank you!Christopher– Christopher2019-02-21 17:26:55 +00:00Commented Feb 21, 2019 at 17:26 -
Now it works, thank you. The date I am looking for was "Change (ctime)". I'm also on 10.14.3 and I am using another language than English. The field literally translates to "Date Added" and if you google "Date Added Finder" you get a lot of results which show that field existing in the same place as my local translation of "Date Added". For example: cdn.osxdaily.com/wp-content/uploads/2017/04/… i.sstatic.net/MJ69g.pngDisplayName– DisplayName2019-02-21 18:54:49 +00:00Commented Feb 21, 2019 at 18:54
-
@DisplayName I see. Thank you. Indeed, I do find "Date Added" in the column display options, but not from "Get Info."Christopher– Christopher2019-02-21 18:59:15 +00:00Commented Feb 21, 2019 at 18:59