A Bash script for safely removing .plist files from common macOS launch directories based on a search string.
This script helps you remove .plist files that match a specified search string from the following macOS system directories:
~/Library/LaunchAgents(User Launch Agents)/Library/LaunchAgents(System Launch Agents)/Library/LaunchDaemons(System Launch Daemons)/Library/StartupItems(Legacy Startup Items)
This can be particularly useful when:
- Uninstalling applications that leave behind launch agents/daemons
- Cleaning up old system services
- Removing unwanted startup items
First, make the script executable:
chmod +x remove_plists.shThen run the script:
./remove_plists.sh <search_string>Replace <search_string> with the text to match in plist filenames.
To remove all plist files containing "google" in their name:
./remove_plists.sh googleThis will search for and remove files like:
com.google.keystone.agent.plistcom.google.crashreporter.plist- etc.
This script requires appropriate permissions to remove files from system directories. You must run it with sudo because it accesses system-level directories that require elevated permissions:
sudo ./remove_plists.sh <search_string>The script accesses these directories:
~/Library/LaunchAgents- No sudo needed (user directory)/Library/LaunchAgents- sudo required (system directory)/Library/LaunchDaemons- sudo required (system directory)/Library/StartupItems- sudo required (system directory)
Since the script accesses system directories that require root permissions, you should always run it with sudo to ensure it can complete all operations successfully.
- The script checks if directories exist before attempting operations
- It only removes files with
.plistextension - It shows which files are being removed before deletion
- macOS operating system
- Bash shell
- File system access permissions for target directories