Ubuntu: Edit file from tty1 terminal [duplicate]



Question:

This question already has an answer here:

I want to set the RUN to yes in the /etc/default/saned, as mentioned in this answer.

Here is a snippet of the file :

# 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  

How can I edit the saned file from within the tty1 terminal?


Solution:1

Open the TTY1 (Ctl + Alt + F1 ) and run this sed command :

sed -i '/^RUN=no$/s/no$/yes/' /etc/default/saned  
  • /^RUN=no$/ will match the line RUN=no

  • On that line we are substituting no with yes by s/no$/yes/

  • -i option is to edit the file in place.

Test :

    $ 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  


Solution:2

Switch to tty1 with Ctrl+Alt+F1 and login.

Edit the file with

sudo nano /etc/default/saned  

Ctrl+O for save and Ctrl+X to leave the editor.


Or use the short command below …

Ok, @heemayl we have a sed version, therefore we need a perl version also =)

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

Example

  • The starting situation

    % 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  
  • The dry run

    % 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  
  • The replacement

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

    % 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  


Solution:3

Indeed you just need to use one of the text-based editors, and lucky you can find many which is installed by default.

The most known/used text based editors are:

and sure you can install tons of other text-based editors.

Now to do what you want you just need to open the file /etc/default/saned with one of your text-based editors, and then edit RUn to yes save and close.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »