Skip to main content

Hi all,



What would be the line/commands to delete all network locations except for two (one named "Ethernet" and one named "Wi-Fi"). I want to delete any other network locations users may have except for two that i've create on their machines.



Thanks for your help forum!!!

networksetup help
look for listallnetworkservices then loop on the result. and delete what you don't want.


I'm actually looking to write a command to add to a script...


I don't want to edit the "networkservices", but want to delete actual "networklocations"


networksetup -help is still your friend


#!/bin/sh

defaultIFS=$IFS

IFS=$'
'

for i in $(networksetup -listlocations | grep -v -e "Location 1" -e "Location2")

do

echo "Removing location $i"
networksetup -deletelocation "$i"

done

IFS=$defaultIFS


quick & dirty, so test, test, test ;)


I've done that.. i know how to delete locations but don't know how to write an IF statement. I guess that what i need help with. I know the basic networksetup -deletelocation "locationname" and how to use it.



I just need help writing a command/statement that says if the network location name isn't (Wi-Fi or Ethernet) then delete it...



Sorry for the confusion...


@Chris Thats exactly what i needed. Thank you for the quick response! I'll test and reply back..Thanks again!


Reply