Rename a file using its created
, modified
, or added
date, as read from its metadata.
More Info: https://gfxhacks.com/renaming-files-by-date-from-metadata
sh metadater.sh file.ext
alternatively, make the file executable:
chmod +x metadater.sh
Then copy/move it to the /usr/local/bin
directory:
sudo mv metadater.sh /usr/local/bin/metadater
If using a custom directory, make sure it's indexed in the PATH
-
add this line to the .bashrc
config file located in the Home directory (~
), if using Bash; or .zshrc
if using zsh:
If the config file doesn't exist, create it first.
export PATH=$PATH:/custom/dir
Now the script can simply be run using:
metadater file.ext
Easily customize the script by adding/removing other metadata options. To list a file's metadata use:
mdls file.ext
Here are some kMDItem Date metadata options:
- kMDItemContentCreationDate
- kMDItemContentModificationDate
- kMDItemAttributeChangeDate
- kMDItemLastUsedDate
- kMDItemDateAdded
- kMDItemRecordingDate
- kMDItemFSContentChangeDate
- kMDItemFSCreationDate