5

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?

1
  • @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. Commented Feb 21, 2019 at 13:17

1 Answer 1

5

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.

  1. /usr/local/bin/zsh(5.7.1 via Homebrew) produces stat: missing file descriptor.
  2. /usr/local/bin/bash (5.0.2(1) via Homebrew) produces testing.txt.
  3. /bin/zsh (5.3 included with macOS) produces stat: missing file descriptor.
  4. /bin/bash (3.2.57(1) include with macOS produces testing.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.

4
  • 1
    zsh has a stat builtin (predates both BSD stat and GNU stat), but it's not activated (in its default build) unless you run zmodload zsh/stat (maybe you have that in your ~/.zshrc). Even then you can always run command stat instead of stat to get the OS's stat. Commented Feb 21, 2019 at 17:11
  • @StéphaneChazelas Yes - the stat builtin was loaded! Thank you! Commented 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.png Commented 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." Commented Feb 21, 2019 at 18:59

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.