为@Postadelmaga的上一个答案增加了更多灵活性,我花了更多的精力来打印要删除的SSID的名称。这增加了一个困难:现在我们必须避免包含单词“ never”的SSID名称与包含“ never”的时间戳意外匹配的可能性。
我还创建了另一个函数,该函数按名称删除连接。
资料来源:https :
//github.com/frgomes/debian-bin/blob/master/bash_20nm.sh
#!/bin/bash
function nmcli_list {
nmcli --pretty --fields NAME,UUID,TIMESTAMP-REAL con show
}
function nmcli_remove {
if [ ! -z "$1" ] ;then
nmcli --fields NAME con show | \
grep "$@" | \
while read name ;do
echo Removing SSID "$name"
nmcli con delete "$name"
done
fi
}
##################################################################################
# The intent here is avoid that a connection named "never drive after you drink" #
# matches a timestamp "never". So, we have to make sure that we match colon #
# followed by "never" followed by spaces and/or tabs and finally an end of line. #
# #
# WARNING: However, I didn't get a chance to test this scenario. #
# So, I provide this code the way it is, in the hope that I've covered #
# well the behavior from some other simulations I did. #
##################################################################################
function nmcli_remove_never_used {
nmcli --terse --fields NAME,TIMESTAMP-REAL con show | \
egrep -e ':never[ \t]*$' | \
sed -r 's/:never[ \t]*$//' | \
while read name ;do
echo Removing SSID "$name"
nmcli con delete "$name"
done
}
然后,您可以删除特定的连接,如下所示:
$ nmcli_remove ScalaX
$ nmcli_remove "My WiFi @ Home"
$ nmcli_remove "never drive after you drink"