Artificial intelligent assistant

Determine which tty is in the "foreground" / "currently displayed"? In linux I can use the key combinations `Alt-Ctrl-F1`,`Alt-Ctrl-F2`... to switch to different `tty1` as I could use `man chvt`. using the command `tty` I also get displayed the teletype/linux virtual console I am on. However if I am in `xterm` or in `gnome-terminal` tty will display the relevant pseude-terminal. Given all that: * How can I tell which is the currently "active" `tty` (meaning it being displayed on the screen)? This would be somewhat the solution (however it seems contorted and relies on loginctl logind, there must be a **non-systemd** to find out): for sessionid in $(loginctl list-sessions --no-legend | awk '{ print $1 }'); do loginctl show-session -p State -p TTY $sessionid; done | grep "State=active" -B1 | head -n 1 | sed 's/.*=//g'

cat /sys/devices/virtual/tty/tty0/active


`tty0` refers to the current virtual console (compare this answer). By reading `/sys/devices/virtual/tty/tty0/active` you can learn which console this is.

"Current" means what you see, not where `cat` is running. E.g. if you start this loop


while sleep 1; do
cat /sys/devices/virtual/tty/tty0/active
done


let in run, manually switch to another console, wait few seconds and switch back, then you will see the other console was reported when you looked at it.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy f366da33a0681cfe3eb443ba8e8da267