Delete specific files from all users documents

New Contributor

I am looking for a simple way to delete specific files from all users documents.  I would expect the following would work, but it does not seem to.  Am I missing something here?



rm -rf "/Users/*/Documents/Power Point Files/ppt1.potx"
rm -rf "/Users/*/Documents/Power Point Files/ppt2.potx"


Valued Contributor

You're likely going to be better served by running a while loop over the user directories. I'll also harken against using the -r flag for anything in a user directory unless you're extremely sure your syntax is correct. Probably best to add a simple if statement to detect the presence off the file in question and then delete just that item. 

Contributor III

Why not use a Policy > Files and Processes to search and Delete file if found

You can only do 1 file at a time this way right?  Would be a pain if you need to delete several files. 

New Contributor

I got it working as follows:


lastUser=`defaults read /Library/Preferences/ lastUserName`
rm "/Users/$lastUser/Documents/Folder Example/PPY file 1.potx"
rm "/Users/$lastUser/Documents/Folder Example/PPY file 2.potx"