You might have tried, unsuccessfully , to use ctrl + c
and ctrl + v
to copy-paste things in your terminal. This happens because the terminal interprets the ctrl + c
key combination as a kill signal that kills the command that is currently running. So far, all the commands we tested are finished within a fraction of a second, but by the time you run more complex commands you will be risking killing it if you use ctrl + c
.
In this case, you need a different strategy, of course they would not let us struggle typing every thing! There are many ways to copy and paste to and from a terminal (which ones you have available will depend on your system), one is more adventurous and risky than the other. You will see why …
If what you want to copy from the terminal, you just need to select the text you want to copy like in the image bellow:
After that you ONLY need to press the scroll (or middle) button of your mouse
Try this method now! You can just copy something from your history of commands and try to run this line again. You can look into your history
and use the create folder command then list your directory to check if it was created correctly.
If you still feel the need to make a few clicks to be more comfortable, you can right click on your mouse and chose “copy” before pressing the scroll button.
The other way to copy & paste might be a bit more risky, but you can be as adventurous as you like! If you do ctrl + shift + c
you can copy something in your terminal (in most terminals) and following with ctrl + shift + v
you can past into the terminal prompt or use the mouse scroll button as said before.
Just keep in mind that if you do ctrl + c
instead of ctrl + shift + c
you are killing the running process!
NOTE: this only applies while you’re interacting with your terminal application. If, for example you paste into a document then your usual paste shortcut applies.
All the programs (commands) we run so far are finished in a fraction of a second, so it is safe to try the above option. Try to remove the new folder, and create it again, but by copying the name and pasting it into the mkdir
command!
To finish a stubborn process that refuses to terminate, Linux provides the kill 😱 command.
Before we explain how to use this deadly command, we will first look at a few other commands that can be helpful. The df
(disk free) command allows to check how much disk space each process is using:
The ps
(process status) allows to see which processes are running. To see more details about these processes you use the ps aux
variant.
In both cases the most important info is the process ID (PID), you need it to kill the process.
To kill a process gracefully, you use the kill
command followed by the PID of the process you want to terminate:kill 2436
If even that doesn’t finish the process, you can it kill it -whatever it takes- via the -9
option:kill -9 2436
1 – Click to do exercise in a controlled environment:
LinuxSurvival (disk space, stop after exercise 61)
2 – Click to do exercise in a controlled environment:
LinuxSurvival (pattern matching, part 2)