“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#