{"id":1090,"date":"2018-07-23T03:31:12","date_gmt":"2018-07-22T22:01:12","guid":{"rendered":"http:\/\/jaipurhosting.com\/blog\/?p=1090"},"modified":"2019-04-27T07:45:48","modified_gmt":"2019-04-27T02:15:48","slug":"10-who-command-examples-for-linux","status":"publish","type":"post","link":"https:\/\/www.jaipurhosting.com\/blog\/10-who-command-examples-for-linux\/","title":{"rendered":"10 \u2018who\u2019 Command Examples for Linux"},"content":{"rendered":"<p><strong>Description<\/strong><\/p>\n<p>One of the various commands we mentioned was the who command which displays users who are currently logged on to a Linux system, including the terminals they are connecting from.<\/p>\n<p>This article will explain some useful examples of who command in Linux .<\/p>\n<p>The basic syntax for using who command is as follows.<\/p>\n<pre class=\"theme:dark-terminal font:ubuntu-mono lang:default decode:true \"># who who [OPTION]... [ FILE | ARG1 ARG2 ]<\/pre>\n<p>&nbsp;<\/p>\n<p>1. If you run <strong>who<\/strong> command without any arguments, it will display account information (user login name, user\u2019s terminal, time of login as well as the host the user is logged in from) on your system similar to the one shown in the following output.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true\">[root@vps ~]# who\nroot pts\/0 2018-07-23 01:04 (123.14.15.26)<\/pre>\n<p>&nbsp;<\/p>\n<p>2. To print the heading of the columns displayed, use the <strong>-H flag<\/strong> as shown.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# who -H\nNAME LINE TIME COMMENT\nroot pts\/0 2018-07-23 01:04 (123.14.15.26)<\/pre>\n<p>&nbsp;<\/p>\n<p>3. To print the login names and total number of logged on users, use the -q flag.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# who -q\nroot\n# users=1<\/pre>\n<p>&nbsp;<\/p>\n<p>4. In case you want to show only hostname and user associated with stdin, use the &#8211;<strong>m switch<\/strong>.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# who -m\nroot pts\/0 2018-07-23 01:04 (123.14.15.26)<\/pre>\n<p>&nbsp;<\/p>\n<p>5. Next, to add user\u2019s message status as <strong>+, &#8211; or ?<\/strong>, use the <strong>-T<\/strong> option.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# who -T\nroot + pts\/0 2018-07-23 01:04 (123.14.15.26)<\/pre>\n<p>The who command also helps you to view some useful system information such as last boot time, current runlevel (<strong>target under systemd<\/strong>), print dead processes as well as processes spawned by <strong>init<\/strong>.<\/p>\n<p>&nbsp;<\/p>\n<p>6. To view the time of last system boot, use the <strong>-b flag<\/strong> and adding the <strong>-u<\/strong> option allows for listing of logged on users in the same output.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# who -b\nsystem boot 2018-07-23 12:54<\/pre>\n<p>&nbsp;<\/p>\n<p>7. You can check the current <strong>runlevel<\/strong> with the <strong>-r<\/strong> option.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# who -r\nrun-level 3 2018-07-23 12:55<\/pre>\n<p>&nbsp;<\/p>\n<p>8. The following command will print <strong>dead processes<\/strong>.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true\">[root@vps ~]# who -d\npts\/1 2018-07-23 11:10 9986 id=ts\/1 term=0 exit=<\/pre>\n<p>&nbsp;<\/p>\n<p>9. Furthermore, to see active processes spawned by init, use the <strong>-p<\/strong> option.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# who -p<\/pre>\n<p>&nbsp;<\/p>\n<p>10. The<strong> -a flag<\/strong> allows for printing of default output combined with information from some of the options we have covered.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# who -a\nsystem boot 2018-07-23 12:54\nLOGIN hvc0 2018-07-23 12:55 709 id=hvc0\nLOGIN tty1 2018-07-23 12:55 711 id=tty1\nrun-level 3 2018-07-23 12:55\nroot + pts\/0 2018-07-23 01:04 . 6861 (123.14.15.26)<\/pre>\n<p>&nbsp;<\/p>\n<p>We hope you\u2019ve found this useful!<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Description One of the various commands we mentioned was the who command which displays users who are currently logged on to a Linux system, including the terminals they are connecting from. This article will explain some useful examples of who command in Linux . The basic syntax for using who command is as follows. # [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1291,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1090","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1090","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/comments?post=1090"}],"version-history":[{"count":2,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1090\/revisions"}],"predecessor-version":[{"id":1137,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1090\/revisions\/1137"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/media\/1291"}],"wp:attachment":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/media?parent=1090"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/categories?post=1090"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/tags?post=1090"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}