Delete File by File Extension

DTeklu
New Contributor

Hey Jamf Nation -

Apologies if this has been posted before.

Is there an easy way to delete a file with a specific extension, found in the logged in user's profile using JAMF? For example, any file with the extension of .DOC, I'd like for JAMF to find it and delete it. Is that possible?

3 REPLIES 3

Dylan_YYC
Contributor III

You'd probably have to make a script to do that, but you'd be using wildcards and that can be risky.

tak10
Contributor II

I've used this to find files with .doc extension. I'm assuming you can add a for loop or something so that each entry will be deleted.

Please test, test, test before putting on JAMF Pro and run it with Check-In policy.

#!/bin/sh

loggedinuser=$(stat -f%SU /dev/console)

sudo find /Users/$loggedinuser/ -type f -name "*.doc"

DTeklu
New Contributor

Thank you sooooo much! So, essentially, that script would find any files with .DOC extension and delete them?

My example was for .DOC, but I'm actually trying to delete Outlook archives/exports and didn't find a way to prevent staff from exporting from Outlook. This would save in .OLM file. So, in theory, I can substitute .DOC with .OLM and test, test, test.