exit Command in Linux
Transform Your Career
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
Overview
The exit command in Linux is a built-in command which is used to terminate the shell where it is currently being executed. It's a fundamental yet essential command to learn as it forms the basis of many scripts and operations in Linux. It can be run manually by the user or can be incorporated into scripts to provide an exit status.
Syntax of exit Command in Linux
The basic syntax of the exit command in Linux is as follows:
Where:
- exit: This is the main command that instructs the shell to terminate.
- [n]: This optional argument signifies the exit status. If this argument is not given, the command will return the status of the last executed command.
Options in exit Command in Linux
-
No option: The exit command in Linux does not have any options or flags.
For example -
Output:
This command simply terminates the current shell without returning any exit status.
Scaler Placement Report and Statistics
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Example Usages
-
Basic usage of the exit command in Linux:
Output:
Explanation: In this case, the exit command is used without any argument. Hence, it just terminates the shell without providing any exit status.
-
Using exit command in Linux with an argument:
Output:
Explanation: In this example, the exit command is followed by an argument '5'. Hence, the command terminates the shell and returns an exit status of 5.
Tips
-
The exit status can be used to troubleshoot issues or to perform different actions based on the status.
-
Although the exit command does not have any flags or options, the exit status can be used as a powerful tool.
Turn Learning into Career Growth
Advanced Use Cases of exit Command in Linux
- Using exit command in a bash script to terminate based on a condition:
Output:
Explanation: This is an example of how the exit command can be used in a script. Here, if the condition is met, the script terminates with an exit status of 1.
Conclusion
-
The exit command in Linux is used to terminate the shell.
-
The exit command can optionally return an exit status, which can be used for various purposes.
-
While it does not have any options or flags, the exit command is incredibly versatile in its usage, particularly within scripts.




