I am new to Ubuntu. I know I can open a file using vim in read-only mode by pass the -R option:

vim -R <filename> //Gives warning if I try to write

However, if I do the same thing with nano, I am able to write files freely:

nano -R <filename>  //I can still write

What am I doing wrong? How can I open files in read-only mode using nano?

  • If you're only wanting to view a file, why not use cat? For example: cat <filename>
    – linux4me
    May 25, 2022 at 20:09
  • @linux4me a text editor allows scrolling, searching through text, syntax highlighting, a familiar interface, and other conveniences that 'cat' doesn't provide.
    – Esther
    May 25, 2022 at 21:59
  • 9
    Seems like you are assuming that -R has a constant OS-defined or OS-enforced meaning. That's not a valid assumption. -R and similar flags are defined by each application. That's what happens when you have a thousand different developers and a thousand independent software projects. Ubuntu is a merely distributor ("distro") of upstream Open Source and Free Software projects, and cannot impose a standard upon them.
    – user535733
    May 25, 2022 at 22:15
  • @linux4me: less -iM <filename> would be my preference. I use alias m=less with LESS = iMRj5X in my ~/.lesskey. Along with , and . as prev-file and next-file. Viewing files or piping into a pager is so common I want a 1-letter alias for it. (And m for more or less is fun, and keeps it on a different letter than ls or l.) May 26, 2022 at 14:34
  • @Esther: Does nano have syntax highlighting? less has all the other things you mentioned, being designed for viewing text files, with space for page-down since it's not an editor. May 26, 2022 at 14:36

1 Answer 1


Nano does not use '-R' as a "read-only-" option and uses '-R' for something else.

-R, --restricted

Restricted mode: don't read or write to any file not specified on the command line. This means: don't read or write history files; don't allow suspending; don't allow spell checking; don't allow a file to be appended to, prepended to, or saved under a different name if it already has one; and don't make backup files. Restricted mode can also be activated by invoking nano with any name beginning with 'r' (e.g. "rnano").

it uses -v or --view:

-v, --view

Just view the file and disallow editing: read-only mode. This mode allows the user to open also other files for viewing, un‐ less --restricted is given too.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .