Is there a way to switch to the last terminal tab with some commands or bash script?

What I have got so far:

  • To switch to the next tab:

    xdotool key ctrl+Page_Down
  • To get the number of terminal tabs:

    let terminal_counts=$(ls /dev/pts/  | wc -l)-1

Now I need to know how many times I need to execute xdotool key ctrl+Page_Down. How to know the current tab number?

  • You didn't mention it but Ctrl+PageUp takes you to the previous terminal tab (but not the last terminal tab). Oct 3, 2019 at 3:32

1 Answer 1


In gnome-terminal.. there is inbuilt function without assigning any shortcut key..

you can assign a shortcut key by Selecting Edit -- >> Preferences -- >> Shortcuts -->> Switch to Last Tab and by pressing valid key/ key combination like below


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .