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.
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 Find Where Mac Terminal App is Located? - MacOS
- PHP Warning: Cannot modify header information - headers already sent - PHP
- Where is adb command-line tool located? - Android
- [git] fatal: your current branch 'main' does not have any commits yet - Git
- Get the Current Working Directory using Java Code - Java
- Chrome move to next or previous tab using keyboard - Chrome
- ADT quit unexpectedly error on Mac OSX Android Eclipse SDK - Android
- Java C# foreach loop equivalent in Python Programming - Python
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.
Facing issues? Have Questions? Post them here! I am happy to answer!
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org