What you will read?
If you’re inside a file in the Linux terminal — usually opened with commands like nano
, vim
, or less
— the way to exit depends on which program you’re using.
Exit nano
If you opened a file like this:
nano filename.txt
To exit:
-
Press
Ctrl + X
-
If prompted to save changes, press
Y
for yes orN
for no -
Press
Enter
to confirm the filename if you saved it
Exit vim
If you opened the file with:
vim filename.txt
You’re in normal mode. Press:
:q
Then hit Enter
to quit. If it says E37: No write since last change, use:
:q!
To save and quit:
:wq
Or, if you’re already in insert mode (-- INSERT --
at the bottom), press Esc
first, then type the commands.
Exit less
or man
If you’re viewing a file with:
less filename.txt
Or reading a manual with:
man ls
Just press:
q
It will instantly take you back to the shell prompt.
Read more: How to Fix: sudo Command Not Found Error