I'm using nano inside a MATLAB session that is running inside a screen (-x) terminal. I accidentally hit Ctrl-Z and it immediately leaves nano, prints "Use "fg" to return to nano", but does not show a command prompt. Whatever I type appears on the screen but nothing responds. If I hit Ctrl-Z, ^Z just prints to the screen. Any ideas? Using 12.04.

  • You should have a prompt after hitting ctrl-z. I have... it seems that this is not happening in your case. How exactly do you run nano in the terminal? – Rmano May 16 '14 at 20:07
  • I just realized I'm not really using 12.04. I am in fact running nano from inside a MATLAB session, which is (obviously) the problem (sorry about neglecting to mention that; I'd forgotten I was in MATLAB). Calling jobs in another screen does not list any jobs to pull up. – user282315 May 16 '14 at 22:35

In the comments the author says that he or she is running the nano command from Matlab, and that there is no prompt whatsoever after suspending it with CTRL-Z. This is probably a bug in Matlab(1) which should not allow a CTRL-Z arrive to nano if it can't cope with it...

The problem is that the shell command fg (and bg, and jobs) works only with direct children of the shell. But you can continue a stopped process from another shell, although this will not guarantee that the status of the screen is correctly managed:

  1. in another terminal window, find the nano process:

    % ps ugx | grep nano
    romano   10600  0.0  0.0  20784  1628 pts/11   T    16:52   0:00 nano prova
    romano   10653  0.0  0.0  18256   900 pts/11   S+   16:53   0:00 grep nano
  2. Notice that it is stopped (state T)

  3. Continue it with

    kill -CONT 10600 

...and hope it works (can mess up the terminal greatly). You can also trying a

killall -CONT nano 

that way the CONT signal is sent to all the "nano" processes (shouldn't be a problem though).


(1) I tried with octave: EDITOR=nano octave and then edit file in octave. Pressing CTRL-Z messes the things up quite well... so maybe it's not Matlab but a strange interaction on who receive and manage the TSTP signal.

| improve this answer | |
  • Awesome, that did it. This issue had been bothering me for a while! Logging a bug with TheMathWorks. Thanks! – user282315 May 16 '14 at 23:08
  • 1
    Alas, new account, no reputation to upvote (yet). – user282315 May 16 '14 at 23:11

If it's the only backgrounded process entering % followed by Return should return you to nano.

That said, fg should always work. Even when you have more than one job, it should bounce you back to the newest one.

| improve this answer | |
  • 7
    imo, this is the real answer, it does what the op ask's , reopen the closed (ctrl+z) Nano windows. – DonSeba Oct 26 '15 at 8:25
  • cool tricks here. – pietrovismara Oct 23 '17 at 9:42
  • This help me too. – Chaklader Asfak Arefe Dec 24 '17 at 4:55
  • 1
    This should be the right answer. – user2180794 Feb 15 '18 at 3:08
  • This solution saved my day! – Maryna Klokova Jun 26 at 8:44

List your jobs


Bring a job to the foreground

fg 1

change the "1" to the job number corresponding to nano.

See also https://unix.stackexchange.com/questions/30228/basic-job-control-stop-a-job-add-a-job-onto-the-stack-and-fg

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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