As other answers have already explained, Ctrl+C doesn't kill Nano because the input of nano is still coming from the terminal, and the terminal is still nano's controlling terminal, so Nano is putting the terminal in raw mode where control characters such as Ctrl+C are transmitted to the program and not intercepted by the terminal to generate signals.
When intercepted by the terminal, Ctrl+C generates a SIGINT signal. If you know the process ID of nano (you can find out with ps u -C nano (Linux ps syntax) or pgrep nano or other process listing utility), you can send this signal with kill -INT 12345 where 12345 is the PID. However, SIGINT conventionally means “return to main loop”, and Nano doesn't exit when it receives SIGINT. Instead, send SIGTERM, which means “terminate gracefully”; this is the default signal, so you can just run kill 12345. Another possibility is kill -HUP 12345; SIGHUP means “you no longer have a terminal, quit gracefully unless you can live without”. If all else fails, send SIGKILL (kill -KILL 12345, or famously kill -9 12345), which kills the program whether it wants to die or not.
Many programs, including Nano, recognize Ctrl+Z to suspend. This is the same sequence that sends the SIGTSTP signal. If the program recognizes this control key, you get back a shell prompt, and since the program becomes a background job, you can easily kill it with kill %% (which sends a signal to the job that has last been put into the background).
With Nano, there is an alternate way: send it its exit key sequence, i.e. Ctrl+X followed if necessary by N for “don't save”. But as a general matter, remember this:
- Try Ctrl+Z followed by
kill %%, and if this doesn't kill the program kill -9 %%.
- If Ctrl+Z didn't work, switch to another terminal, find out the process ID (you can use
ps -t pts/42 to list the processes running on the terminal /dev/pts/42) and kill it.
nano xyz > abc. Similar withvim– Karthik T Dec 20 '12 at 5:15Ctrl+Z, thenkill %1to get rid of it... – ire_and_curses Dec 20 '12 at 5:17nanocatches SIGSTOP too – Michael Mrozek♦ Dec 20 '12 at 7:20Ctrl+Zandkill %1does something, i.e. it returnsReceived SIGHUP or SIGTERM. Searching for the process usingps aux | grep nanoreturns[1]+ Terminated nano head_of_data_url_script_2012-12-17_112253.txt | uniq. So,Ctrl+zis a solution, right? – Nikos Alexandris Dec 20 '12 at 8:38