14

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

3
  • 6
    Just exit the shell (ctrl-d)? The other tab will remain open.
    – muru
    Mar 4, 2016 at 13:06
  • 1
    So, I can use either exit or Ctrl+D to close a tab. Thank you.
    – misha
    Mar 4, 2016 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, 2016 at 2:51

4 Answers 4

30

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.

6
  • 1
    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, 2016 at 15:10
  • EOT, AKA EOF :D
    – cat
    Mar 4, 2016 at 18:48
  • @tac no, EOF is "End Of File". EOT is something else, although triggering EOT on a blank input line generates an EOF for the listening program. To learn more, I recommend you to read this answer from Stack Overflow.
    – Byte Commander
    Mar 4, 2016 at 19:15
  • @ByteCommander I've never encountered a situation in which the difference is significant. EOF is to EOT as ETX is to SIGINT
    – cat
    Mar 4, 2016 at 20:23
  • 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, 2016 at 10:32
27

From the GNOME Terminal help:

  • Close Tab: ShiftCtrlW
  • Close Window: ShiftCtrlQ
1
  • 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, 2016 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.

You must log in to answer this question.

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