1.说明:<config> 指配置文件名,如dhcp,firewall,fstab等
uci set <config>.<section>=<section-type> 增加一个节点到文件中
uci set <config>.<section>.<option>=<value> 增加一个选项和值到节点中
uci add_list <config>.<section>.<option>=<value> 增加一个值到列表中
2.示例
touch /etc/config/test //创建一个配置文件test
uci set test.first=config //创建一个节点first
uci set test.first.name='abc' //添加option name及值'abc'
uci show test //显示配置文件test里的内容
#test.first=config
#test.first.name='abc'
uci commit //保存配置文件test
3.新增节点:
uci set firewall.test=rule # 这里是新增test section,注意是set而不是add
uci add_list firewall.test.icmp_type='router-advertisement'
uci set firewall.test.target='DROP'
uci set firewall.test.src='wan'
uci set firewall.test.proto='icmp'
uci set firewall.test.family='ipv6'
uci commit firewall
4.删除节点
uci del firewall.test
5.统计同一<section-type>的分区个数
uci set <config>.<section>=<section-type>
<section-type>可以自定义名字
root@OpenWrt:~# touch /etc/config/op_station
root@OpenWrt:~# uci set op_station.1=station
root@OpenWrt:~# uci set op_station.2=station
root@OpenWrt:~# uci set op_station.1.mac='11:22:33:44:55:66'
root@OpenWrt:~# uci set op_station.2.mac='12:22:33:44:55:66'
root@OpenWrt:~# uci show op_station
op_station.1=station
op_station.1.mac='11:22:33:44:55:66'
op_station.2=station
op_station.2.mac='12:22:33:44:55:66'
root@OpenWrt:~# uci commit op_station
root@OpenWrt:~# uci show op_station | grep -w station | wc -l
2
root@OpenWrt:~# cat /etc/config/op_station
config station '1'
option mac '11:22:33:44:55:66'
config station '2'
option mac '12:22:33:44:55:66'
参考:https://blog.csdn.net/m0_37922443/article/details/103006846