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
- Command to know the Available Memory on Linux System
- How to install curl on Alpine Linux
- How to backup a file in Linux/Unix
- Install Java Runtime Environment (Oracle or open JRE) on Ubuntu
- What is the Default Admin user and Password for Jenkins
- How to tar.gz a directory or folder Command
- Copy entire directory using Terminal Command [Linux, Mac, Bash]
- Fix: bash: ipconfig: command not found on Linux
- Command to check Last Login or Reboot History of Users and TTYs
- Linux: Create a New User and Password and Login Example
- ls command to list only directories
- bash: cls: command not found
- How to exit from nano command
- Installing and using unzip Command to unzip a zip file using Terminal
- What does apt-get update command does?
- ls command: sort files by name alphabetically A-Z or Z-A [Linux/Unix/macOS/Bash]
- How to remove or uninstall Java from Ubuntu using apt-get
- scp: ssh: connect to host xxxx port 22: Connection refused Error
- Sort ls command by last modified date and time
- Create Nested Directories using mkdir Command
- How to Exit a File in Terminal (Bash/Zsh)
- Command to know the installed Debian version?
- How to connect to SSH port other than default 22
- How to save a file in Nano Editor and Exit
- Install OpenSSL on Linux/Ubuntu
- How to create a tar.gz file using Java - Java
- How to display only IP address using Terminal command - HowTos
- How to Export a man page using Mac Terminal to a file - MacOS
- Android Development: Spinners with Example - Android
- How to Download and Install Roblox Studio on Mac (M1/M2/Intel) - MacOS
- How to Display Current Date and Time in UTC/GMT in Mac Terminal - MacOS
- Fix - Java: invalid source release: IntelliJ IDE - Java
- How to Split on String in Java with Regular Expressions by Dot. - Java
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.