Open In App

Shell Scripting – Logout Command

Last Updated : 02 Aug, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The logout command is a Linux/UNIX shell command that performs the task of logging out the logged-in user from the system in that session, programmatically. Logout only works in logon shells, not in the non-logon shells. The difference is as follows:

  • Login-Shell uses invokes the ~/.bash_profile whereas the Non-Login shell invokes the ~/.bashrc first.
  • Login-Shell is preferred when the system environment has multiple users.

Syntax

$ logout

Output

The logout command gives verbose output. After execution, it takes the user to the login screen of the Linux distro used.

.bash_logout File in Linux

The .bash_logout file is executed only when a login shell is invoked. The purpose of the file is to clear the screen after logout in the terminal for better privacy measures.

Location: The .bash_logout file is located in the $HOME folder of the system. It could be viewed by the following command

cat ~/.bash_logout

Editing the .bash_logout file

The file can be edited by usual file editors such as nano or vim like any other file, and the commands edited in the file will be executed at the logout of login shell. 

 

A console like the following will open on the execution of the above command; assuming that the user has nano editor installed. In the nano console, the .bash_logout file can be edited at will, like any regular shell script.

 

Sample file

A screenshot of the .bash_logout file is attached below.

Sample .bash_logout file in kali linux


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads