{"id":3738,"date":"2018-05-09T17:50:35","date_gmt":"2018-05-09T13:50:35","guid":{"rendered":"https:\/\/www.howtoforge.com\/linux-users-command\/"},"modified":"2018-05-09T17:50:35","modified_gmt":"2018-05-09T13:50:35","slug":"linux-users-command-tutorial-for-beginners-with-examples","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/linux-users-command-tutorial-for-beginners-with-examples\/","title":{"rendered":"Linux &#8216;users&#8217; Command Tutorial for Beginners (with Examples)"},"content":{"rendered":"<p>Sometimes, while working on the Linux command line, you might want to quickly check which all users are currently logged in to the system. Well, there&#8217;s a built-in Linux command line utility that lets you do this easily. The tool in question is &#8216;users&#8217;, and in this tutorial, we will discuss the basics of it using some easy to understand examples.<\/p>\n<p>But before we do that, it&#8217;s worth mentioning that all examples in this article have been tested on an Ubuntu 16.04 machine.<\/p>\n<h2 id=\"linux-users-command\">Linux users command<\/h2>\n<p>As already mentioned above, the users command prints in output the names of users who are currently logged in. Following is its syntax:<\/p>\n<p class=\"command\">users [FILE]<\/p>\n<p>And here&#8217;s how the tool&#8217;s man page explains it:<\/p>\n<pre>Output who is currently logged in according to FILE. \u00a0If FILE is not specified, use \/var\/run\/utmp. \u00a0\/var\/log\/wtmp as FILE is common.<\/pre>\n<p>The info page for &#8216;users&#8217; contains an even detailed explanation:<\/p>\n<pre readability=\"12\">`users' prints on a single line a blank-separated list of user names of<br\/>users currently logged in to the current host. Each user name<br\/>corresponds to a login session, so if a user has more than one login<br\/>session, that user's name will appear the same number of times in the<br\/>output. Synopsis:<p>users [FILE]<\/p><p>With no FILE argument, `users' extracts its information from a<br\/>system-maintained file (often `\/var\/run\/utmp' or `\/etc\/utmp'). If a<br\/>file argument is given, `users' uses that file instead. A common<br\/>choice is `\/var\/log\/wtmp'.<\/p><p>An exit status of zero indicates success, and a nonzero value<br\/>indicates failure.<\/p><\/pre>\n<p>Following are some Q&amp;A-styled examples that should give you a good idea on how the users command works.<\/p>\n<h2 id=\"q-how-to-use-users-command\">Q1. How to use users command?<\/h2>\n<p>It&#8217;s very simple &#8211; just execute &#8216;users&#8217;. Here&#8217;s an example:<\/p>\n<p class=\"command\">users<\/p>\n<p>On my system, the command produced the following output:<\/p>\n<pre>himanshu himanshu himanshu<\/pre>\n<p>So that means the user &#8216;himanshu&#8217; has logged in three times. Of course, depending upon your case, these names (and their number) could be different.<\/p>\n<h2 id=\"q-how-to-list-number-of-logged-in-users\">Q2. How to list number of logged in users?<\/h2>\n<p>Just in case you are only interested in the number of users currently logged in, you can use the &#8216;users&#8217; command in the following way:<\/p>\n<p class=\"command\">users | wc -w<\/p>\n<p>On my system, the above command produced &#8216;3&#8217; as output, which\u00a0is inline with the output shown in the previous section.<\/p>\n<h2 id=\"q-how-to-make-users-extract-info-from-a-specific-file\">Q3. How to make users extract info from a specific file?<\/h2>\n<p>BY default, the users command fetches information from files like:<\/p>\n<pre>`\/var\/run\/utmp' or `\/etc\/utmp'<\/pre>\n<p>However, if you want, you can make the tool extract information from some other file. In that case, you&#8217;ll have to pass the file name and path as input to the &#8216;users&#8217; command. For example:<\/p>\n<pre>users \/var\/log\/wtmp<\/pre>\n<h2 id=\"q-how-to-get-more-info-about-users-command\">Q4. How to get more info about &#8216;users&#8217; command?<\/h2>\n<p>While the users command doesn&#8217;t offer any exclusive command line option, the standard &#8211;help and &#8211;version options do exist so that you can get more info about the tool itself.<\/p>\n<p class=\"command\">users &#8212; help<\/p>\n<p class=\"command\">users &#8211;version<\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>As you&#8217;d have observed, the users command doesn&#8217;t offer many features &#8211; it just sticks to its basic task of providing names of users currently logged in to the system. So in that sense, it&#8217;s a handy tool. Just in case you need, here&#8217;s the tool&#8217;s man page.<\/p>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<p>\n<a href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.howtoforge.com%2Flinux-users-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/05\/linux-users-command-tutorial-for-beginners-with-examples.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-users-command%2F&amp;text=Linux+%27users%27+Command+Tutorial+for+Beginners+%28with+Examples%29&amp;via=howtoforgecom&amp;related=howtoforgecom\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/05\/linux-users-command-tutorial-for-beginners-with-examples-1.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/howtoforgecom\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/05\/linux-users-command-tutorial-for-beginners-with-examples-2.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/plus.google.com\/share?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-users-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/05\/linux-users-command-tutorial-for-beginners-with-examples-3.png\" height=\"20\" alt=\"\" title=\"\"><\/a>\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes, while working on the Linux command line, you might want to quickly check which all users are currently logged in to the system. Well, there&#8217;s a built-in Linux command line utility that lets you do this easily. The tool in question is &#8216;users&#8217;, and in this tutorial, we will discuss the basics of it [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-3738","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/3738","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=3738"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/3738\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=3738"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=3738"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=3738"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}