Home / Alt manpages / rnano(1)

  • rnano(1)
  • User command
  • linux

Edit One File Without Opening the Rest with rnano

rnano is nano's restricted mode, built for one job: editing a named file with the shell and file-browsing escape routes locked off. The installed command is GNU nano 7.2 from package version 7.2-2ubuntu0.2, and this takes about ten minutes.

The restricted behaviour described here comes from the installed rnano(1) manual, so check your own version before relying on a detail in an automated workflow.

You need a terminal, a file you are allowed to edit, and write permission on its directory. No elevated privilege is normally needed, and this guide never touches sudo, a system configuration or a service.

1. Check the command before opening a file

Ask the installed program for its version and help. Both are read-only:

$ rnano --version
GNU nano, version 7.2
$ rnano --help
Usage: nano [OPTIONS] [[+LINE[,COLUMN]] FILE]...

The help text lists a lot of nano options, but the contract that matters here is the final argument: give rnano the file, and only the file, that is explicitly in scope. The + form can also set a starting line and column, for example +25,1.

Checkpoint

Confirm the command resolves to the binary you expect:

$ command -v rnano
/usr/bin/rnano
$ dpkg-query -W -f='${Package} ${Version}\n' nano
nano 7.2-2ubuntu0.2

Package versions differ between distributions, so treat the one your own host prints as authoritative for that host.

2. Prepare a disposable test file

Practise somewhere a mistake cannot damage a document you care about. These commands create and display a temporary file and need no root:

$ test_dir="/tmp/rnano-demo"
$ mkdir -p -- "$test_dir"
$ printf 'first line\nsecond line\n' > "$test_dir/notes.txt"
$ ls -l -- "$test_dir/notes.txt"
-rw-r--r-- 1 user user 24 ... /tmp/rnano-demo/notes.txt

Owner, group, timestamp and size will all vary. If you use a real document instead of a throwaway test file, back it up first: saving in any editor is a state change, and a restricted editor is not a substitute for your normal backup process.

To clean up the test later, use the exact path you created:

$ rm -- "$test_dir/notes.txt"
$ rmdir -- "$test_dir"

Those two removals are irreversible, so do not adapt them to a directory you have not checked.

3. Open only the named file

Start rnano with the test file as its explicit target:

$ rnano "$test_dir/notes.txt"
  • Edit with ordinary typing. The control-key help at the bottom of the screen uses ^ to mean the Control key.
  • Save with Ctrl-O, confirm the displayed filename, then exit with Ctrl-X.
  • Changed nothing? Exiting should not prompt you to save at all.

Checkpoint

After leaving rnano, check the file with a separate read-only command rather than reopening it in another editor:

$ sed -n '1,5p' -- "$test_dir/notes.txt"
first line
second line

Anything you added should show up here. If the save prompt showed a filename you did not intend to change, cancel it instead of confirming. A cancelled or failed save leaves the previous file exactly as it was, unless you deliberately overwrote it.

4. Know what restricted mode actually blocks

rnano runs nano in restricted mode, limiting the session to the file or files given on the command line and removing several escape routes ordinary nano allows:

  • No suspending to a shell.
  • No saving the buffer under a different name.
  • No inserting another file or opening a new buffer.
  • No appending to or prepending another file.
  • No backup files and no spell checking.

Those limits keep an editing task pinned to a known path, but they are not a complete security boundary: the editor still needs read and write permission on the named file, and whatever process launches rnano may already have other access. Keep the terminal and the account running it trustworthy.

Warning

Restricted mode does not make a file safe to overwrite. Before editing anything important, copy it to a checked backup name on the same filesystem:

$ cp --preserve=all -- /path/to/settings.conf /path/to/settings.conf.before-rnano
$ rnano /path/to/settings.conf

Keep that backup until you have confirmed the change is correct. To recover, restore it explicitly:

$ cp --preserve=all -- /path/to/settings.conf.before-rnano /path/to/settings.conf

Never restore a backup over a live service configuration without checking that service's documented reload or restart procedure; it can change behaviour immediately or at the next restart.

5. Jump to a known location

For a long file, add a line number after the plus sign:

$ rnano +25 /path/to/notes.txt
$ rnano +25,1 /path/to/notes.txt

The first form starts at line 25, the second also lands on column 1. These are navigation hints, not a request to edit a different file. If the file has fewer lines than that, behaviour is version-specific enough to be worth confirming the cursor position before you start typing.

Common traps

  • rnano cannot open a path. Check it first without changing anything: ls -l, then a readable and writable test.
  • Reaching for sudo to hide a permissions problem. A missing file, a read-only file and a directory without write permission are three different problems. If the file is deliberately protected, get the correct change process instead of overriding it.
  • Switching to plain nano to dodge a restriction. Only do that after confirming the broader file access it grants is actually acceptable: it changes the safety boundary, not just the feature set.
$ ls -l -- /path/to/notes.txt
$ test -r /path/to/notes.txt && echo readable
$ test -w /path/to/notes.txt && echo writable

Done means

  • Checked the installed rnano and nano versions.
  • Opened only the intended path and saved it deliberately.
  • Verified the result with a separate read-only command.
  • Understand what restricted mode blocks, and that it never replaces permissions or backups.
  • Have a checked backup and an explicit restore command for anything important.