How do I move out of a file in Linux?

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:

  1. Press Ctrl + X

  2. If prompted to save changes, press Y for yes or N for no

  3. 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.

Share:

More Posts

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments