如何从命令行忘记无线网络?

如何从命令行忘记无线网络?

使用命令行,如何让系统忘记我之前连接过的无线网络?

答案1

对于通过 管理的连接network-manager,应该可以通过界面进行操作nmcli,例如删除超过一天的无线连接

nmcli -t -f TYPE,TIMESTAMP,UUID con list | 
  awk -F\: -v oldts="$(date +%s -d '1 day ago')" '$1 == "802-11-wireless" && $2 < oldts {print $3}' |
  while read -r uuid; do
    nmcli con delete uuid "$uuid"
  done

或者(也许更好一点)类似

#!/bin/bash

oldstamp=$(date +%s -d '1 day ago')

while IFS=\: read -r contype timestamp uuid
do
  case "$contype" in
    802-11-wireless)
      if ((timestamp < oldstamp)); then
        nmcli con delete uuid "$uuid"
      else
        echo "$uuid: too new: skipping"
      fi
    ;;

    *)
      echo "skipping connection type $contype"
    ;;
  esac
done < <(nmcli -t -f TYPE,TIMESTAMP,UUID con list)

权限提升应该由 dbus/policykit 处理,因此sudo不需要删除调用用户创建的连接。

相关内容