Posted on 07-07-2022 09:57 AM
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?
#!/bin/sh
rm -rf "/Users/*/Documents/Power Point Files/ppt1.potx"
rm -rf "/Users/*/Documents/Power Point Files/ppt2.potx"
07-07-2022 12:11 PM - edited 07-07-2022 12:12 PM
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.
Posted on 07-08-2022 06:26 AM
Why not use a Policy > Files and Processes to search and Delete file if found
Posted on 07-08-2022 07:49 AM
You can only do 1 file at a time this way right? Would be a pain if you need to delete several files.
Posted on 07-08-2022 08:27 AM
I got it working as follows:
lastUser=`defaults read /Library/Preferences/com.apple.loginwindow lastUserName`
rm "/Users/$lastUser/Documents/Folder Example/PPY file 1.potx"
rm "/Users/$lastUser/Documents/Folder Example/PPY file 2.potx"