Get a list of open windows in Linux

wmctrl -l may be what you're looking for. The wmctrl program can also perform some simple actions on the windows like moving them around and setting their properties.


xlsclients shows the running clients and xwininfo -root -children shows all children of the root window. That also includes some stuff your window manager or desktop renders.


Here is the way to show names only:

wmctrl -l|awk '{$3=""; $2=""; $1=""; print $0}'

because wmctrl -l shows a bit extra info rather than just names required in the question:

like this:

0x020002c6  0 ruslan-Latitude-E6410 fromscratch
0x04600007  0 ruslan-Latitude-E6410 Psensor - Temperature Monitor
0x01600007  0 ruslan-Latitude-E6410 Top Expanded Edge Panel
0x01600017  0 ruslan-Latitude-E6410 Bottom Expanded Edge Panel
0x0200000a -1 ruslan-Latitude-E6410 Desktop
0x05a0000c  0 ruslan-Latitude-E6410 ruslan@ruslan-Latitude-E6410: /var/lib/apt
0x05600085  0 ruslan-Latitude-E6410 index.html (~/Dropbox/cpucraft.com/fromscratch) - gedit

and filtering it by awk we get only names of open windows:

   fromscratch
   Psensor - Temperature Monitor
   Top Expanded Edge Panel
   Bottom Expanded Edge Panel
   Desktop
   ruslan@ruslan-Latitude-E6410: /var/lib/apt
   index.html (~/Dropbox/cpucraft.com/fromscratch) - gedit
   ubuntu - Get a list of open windows in Linux - Super User - Mozilla Firefox
   [email protected] - FileZilla

If you want simply the titles and no other information (not even whitespace), you can use this:

wmctrl -l | grep -o "$HOSTNAME.*" | sed "s/$HOSTNAME //g"

Result:

linux - How to grep and replace - Stack Overflow - Pale Moon
How can I use a variable in sed? | Unix Linux Forums | Shell Programming and Scripting - Pale Moon
Delete everything after characters * or # or & in text file with GREP - Stack Overflow - Pale Moon
Video.mp4 - VLC Media Player