How to kill all open terminals using command lines in CentOs
I’m using putty to connect to Centos and sometimes it disconnect, and the open terminals on centos stays open, is there a way by a command line to close/kill all open terminals?
4 Answers 4
If you want to kill all open terminals except for the current one, you can use
pgrep bash lists the pids of all the active terminals
if the terminals refuse to die, you can use
the «-9» is used to send the SIGKILL Signal to the process
if you are using linux then just find out the process id of the putty
use ps -a to get PID of process then use kill PID
ps -ef | grep -E ‘ssh.*pts’ | grep -v grep |awk -F» » ‘
The above script it will give you the PID of those ssh pst connections on your machine; then as Vikas said you can kill those processes, remember be aware by using the kill command.
NOTE: you can use the last command where you can see a list of the current/olders session on your machine.
kill -9 PID1 PID2 PID3
Kill old login wit command:
You can use ‘screen’ program for reconnect from where your connection was lost.
Источник
How to close the Terminal?
I found many questions about how to open the terminal but cant find a question with an answer on how to close the terminal and return back to the desktop of Ubuntu (note: I am on virtual machine)
3 Answers 3
You can type exit . You can type ctrl — d . Or (if you’re on a virtual terminal), you use ctrl — alt — F8 .
ctrl + shift + w closes the current tab and ctrl + shift + q closes the entire window.
This is similar to other commands that also are normally ctrl + whatever such as, ctrl + c and ctrl + v for copy and paste which, in gnome-terminal are, ctrl + shift + c and ctrl + shift + v respectively.
I’m not sure if the following works in a virtual machine, however, it is important to also note that when you switch to a tty text session such as tty1 — tty6 using ctrl + alt + f1 up to ctrl + alt + f6 , you can return to the regular desktop xsession by pressing ctrl + alt + f7 typically or sometimes ctrl + alt + f8 .
TL;DR: Press Alt + F7 .
You are apparently asking how to close a virtual console, also known as a virtual terminal—a full-screen text terminal you got to by pressing a key combination like Ctrl + Alt + F1 , Ctrl + Alt + F2 , and so forth.
In infer this since you say you wish to «return back to the desktop of Ubuntu» (indicating you are not on your desktop now) and, in a comment, wrote:
my terminal in virtual machine is at a black background and when i type exit it refreshes its not a program .
Rather than actually closing your text-based virtual console, you probably just want to get back to the virtual console on which the graphical user interface is running. This is usually the seventh virtual console, so press Alt + F7 . ( Ctrl is optional when switching from a virtual console that does not have the GUI running on it; however, you must use it when switching from a virtual console that does have the GUI running on it.)
If those key combinations do not work—or change the virtual console of the host rather than the guest—and your Ubuntu system is a VirtualBox guest system, see How do I switch between virtual terminals in a guest system? as suggested by LiveWireBT.
Another way, which is much less often used, is to run the command chvt 7 .
Источник
close the terminal without terminating the process
I started an installation process from a terminal and have two questions about this:
- How can I close the terminal without terminating the installation process? and how can I restore it again?
- How can I figure that this terminal has finished processing from another terminal so that I can do other processes based on the result of the first terminal?
1 Answer 1
For 1. you need to send your running process to the background and remove the associated job from current shell.
- Press Ctrl + Z and type bg to send the installation process to the backgroud
- then type disown .
You can now close the terminal, the process will still be alive. You can open another terminal and check its process id with ps -aef
In my case the process id is 14426 . Unfortunately there’s no easy way to reattach it to another terminal (See How to attach terminal to detached process?) unless you used something based on screen .
For 2. You can use the following command:
It will print ok when the process is over from an other terminal. You can of course change this echo command with something more complex.
Источник
How to really clear the terminal?
I can issue the clear command or press Ctrl + L to clear the current Ubuntu terminal, but this just shifts previous output upwards and if you use mouse scroll or PgUP and PgDown keys it’s hard to distinguish where the output of previous command ends and output of current command begins.
Is there a way to really clear the terminal so I won’t see previous command results?
12 Answers 12
Yes, the command you’re looking for is
In contrast to clear , or Ctrl + L , reset will actually completely re-initialise the terminal, instead of just clearing the screen. However, it won’t re-instantiate the shell (bash). That means that bash’s state is the same as before, just as if you were merely clearing the screen.
As @Ponkadoodle mentions in the comments, this command should do the same thing more quickly:
From the other answers:
You can set a Keyboard Shortcut to reset the terminal, as explained by towolf.
If you’re running Kubuntu, and your terminal is Konsole, you need to go to Edit → Clear history, since reset doesn’t work the same way there, as UncleZeiv notes.
I was looking for this for a while and I found some genius that posted this:
Clears the whole screen buffer, very clean. Works on OS X and believe it works fine on most *nix terminals.
For curious, this part ‘\e[3J’ is a terminal escape command.
/.bashrc and add alias reset=»clear && printf ‘\e[3J'»
You can also assign a shortcut in gnome-terminal by going to Edit → Keyboard Shortcuts. I use Shift + Ctrl + Alt + C .
Cross posting my answer from stackoverflow.
Use the following command to do a clear screen instead of merely adding new lines .
yes that’s a ‘printf’ on the bash prompt.
You will probably want to define an alias though.
Explanation
So this becomes c which is the VT100 escape code for resetting the terminal. Here is some more information on terminal escape codes.
Here are a few other ways of doing it.
The above does not work on the KDE console (called Konsole) but there is hope! Use the following sequence of commands to clear the screen and the scroll-back buffer.
Or perhaps use the following alias on KDE.
I got the scroll-back clearing command from here.
run this command:
This has the same effect as launching a new terminal.
My favorite is printf «\ec» . This can also be printf «\033c» or printf «\x1bc» . That is an ansi escape sequence that miraculously clears the screen and buffer for the terminal output (for most standard terminals I have worked in it seems — I know it works in such as gnome-terminal, terminator, xterm, etc. on Ubuntu-like Linuxes)
I know this works in Linux Mint and Ubuntu 14.04, so I don’t know why people are appending and prepedning things like clear && echo -ne «\033c . printf «\ec» has always worked for me.
Additionally, in my .bashrc I have a binding like this:
Источник
Close Terminal window from within shell script (Unix)?
Is there a way to close a Terminal window from within a shell script? I have a .command file that should just get out of the way once it’s done.
6 Answers 6
Using exit 0 will cleanly terminate the script.
Whether Terminal window stays open is user-configurable. The default is to always stay open. To change this:
When «Close if shell exited cleanly» is used, the script will close the window if the exit result is 0, which is the default if nothing went wrong.
Since you don’t want to delete all Terminal windows, first change the name of your window from «Terminal» to something else:
Then at the end of the script, use:
osascript -e ‘tell application «Terminal» to close (every window whose name contains «My Window Name»)’ &
You can use apple script to quit the terminal app . Add the following to your script —
This will give you a popup confirming to close the app. You can disable this in Terminal preferences.
Alternatively, you can also use killall command to quit the app. The following would work just as well.
Just as a side note, you can freely add the above commands to your script and it would work as you want. However, there are few caveats. First being you will limit the ability of your script to work on different boxes. Secondly, it would be safer to use nohup so that any commands that are currently running won’t quit due to quitting of the Terminal app .
This works for me:
This will work for closing just your windows opened with a .command file but leave things already running in other terminal windows. I know that I almost always have either sass or grunt watch something so I don’t want to quit terminal totally.
This will close the Terminal window for your script and keep any other Terminal windows open as long as their window titles don’t match. For it to work Terminal will have to be added to the list of applications permitted to use the Accessibility framework. You can also cycle through Terminal windows with a repeat command and close every window x that contains a UI element «Close» on sheet 1.
I find the best solution for this is to use Automator to create a true OSX application which will work the same way regardless of how your system is configured. You can have the Automator run your shell script, or you can embed the shell script itself in Automator.
Here is how you do it:
- Run Automator (in Applications).
- Choose «New Document» and when it asks «Choose a type for your document» choose «Application»
- In the left panel, select «Utilities» then «Run Shell Script».
- Type in your script commands in the workflow item in the right panel. You can either call another shell script, or just put your commands in their directly.
- Save the Application, which will be a full-fledged Mac App. You can even cut-and-paste icons from other apps to give your script some personality.
Источник