Created
July 4, 2020 04:27
-
-
Save gfxhacks/ceefbf34b8b5dff2fcade86834e46f57 to your computer and use it in GitHub Desktop.
Command snippets when working with metadata in OSX. More info: https://gfxhacks.com/renaming-files-by-date-from-metadata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Based on this example date: 2020-12-31 16:01:33 +0000 | |
# ---- Reading Metadata ---- # | |
# read all file's metadata attributes | |
mdls file.ext | |
# get file's metadata attribute by name | |
mdls -name kMDItemContentCreationDate file.ext | |
# returns: kMDItemContentCreationDate = 2020-12-31 16:01:33 +0000 | |
# get multiple file's metadata attributes by name | |
mdls -name kMDItemContentCreationDate -name kMDItemContentModificationDate file.ext | |
# returns: kMDItemContentCreationDate = 2020-12-31 16:01:33 +0000 | |
# kMDItemContentModificationDate = 2020-12-31 18:21:48 +0000 | |
# ---- Formatting mdls datetime output ---- # | |
mdls -name kMDItemContentCreationDate filename.ext | sed 's/[^0-9]//g' | cut -c 3-14 | |
# returns: 201231160133 (YYMMDDhhmmss) | |
mdls -name kMDItemContentCreationDate filename.ext | cut -d " " -f 3 | |
# returns: 2020-12-31 (YYYY-MM-DD) | |
mdls -name kMDItemContentCreationDate filename.ext | sed 's/-/_/g' | cut -d " " -f 3 | |
# returns: 2020_12_31 (YYYY_MM_DD) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment