1

I opened 4 terminals but when check them with who or w

me@alpha:~$ w
 17:28:19 up  3:09,  1 user,  load average: 0.51, 0.35, 0.34
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
me :0       :0               14:20   ?xdm?   3:27   0.01s /usr/lib/gdm3/gdm-x-session --run-script env GNOME_SHELL_SESS
me@alpha:~$ who
me   :0           2019-01-16 14:20 (:0)

It display only one termianl called ':0'

if on macos it will display

me at mbp in ~
$ who
me  console      2019-01-04 08:57
me  ttys000      2019-01-04 08:57
me  ttys001      2019-01-04 08:57

How could display all the terminal ?

Sergiy Kolodyazhnyy
  • 103,293
  • 19
  • 273
  • 492
Alice
  • 1,640
  • 3
  • 18
  • 36
  • amazing, yes @SergiyKolodyazhnyy – Alice Jan 16 '19 at 10:50
  • Well, very nice ! Welcome to Ask Ubuntu ! 欢迎 – Sergiy Kolodyazhnyy Jan 16 '19 at 10:52
  • 谢谢, 来学习了。 论语说“學而時習之”。 學 效也, 效倣, 模倣, imitate . 習, 練習(白羽), 幼鳥 煽動 剛剛髮育的白色的羽毛。 @SergiyKolodyazhnyy – Alice Jan 16 '19 at 11:31
  • 1
    学习是君子之乐 :) 我没读过《论语》,只是偶尔看《周易》的卦解释,但是希望以后能学到了更多古文。这样以后看《三生三世十里桃花》会看懂更多的:) 那你也以后多模倣啊,要提升Linux水平为了写在这里的答案吧,哈哈。 – Sergiy Kolodyazhnyy Jan 16 '19 at 11:45

1 Answers1

2

The issue is due to how certain terminals work. In particular, sakura and gnome-terminal (Ubuntu's default) which I have used before do not register the terminal. There is, in fact, a bug report for gnome-terminal, which is closed with WONTFIX status.

Finding number of open terminal sessions, therefore, should be focused on finding parent processes of shell sessions or associated pts/tty devices, as shown in this question:

$ ps -eo tty= | sort -u 

The only issue with this command is that it should display processes from all users. My personal approach would be to filter out my own processes ( i.e. terminals I opened myself ) via -u option and parse with awk:

#  Note that this includes tabs as well, not just open windows
$ ps -u $USER -o tty | awk 'NR>1 && $1 != "?" {a[$0]++};END{for(val in a) print val}'
Sergiy Kolodyazhnyy
  • 103,293
  • 19
  • 273
  • 492