9

I'm not talking about closing the terminal window itself which you can easily do by using the exit command. I'm talking about closing a tab that you have originally opened up by pressing the CtrlShiftT key combination. When I'm done working with it, I would like to close it down without lifting my hands up from the keyboard and going for the mouse to click that small X button. Is there a command for that?

enter image description here

  • 6
    Just exit the shell (ctrl-d)? The other tab will remain open. – muru Mar 4 '16 at 13:06
  • So, I can use either exit or Ctrl+D to close a tab. Thank you. – misha Mar 4 '16 at 13:11
  • A keyboard shortcut could actually be useful if you're trying to close a tab with a frozen unresponsive ssh session... – Yibo Yang Aug 11 '16 at 2:51
26

When the shell process inside the terminal tab exits, it will close. If it was the only tab, the entire window will close. So you just have to quit the Bash session.

Your Bash session quits...

  • when you type the command exit.
  • when you press Ctrl+D to send an EOT ("End Of Transmission") code.
    Note that it must be pressed when the command prompt is empty, i.e. you haven't typed anything else on that line yet.

Please also note that you can nest multiple interactive shells. You can start a new shell inside the current one by running e.g. bash, sh, python, bc, ... The exit and Ctrl+D will always only terminate the currently active shell, which is usually the innermost one.

  • when you press ctrl-d ... on an otherwise empty prompt. – muru Mar 4 '16 at 14:10
  • @muru Yes, that's correct. I'll add it. – Byte Commander Mar 4 '16 at 14:13
  • another small addition: if you are inside more than 1 shell ... it will exit the shell and not close the tab. (ie. "bash" "bash" "bash" requires 4 control-d's for the tab to close) – Rinzwind Mar 4 '16 at 15:10
  • @Rinzwind Ooohhhkay... I'll add that as well ;-) – Byte Commander Mar 4 '16 at 15:21
  • 1
    Might be worth noting that Ctrl+u will clear the current line of the terminal so ctrl+u, ctrl+d will exit. – Holloway Mar 6 '16 at 10:32
24

From the GNOME Terminal help:

  • Close Tab: ShiftCtrlW
  • Close Window: ShiftCtrlQ
  • 3
    Those are the defaults. See "Terminal" "preferences" "shortcuts" in case these do not work and "someone" changed them and forgot about the change. The other answers are ever so slightly flawed: exit or control-d only works on the 1st level (if you type "bash" you need 2 exits) and on an empty prompt. – Rinzwind Mar 4 '16 at 15:08
8

You already mentioned it, type exit and the tab (as well as the terminal session running within the tab) will be closed.

1

Like @YiboYang mentioned in comments, it is not possible to do Ctrl + W or exit in some cases:

A keyboard shortcut could actually be useful if you're trying to close a tab with a frozen unresponsive ssh session.

That shorcut can be viewed/changed from the Menu bar, via File>Terminal>Preferences>Shortcuts

GNOME terminal preferences

It is highlighted in the image above. Double-click on the Shortcut key and simple key-in a new combination to assign to it,

E.g. I have set mine as Ctrl + W to be synchronous with the standard browser shortcut to close a tab.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.