Skip to main content
Solved

Need to delete all network locations except for two (Script Help please)


rqomsiya
Forum|alt.badge.img+12

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!!!

Best answer by Chris

#!/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 ;)

View original
Did this topic help you find an answer to your question?

7 replies

Forum|alt.badge.img+18
  • Valued Contributor
  • 1007 replies
  • October 14, 2014

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


rqomsiya
Forum|alt.badge.img+12
  • Author
  • Honored Contributor
  • 225 replies
  • October 14, 2014

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


rqomsiya
Forum|alt.badge.img+12
  • Author
  • Honored Contributor
  • 225 replies
  • October 14, 2014

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


Forum|alt.badge.img+18
  • Valued Contributor
  • 1007 replies
  • October 14, 2014

networksetup -help is still your friend


Forum|alt.badge.img+13
  • Valued Contributor
  • 268 replies
  • Answer
  • October 14, 2014
#!/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 ;)


rqomsiya
Forum|alt.badge.img+12
  • Author
  • Honored Contributor
  • 225 replies
  • October 14, 2014

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...


rqomsiya
Forum|alt.badge.img+12
  • Author
  • Honored Contributor
  • 225 replies
  • October 14, 2014

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


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings