exit command in Linux with Examples Last Updated : 06 Sep, 2024 Comments Improve Suggest changes Like Article Like Report The 'exit' command is a fundamental command in Linux used to exit the current shell session. This command is widely used in scripting and command-line operations, allowing users and scripts to terminate a session or a process in a controlled manner. The 'exit' command can take an optional parameter [N], which specifies the exit status code to be returned upon exiting the shell. If no parameter is provided, the command returns the exit status of the last executed command.Syntax:exit [n]Options and Examples for the 'exit' Command1. Exit Without ParametersThe simplest use of the 'exit' command is without any parameters. When executed, it will close the current terminal session:After pressing enter, the terminal will simply close.2. Exit With a Specific Status CodeYou can specify an exit status code when exiting a session. This is useful for scripting and error handling:After pressing enter, the terminal window will close and return a status of 110. Return status is important because sometimes they can be mapped to tell error, warnings and notifications. For example generally, return status - "0" means the program has executed successfully. "1" means the program has minor errors.3. Exiting a Root SessionUsing "sudo su" we are going to the root directory and then exit the root directory with a return status of 5. After returning it will show how to display the return status code. 'echo $?' command is used to see the last return status.4. Displaying Help Information It displays help information. This command will display the help section for the exit command, providing an overview of its usage and options.Importance of Exit Status CodesExit status codes play a crucial role in Linux, especially in scripting and automation. They provide a way to indicate the outcome of command execution:0: Success – The command executed successfully without errors.1: General Error – The command encountered minor errors.2: Misuse of Shell Builtins – Indicates that a shell built-in command was misused.ConclusionThe 'exit' command in Linux is not just a simple way to close the terminal session—it’s a powerful tool that helps manage processes and scripts by using exit status codes. You can better control the flow of scripts and improve error handling and make your automation processes more reliable and robust with the help of specific exit codes. Comment More infoAdvertise with us Next Article exit command in Linux with Examples D DrRoot_ Follow Improve Article Tags : Technical Scripter Linux-Unix Technical Scripter 2018 linux-command Linux-Shell-Commands +1 More Similar Reads dump command in Linux with examples The dump command in Linux is used for backing up the filesystem to a storage device. Unlike commands that back up individual files, dump operates on entire filesystems, transferring data to tape, disk, or other storage media for safekeeping. One of its key advantages is the ability to perform increm 5 min read dumpe2fs command in Linux with examples dumpe2fs command is used to print the super block and blocks group information for the filesystem present on device. Can be used with ext2/ext3/ext4 filesystem for information. The printed information may be old or inconsistent when it is used with a mounted filesystem. Don't forget to unmount your 2 min read dumpkeys command in Linux with examples 'dumpkeys' command in Linux is used for the dump keyboard translation tables. It writes to the standard output and the current contents of the keyboard driver's translation tables in the format specified by Keymaps. Part of the kbd package, it displays the key bindings, function key strings, and com 4 min read echo command in Linux with Examples The echo command in Linux is a built-in command that allows users to display lines of text or strings that are passed as arguments. It is commonly used in shell scripts and batch files to output status text to the screen or a file. Syntax of `echo` command in Linuxecho [option] [string]Here, [option 3 min read ed command in Linux with examples Linux 'ed' command is used to start the ed text editor, a very minimal fronted line-based text editor. The lines are very simple in relation to other text files, hence easy to work on, for creating as well as editing, display, and manipulation of files. Since it was the first editor that was include 4 min read egrep command in Linux with examples The 'egrep' command in Linux is a powerful pattern-searching utility that belongs to the family of grep functions. It functions similarly to 'grep -E' by treating patterns as extended regular expressions, allowing more complex pattern matching without the need to escape special characters. This comm 3 min read eject command in Linux with examples eject allows ejecting a removable media (typically a CD-ROM, floppy disk, tape, or JAZ or ZIP disk) using the software. You can also control some multi-disc CD-ROM changers, the auto-eject feature (supported by some devices), and close the disc tray of some CD-ROM drives. Syntaxeject [...OPTIONS]The 4 min read emacs command in Linux with examples Introduction to Emacs Editor in Linux/Unix Systems: The Emacs is referred to a family of editors, which means it has many versions or flavors or iterations. The most commonly used version of Emacs editor is GNU Emacs and was created by Richard Stallman. The main difference between text editors like 5 min read env command in Linux with Examples The 'env' command in Linux is a versatile tool used to manage environment variables. It can print all the current environment variables, set new ones, or run a command within a custom environment. Additionally, 'env' is commonly used in shell scripts to launch the correct interpreter, ensuring the s 3 min read eval command in Linux with Examples eval is a built-in Linux command that executes arguments as a shell command. It combines arguments into a single string, uses it as input to the shell, and executes the commands. Syntaxeval [arg ...]Here, arg can be one or more arguments that eval will process and combine into a single shell command 2 min read Like