Skip to content

Instantly share code, notes, and snippets.

@rjames86
Created January 18, 2015 06:51
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rjames86/c89dc290017019090bc1 to your computer and use it in GitHub Desktop.
Save rjames86/c89dc290017019090bc1 to your computer and use it in GitHub Desktop.

Last updated: 2014-12-25

mdfind commands

Find all the file types in a given directory

mdfind -attr kMDItemContentType "kMDItemContentType == '*'" -onlyin . | awk -F"kMDItemContentType =" '{print $2}' | sort | uniq -c | sort -r

Get Last 5 Files Added in Dropbox Folders

DROPBOX_WORK=$(python -c "import json;f=open('$HOME/.dropbox/info.json', 'r').read();data=json.loads(f);print data.get('business', {}).get('path', '')")
DROPBOX_PERSONAL=$(python -c "import json;f=open('$HOME/.dropbox/info.json', 'r').read();data=json.loads(f);print data.get('personal', {}).get('path', '')")
DROPBOX="$HOME/Dropbox"

LAST_ADDED=$(mdfind \
    -onlyin "$DROPBOX_PERSONAL" \
    -onlyin "$DROPBOX_WORK" \
    -onlyin "$DROPBOX" \
    'kMDItemDateAdded >= $time.today(-1)' \
    -attr 'kMDItemDateAdded' | \
awk -F"kMDItemDateAdded =" '{print $2 "|" $1}' |
sed -e 's/^ *//' -e 's/ *$//' |
sort -r | \
cut -d'|' -f2 | \
head -n5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment