Shell Script to Find How Many Terminals Has User Logged-In Last Updated : 24 Feb, 2022 Comments Improve Suggest changes Like Article Like Report Here we are going to see Find How Many Terminals Has User Logged In. Using who command to fetch the user list and then using grep command we can find the number of Terminal that the user has logged in the Linux. We can use LOGNAME or UID to identify the user. UID is a unique User ID assigned to every user that logged in the system, it is an integer value. The LOGNAME is the unique username of the user it can be alphanumeric. We can use the following command to know the username of the current and its user ID: For Username/LOGNAME echo $LOGNAME Output: Displaying username For UID(User ID): id -u Here, -u represents that we are interested in user ID. Output: Displaying user ID Approach : Taking input from TerminalCheck if the input is UID or LOGNAMEFrom the user list find all the numbers of Terminal that are opened via input UID.Then read the passwd file from etc directory that contains all the information about users. Below is the implementation: #! /bin/bash # Taking input from user echo "Enter LOGNAME OR UID" read input # checking if input is a UID or LOGNAME if [[ $input ]] && [ $input -eq $input 2>/dev/null ] # If input is UID then echo "Number of terminals are " cat /etc/passwd | grep $input -c # If input is LOGNAME else cat /etc/passwd>userlist echo "Number of terminals are " grep -c $input userlist fi Output: Using LOGNAMEUsing UID Comment More infoAdvertise with us Next Article How to Open Multiple Terminals in Ubuntu A amnindersingh1414 Follow Improve Article Tags : Linux-Unix Shell Script Similar Reads Shell Scripts to Find How Many Users are Logged In Every operating system provides a feature of multiple user accounts. Linux-based operating systems have some commands or functionalities to check user accounts' details and change them. This ability is mainly used by the admin account user that is the root user, to provide permissions and access to 7 min read How to Send a Message to Logged Users in Linux Terminal? Linux is a solution to the data center. It is flexible, stable, secure, and reliable. There are many users logged into servers for development purposes, testing, and usage. There are various tools to send messages to other users, but they do not allow widespread sending or sending to specific users 5 min read How to List all Users in the Mongo Shell In MongoDB, user management is an essential aspect of database administration, allowing administrators to control access and permissions for different users. The Mongo Shell provides a powerful interface to interact with MongoDB including managing users. In this article, we'll explore how to list al 3 min read How to Use Heredoc in Shell Scripting The Heredoc or Here Document is an input literal used by many programming and scripting languages. The Heredoc was originally used in UNIX Shells and is in fashion till date and, is supported by all popular Linux shells such as zsh, bash, tsh, etc. The symbol for a Heredoc is '<<' two left che 6 min read How to Open Multiple Terminals in Ubuntu As a programmer or developer, we may feel insufficient to use only one terminal or window. We need more than one terminal to easily navigate through code files or do another installation task. This problem is also faced by the system administrators as well as the DB administrators because we may nee 5 min read Shell Script to Display the Exit Status Using Grep Command Linux provides users a great cool feature of the command-line tool along with a graphical user interface where they can perform tasks via ruining command. All of this command returns a status according to their execution. Its execution value can be used for showing errors or take some other action i 4 min read Like