Fixing network list duplication with nm-applet on Linux


I use XFCE in Ubuntu, and for a while used the default network applet built into the status bar. Eventually I wanted to get rid of it, since it had problems connecting to networks occasionally (I use a laptop and thus switch wifi networks often). Simply removing the status bar made XFCE replace it with nm-applet, which is much better. However, I was shocked to find over 500 network duplicates for one network (network-name, network-name 1, network-name 2, ..., network-name 538)! However, it's quite easy to delete this and other unused networks without manually clicking the name, then delete in nm-connection-editor.

Standard disclaimer: I'm not responsible if you fuck up your system blah blah blah.

All the networks that show up when you hover over a name are stored in /etc/NetworkManager/system-connections/.

ls -l /etc/NetworkManager/system-connections/
total Too Damn Many
-rw------- 1 root root 332 Oct 11 17:45 XXX
-rw------- 1 root root 333 Jul 27 00:17 YYY (repeated about 500 times)

To delete the duplicates, simply do sudo rm /etc/NetworkManager/system-connections/NAME\ * (replace NAME with the name of your duplicated network, obviously). If NAME has spaces in it, make sure to prefix the spaces with backslashes (e.g., My Network -> My\ Network). If you have two networks that aren't duplicates but have the same start, then one has a space followed (e.g. My Network and My Network Repeater), temporarily move the second to your home directory or other safe place, then move it back afterwards. However, even if you do accidentally delete some networks you wanted to keep, the only thing that will happen is you'll have to type the password in again.

Explanation of sudo rm /etc/NetworkManager/system-connections/NAME\ *: * in a shell command expands to all possibilities. For example, in a directory with files file1, file2, file3, apple, file* would expand to file1 file2 file3, but not apple. In the same way, NAME\ * expands to all connections of NAME<space>thing, in this case thing being numbers. rm deletes every file passed to it, so the command will delete every duplicate network, but not the original network.