If you are new to editing files with Terminal programs such as VI, VIM, or Nano, then it could be difficult at first to understand how to exit a file that is being opened in edit mode.
Let us take a look at how to exit a file based on each editor type.
Table of Contents
Exit a file using Nano Editor
If you want to save changes and exit then press Control + Y
If you do not want to save changes and exit then press Control + N
If you do not want to exit the file and continue editing then press Control + C
The Nano editor is the most easy to use editor for the Terminal. If you have opened a file using nano command, then you can exit by pressing the Keys "Control + X"
If you have made no changes to the file, the application will exit and return to your bash/zsh shell prompt.

If you have made changes to the file, then when you press Control + X you will be asked a question,

Exit File using Vi/Vim
- Step 1: Press Escape key to get into the command mode.
- Step 2:
- If you want to save and exit, then type :wq (write and quit) and press Enter.
- If you do not want to save changes and exit, then type :q! and press Enter.
- If you want to save and exit, then type :wq (write and quit) and press Enter.
Vi/Vim is a more powerful and advanced text editor, it could be a bit difficult at first how to exit its file editing modes as compared to Nano.
You should return back to the terminal prompt.
Exit File when using less or more commands
- Rename a directory using Linux/Unix command
- ls command to list only directories
- How to Restart or Reload Nginx Server Service on Linux
- 3 ways to clear screen on Linux Terminal
- ls command: sort files by name alphabetically A-Z or Z-A [Linux/Unix/macOS/Bash]
- Copy entire directory using Terminal Command [Linux, Mac, Bash]
- Fix: sudo: unable to open Read-only file system
- Create Hidden File or Directory using Shell Command
- Command to know the installed Debian version?
- The Date Command and its usage [Linux - Unix - macOS]
- Fix - bash: man: command not found
- How to tar.gz a directory or folder Command
- How to Display content of a file in Terminal Screen?
- How to change bash terminal prompt string and color
- Sort ls command by last modified date and time
- Execute .bin and .run file Ubuntu Linux
- zsh hello world example
- How to check uptime of Linux/Unix/macOS system/server using console command?
- [Fix] Linux - bash: useradd: command not found
- Command to check Last Login or Reboot History of Users and TTYs
- How to install and Configure sar sysstat tools in Ubuntu Linux
- How to use SCP Command to Copy Directory
- Linux Remove or Delete Files and Directories using Terminal Commands
- How to connect to SSH port other than default 22
- Install OpenSSL on Linux/Ubuntu
- How to fix: zsh: command not found: jupyter - zsh
- How to quit or exit SFTP Prompt on Terminal - Linux
- Facebook Thanks for stopping by! We hope to see you again soon. - Facebook
- REST API to get all Jira projects - Postman, Basic Auth - Jira
- -bash: startup.sh: command not found - Apache Tomcat 8 - Tomcat
- Know current Python Version - Python
- Send Email with attachment using SharePoint PowerShell, SMTP server - SharePoint
- How to get cURL Command to run in verbose mode? - cURL
If you are less or more command to view the file contents in the terminal, then simply press Q to return back to the Terminal prompt.