exit Command in Linux

Learn via video courses
Topics Covered

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

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.
Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science

Options in exit Command in Linux

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

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

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

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

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.