Linux on call · Chapter 13 of 30

Editing in the terminal

By the end of this chapter you can open a file in a terminal editor, change, delete and add lines, save it, and get out of vim when it traps you. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.

  • Part: Files and text
  • 4 tasks
  • Linux
  • In the all labs plan

The first 2 chapters of Linux on call are free. This one comes with the all labs plan.

Why you need this

Ravi has a list for the ordering app. The new payment service needs port 3000, so the app moves to 4000. Debug mode is still on and fills the disk. And the kitchen takes at most 50 orders at once now. All of it lives in one settings file, which also has a line Bunty added "for luck":

cat config/app.conf
# Tapri ordering app settings
shop_name=Tapri Koramangala
port=3000
debug=true
db_host=localhost
bunty_was_here=yes
log_level=info

Bunty wants to edit it on his laptop and upload it back, but a server has only a terminal. What you know so far works blind: > replaces a whole file, >> only adds at the end, and sed (chapter 10) changes lines you cannot see. For a few small edits you want to see the file.

What you build: 4 tasks

Each task has tests. You write the code in the lab's editor and press Check.

  1. Task 1

    Change the port to 4000

    The app must move to port 4000. Change it in the settings file.

    1. Open config/app.conf in nano.

    2. On the port line, change 3000 to 4000. Do not add a second port line.

    3. Save with Ctrl+O and Enter. Leave with Ctrl+X.

    4. Run cat config/app.conf to see the file.

    To pass: config/app.conf has exactly one port line, port=4000. The comment at the top, shop_name, db_host and log_level stay as they are.

  2. Task 2

    Turn debug mode off

    Debug mode fills the disk. Turn it off in the settings file.

    1. Open config/app.conf in nano.

    2. On the debug line, change true to false.

    3. Save, leave, and run cat config/app.conf.

    To pass: config/app.conf has exactly one debug line, debug=false. The comment at the top, shop_name, db_host and log_level stay as they are.

  3. Task 3

    Delete Bunty's line

    Bunty added a line that the app does not need. Delete it.

    1. Open config/app.conf in nano.

    2. Put the cursor on the line bunty_was_here=yes. Press Ctrl+K to cut the whole line.

    3. Save, leave, and run cat config/app.conf.

    To pass: no line in config/app.conf has the word bunty. Delete only that line: the comment at the top, shop_name, db_host and log_level stay as they are.

  4. Task 4

    Add max_orders=50 as the last line

    The kitchen takes at most 50 orders at once. Add this setting at the end of the file.

    1. Open config/app.conf in nano.

    2. Go to the end of the last line, log_level=info. Press Enter to start a new line.

    3. Type max_orders=50.

    4. Save, leave, and run cat config/app.conf.

    To pass: the last line of config/app.conf is max_orders=50, and it is in the file only once. The lines above it stay.

What you will learn

  • nano: an editor inside the terminal, with its shortcuts listed at the bottom of the screen.
  • Saving and leaving: nothing reaches the file until you write it out.
  • vim: the editor on every server, its modes, and the way out.
  • Careful edits: change only what you were asked, then read the file again.

More in Files and text

Build "Editing in the terminal" yourself

Tapri’s ordering app moves onto a Linux server, and the server is now yours to run. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.

The first 2 chapters of Linux on call are free. This one comes with the all labs plan.