openwrt之uci使用

“uci”是“Unified Configuration Interface”(统一配置界面)的缩写,意在OpenWrt整个系统的配置集中化。

用法: uci [<options>] <command> [<arguments>]

命令:
	batch
	export     [<config>]
	import     [<config>]
	changes    [<config>]
	commit     [<config>]
	add        <config> <section-type>
	add_list   <config>.<section>.<option>=<string>
	show       [<config>[.<section>[.<option>]]]
	get        <config>.<section>[.<option>]
	set        <config>.<section>[.<option>]=<value>
	delete     <config>[.<section[.<option>]]
	rename     <config>.<section>[.<option>]=<name>
	revert     <config>[.<section>[.<option>]]

参数:
	-c <path>  set the search path for config files (default: /etc/config)
	-d <str>   set the delimiter for list values in uci show
	-f <file>  use <file> as input instead of stdin
	-m         when importing, merge data into an existing package
	-n         name unnamed sections on export (default)
	-N         don't name unnamed sections
	-p <path>  add a search path for config change files
	-P <path>  add a search path for config change files and use as default
	-q         quiet mode (don't print error messages)
	-s         force strict mode (stop on parser errors, default)
	-S         disable strict mode
	-X         do not use extended syntax on 'show'
  • 读取配置,以/etc/config/wireless为例
root@Eric:/# cat /etc/config/wireless

config wifi-device 'radio0'
        option type 'mac80211'
        option channel '11'
        option hwmode '11g'
        option path 'platform/10300000.wmac'
        option htmode 'HT20'
        option disabled '0'

config wifi-iface 'default_radio0'
        option device 'radio0'
        option network 'lan'
        option mode 'ap'
        option ssid 'OpenWrt-eric'
        option encryption 'none'
        
root@Eric:/# uci show wireless
wireless.radio0=wifi-device
wireless.radio0.type='mac80211'
wireless.radio0.channel='11'
wireless.radio0.hwmode='11g'
wireless.radio0.path='platform/10300000.wmac'
wireless.radio0.htmode='HT20'
wireless.radio0.disabled='0'
wireless.default_radio0=wifi-iface
wireless.default_radio0.device='radio0'
wireless.default_radio0.network='lan'
wireless.default_radio0.mode='ap'
wireless.default_radio0.ssid='OpenWrt-eric'
wireless.default_radio0.encryption='none'
  • 读取某一项
root@Eric:/# uci get wireless.radio0.type
mac80211
  • 新建配置文件server
root@Eric:/etc/config# touch server
  • 增加配置config mqtt,默认没有section
root@Eric:/etc/config# uci add server mqtt
cfg01c4eb
root@Eric:/etc/config# uci commit server
root@Eric:/etc/config#
root@Eric:/etc/config# cat server

config mqtt

  • 增加option name=abc
root@Eric:/etc/config# uci set server.@mqtt[0].name=abc
root@Eric:/etc/config# uci commit server
root@Eric:/etc/config# cat server

config mqtt
        option name 'abc'
  • 删除option name,删除config mqtt
root@Eric:/etc/config# uci delete server.@mqtt[0].name
root@Eric:/etc/config# uci commit server
root@Eric:/etc/config# cat server

config mqtt

root@Eric:/etc/config#
root@Eric:/etc/config# uci delete server.@mqtt[0]
root@Eric:/etc/config# uci commit server
root@Eric:/etc/config# cat server

root@Eric:/etc/config#
  • 增加带名字的config,mqtt=ali
root@Eric:/etc/config# uci set server.ali=mqtt
root@Eric:/etc/config# uci commit server
root@Eric:/etc/config# cat server

config mqtt 'ali'

root@Eric:/etc/config#
  • 增加option name=abc
root@Eric:/etc/config# uci set server.ali.name=abc
root@Eric:/etc/config# uci commit server
root@Eric:/etc/config# cat server

config mqtt 'ali'
        option name 'abc'

root@Eric:/etc/config#

  • 删除config mqtt
root@Eric:/etc/config# uci delete server.ali
root@Eric:/etc/config# uci commit server
root@Eric:/etc/config# cat server

root@Eric:/etc/config#


  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值