Is there a command to close a terminal window via commandline?

9 Answers 9


To close a terminal window you can use the exit command . Alternatively you can use the shortcut ctrl+shift+w to close a terminal tab and ctrl+shift+q to close the entire terminal including all tabs.


You can use the ^D shortcut - that is, hitting Control and d. This works in many shells and shell-like environments. Technically speaking, this key combination emits the end-of-transmission character (ASCII code 04). In gnome-terminal, i.e. bash and other shells, this is interpreted as finishing the interactive session. You can also see this behavior in programs like cat which read from standard input (the keyboard). Try running it without arguments; you can terminate by entering ^D.

  • I like this shortcut!
    – themefield
    Sep 28, 2018 at 16:01

is the command you want to use for that.


There is an alternate way, which requires a bit more keystrokes, but is worth knowing.

Using exec command

  • Syntax
exec <command-name>
  • This will first execute the <command-name> and then exit the shell.

  • For example, you could do:

exec sleep 1

          which would, effectively, close the window after 1 second.

  • It doesn't quite "exit" the shell, but it rather replaces the shell's process with the <command-name>. When command terminates, process exits. Nov 30, 2015 at 11:46
  • Exactly what I was looking for. Running python scripts with bash and killing them later
    – Josh
    Jul 25, 2019 at 16:20

I know this answer is a little bit late but, If you are using Ubuntu or another Linux distro, simply use Ctrl+D to close the entire terminal.

I initially tried all the rest and they were just not working. For example I see people recommending exit but honestly, it just doesnt work.

I hope someone agrees with me.

  • 2
    Ctrl + D works indeed, but in my case "exit" has always been working too... It's weird that it doesn't for you.
    – FloT
    Nov 7, 2019 at 14:03

You can use xdotool:

xdotool getactivewindow windowkill

Notice that this will kill all active windows!

If you want to kill only the current window use:

xdotool key --clearmodifiers Ctrl+Shift+Q key --clearmodifiers KP_Enter

  • Welcome to AskUbuntu. A good answer that can be improved. "Try using" is the hallmark of a suggestion and suggestions should go in comments. Replacing it with "You can use" makes it into a proper answer. I'll suggest an editing.
    – user589808
    Oct 18, 2016 at 10:11
  • CelticWarrior Tnx!!!
    – Yonti
    Oct 18, 2016 at 11:11
  • That's the command I was looking for! Billion thanks!!!
    – Redbob
    Aug 11, 2018 at 15:27

Yes there is.First type echo $$ in terminal to know it's process id. Then type kill -9 processid.


To close the terminal whilst leaving all running processes to continue running, you can do the following:

  • pause the process using Ctrl + Z , pull it into the background with bg and then disown it, eg:



[1]+ Stopped


[1]+ vlc & disown


This will leave the current running process running in the background and close the terminal(i find this to be very useful).


Yes. The command is exit. Type exit into the terminal and press enter

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