Simple linux command line command to modify an option in a INI like config file

前端 未结 3 1718
北海茫月
北海茫月 2021-02-15 15:03

I am looking for a generic command line solution that would allow me to add or modify a configuration option inside a config file (ini like format).

Most linux configur

相关标签:
3条回答
  • 2021-02-15 15:43

    Augeas / augtool aims to do this, although you'll need the right lens for the type of file you're after (you can also write your own), for example, the Nginx lens.

    It also has an API if required.

    0 讨论(0)
  • 2021-02-15 16:07

    git config is actually a semi-generic INI interface.

    ❱ git config --file=/etc/default/nginx somegroup.ULIMIT '-n 4096'
    ❱ cat /etc/default/nginx
    [somegroup]
        ULIMIT = -n 4096
    ❱ git config --file=/etc/default/nginx somegroup.ULIMIT
    "-n 4096"
    

    It doesn't support adding top-level keys, though. All keys have to be placed in an INI style group, hence the "somegroup." above. That makes it unsuitable for your task, but I thought I'd mention it here for others finding their way here.

    0 讨论(0)
  • 2021-02-15 16:10

    Try crudini. BTW I think this file is a shell file rather than an ini file, but crudini can still work in this case:

    crudini --set /etc/default/nginx '' ULIMIT '"-n 4096"'
    
    0 讨论(0)
提交回复
热议问题