从 tty1 终端编辑文件

从 tty1 终端编辑文件

我想将设置RUNyes/etc/default/saned如中所述这个答案

以下是该文件的片段:

# Defaults for the saned initscript, from sane-utils

# Set to yes to start saned
RUN=no

# Set to the user saned should run as
RUN_AS_USER=saned

如何在 tty1 终端内编辑 saned 文件?

答案1

打开 TTY1 ( ++ Ctl)并运行此命令:Alt F1 sed

sed -i '/^RUN=no$/s/no$/yes/' /etc/default/saned
  • /^RUN=no$/将匹配行RUN=no

  • 在这一行中我们noyess/no$/yes/

  • -i选项是就地编辑文件。

测试 :

    $ sed '/^RUN=no$/s/no$/yes/' /etc/default/saned

    # Defaults for the saned initscript, from sane-utils

    # Set to yes to start saned
    RUN=yes

    # Set to the user saned should run as
    RUN_AS_USER=saned

答案2

Ctrl使用++切换到 tty1AltF1登录。

使用以下方式编辑文件

sudo nano /etc/default/saned

Ctrl+O保存,Ctrl+X离开编辑器。


或者使用下面的简短命令...

好的,@heemayl 我们有一个sed版本,因此我们也需要一个 perl 版本=)

sudo perl -i -pe 's/(^RUN=)no/$1yes/' /etc/default/saned

例子

  • 起始情况

    % cat /etc/default/saned
    # Defaults for the saned initscript, from sane-utils
    
    # Set to yes to start saned
    RUN=no
    
    # Set to the user saned should run as
    RUN_AS_USER=saned
    aboettger-VirtualBox% perl -pe 's/(^RUN=)no/$1yes/' /etc/default/saned 
    # Defaults for the saned initscript, from sane-utils
    
    # Set to yes to start saned
    RUN=no
    
    # Set to the user saned should run as
    RUN_AS_USER=saned
    
  • 试运行

    % sudo perl -pe 's/(^RUN=)no/$1yes/' /etc/default/saned 
    # Defaults for the saned initscript, from sane-utils
    
    # Set to yes to start saned
    RUN=yes
    
    # Set to the user saned should run as
    RUN_AS_USER=saned
    aboettger-VirtualBox% perl -pe 's/(^RUN=)no/$1yes/' /etc/default/saned 
    # Defaults for the saned initscript, from sane-utils
    
    # Set to yes to start saned
    RUN=yes
    
    # Set to the user saned should run as
    RUN_AS_USER=saned
    
  • 替代者

    % sudo perl -i -pe 's/(^RUN=)no/$1yes/' /etc/default/saned
    
  • 最后的情况

    % cat /etc/default/saned                                  
    # Defaults for the saned initscript, from sane-utils
    
    # Set to yes to start saned
    RUN=yes
    
    # Set to the user saned should run as
    RUN_AS_USER=saned
    aboettger-VirtualBox% perl -pe 's/(^RUN=)no/$1yes/' /etc/default/saned 
    # Defaults for the saned initscript, from sane-utils
    
    # Set to yes to start saned
    RUN=yes
    
    # Set to the user saned should run as
    RUN_AS_USER=saned
    

答案3

实际上,您只需要使用其中一个基于文本的编辑器,幸运的是,您可以找到许多默认安装的编辑器。

最知名/使用的基于文本的编辑器是:

  • 纳米(最简单的),学会使用
  • Vi(传统 Linux 编辑器),学会使用
  • pico(实际上它只是 nano 的符号链接)

当然,您还可以安装大量其他基于文本的编辑器。

现在要做您想做的事情,您只需用您的一个基于文本的编辑器打开文件 /etc/default/saned,然后编辑 RUn 为是,保存并关闭。

相关内容