brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: mdls -name kMDItemWhereFroms tells you where a download came from

Terminal
~/tips/tip-macos-mdls-wherefroms

mdls -name kMDItemWhereFroms ~/Downloads/example.pdf

Shows the web address a downloaded file came from.

A file sits in Downloads and you do not remember where it came from. The Mac often does.

mdls prints the Spotlight metadata of a file. Ask for the one attribute you want with -name.

mdls -name kMDItemWhereFroms ~/Downloads/example.pdf

The attribute describes where the file was obtained from. For a browser download you normally get the file URL and often the page that linked to it. In Finder you can see the same under Get Info, in the More Info section.

Add -raw when you want the value without the attribute name, for scripts. The man page notes that raw mode separates fields with an ASCII NUL character, so pipe it to xargs -0.

The caveat is that it is only there when the app that saved the file wrote it. Browsers usually do. Files fetched with curl, or copied from elsewhere, often have nothing, and then you get a null value.

A file with no clear origin is a mild security question, and knowing the page it came from helps you decide what to do with it. It does not prove that a file is safe, but it tells you where to start looking.

Further reading: mdls.1 man page, kMDItemWhereFroms (Apple Developer), On this site: mdfind -name searches by file name from the terminal, using Spotlight, On this site: mdutil -s tells you if Spotlight is indexing a volume

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}' All Terminal tips (116) All topics

Link