I have a Mac and need to create a list of all the file contents in a given directory and it's sub-directories, together with the 'Creation', 'Added', 'Modified' and 'Last Opened' dates for each file.

Looking through the various threads I can see how to get the Creation/Added/Modification data using 'ls' or 'stat' commands, but I can not see any way of getting the Last Opened date information for all files recursively.

  • 1
    What do you mean by "file contents". By the context it seems that you mean the file names? The "last opened" date is called "time of last access" (atime). Also, what's the difference between "added" and "created"?
    – Kusalananda
    Commented May 20, 2017 at 14:00

2 Answers 2

  • Creation: Although not one of the original file properties included in UNIX, this one is available on many filesystems today (including, most pertinently to MacOS, HFS+), and the modern versions of tools like ls and stat know how to access it: ls -U, stat uses B (documented in the manpages).
  • Added: This does not exist per se. You can use the last-modified time of the directory that contains a file to know when the last modification to that directory happened, which is either that a file got added (created or moved in), removed (deleted or moved away), or renamed. But you don't know which one, and you only get information about the most recent event.
  • Modified and Last access: These are original stats that have been available on files in UNIX since forever. Most filesystems and basically all tools support them: ls -u, stat uses a and m (again, as documented). Note that, to save disk writes on every file access, the last access timestamp tracking is sometimes turned off or conditionally turned off.

There's another one you haven't mentioned, which is last inode change. This tracks when a file's metadata has last changed, as opposed to the file contents.


You can use the stat command to list information about a file. This command can list all four timestamps that the operating system records for a file:

  • %a: the access time (atime). This is the last time the file was opened or otherwise read (e.g. to analyze or index its contents).
  • %m: the modification time (mtime). This is the last time the file's content was modified. If the file was copied or downloaded from elsewhere, whether its mtime is updated at the point of copying depends on how the copy is made.
  • %c: the inode change time (ctime). This time is updated whenever anything happens to the file other than reading it: modification, renaming, moving, changing permissions, etc.
  • %B: the birth time (creation time). This is normally the time when the file was created or downloaded, though with some applications this may reflect the last time the file was saved.

You can combine it with the find command to list files recursively. For example, to list the timestamps and the names for all regular files under the current directory, you can use:

find . -type f -exec stat -f '%Sa %Sc %Sm %SB %N' {} \;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .