Is there a command to close a terminal window via commandline?
9 Answers
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.
exitis 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.
2I 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.
1You 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
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
bgand then disown it, eg:
vlc
^Z
[1]+ Stopped
bg[1]+ vlc & disown
exitThis 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