Skip to main content
Question

Delete File by File Extension

  • March 20, 2018
  • 3 replies
  • 16 views

Forum|alt.badge.img+3

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

Forum|alt.badge.img+12
  • Valued Contributor
  • March 20, 2018

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


Forum|alt.badge.img+8
  • Valued Contributor
  • March 20, 2018

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"

Forum|alt.badge.img+3
  • Author
  • New Contributor
  • March 20, 2018

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.