如何在Mac上仅删除以"SAMSUNG"开头的网络服务?
Batch Delete SAMSUNG-Named Network Services on Mac
I feel your pain—deleting over a thousand SAMSUNG modem services manually is totally a waste of time. Here's a simple, efficient way to automate the process:
One-Liner Command
Run this directly in your Terminal (you’ll need to enter your admin password when prompted):
networksetup -listallnetworkservices | grep "^SAMSUNG" | while read service; do sudo networksetup -removenetworkservice "$service"; done
Let’s Break It Down
Each part of the command works together to target only the services you want to delete:
networksetup -listallnetworkservices: Pulls up the full list of your network services, just like you did manually.grep "^SAMSUNG": Filters the list to keep only services that start with "SAMSUNG" (the^ensures we don’t accidentally match any services that mention SAMSUNG later in the name).while read service; do ... done: Loops through every filtered service name one by one.sudo networksetup -removenetworkservice "$service": Runs the delete command with admin privileges for each SAMSUNG service.
Important Pre-Checks & Tips
- Preview First: Before deleting anything, run this command to confirm you’re only targeting the right services:
networksetup -listallnetworkservices | grep "^SAMSUNG" - Admin Rights: The
sudois mandatory here—modifying network services requires administrator access. - Safe for Critical Services: Since we’re only filtering for services starting with "SAMSUNG", your Wi-Fi, Thunderbolt Bridge, and other essential connections won’t be touched.
Alternative: Verbose Script (Easier to Follow)
If you prefer something more readable (great if you’re new to shell commands), save this as delete_samsung_services.sh:
#!/bin/bash # Fetch all network services starting with SAMSUNG samsung_services=$(networksetup -listallnetworkservices | grep "^SAMSUNG") echo "Found the following SAMSUNG services to delete:" echo "$samsung_services" echo "---------------------------------------------" # Delete each service one by one for service in $samsung_services; do echo "Deleting: $service" sudo networksetup -removenetworkservice "$service" done echo "---------------------------------------------" echo "All SAMSUNG network services have been deleted!"
Then run it in Terminal with:
sudo chmod +x delete_samsung_services.sh && sudo ./delete_samsung_services.sh
Either method will wipe out all those unwanted SAMSUNG modems in seconds instead of hours.
内容的提问来源于stack exchange,提问作者Francisco Souza
相关产品推荐
相关产品推荐

