1

I was ssh'ing into a Raspberry Pi running Raspbian, editing a file with nano, when I lost my internet connection (by leaving the WiFi zone). After reconnecting an hour later, I found that the pi had kicked me out, but after logging back in, I saw that it did not stop the task. When I reopened nano, it told me that the file was being edited by the previous nano process, and it gave me the PID. I made substantial changes to the file and forgot to save, but presumably the changes are still there.

How can I tell nano to save & quit (^O -> Enter -> ^X) or reopen the task in a new shell, from outside the original process?

AAM111
  • 131
  • 3
    It's unlikely you'll be able to reattach to that session, or send it anything meaningful. If nano 'knows' that the file is open, there's a good chance that the temporary save has been written somewhere and this serverfault answer may be how you are required to resolve this: https://serverfault.com/questions/453703/can-i-recover-a-nano-process-from-a-previous-terminal – cunninghamp3 May 03 '18 at 21:12
  • 1
    One of nano’s online man pages indicates it will write buffers out to files named nano.save if it receives a HUP or TERM signal. Test on an innocent file first! – Jeff Schaller May 03 '18 at 21:16
  • maybe this link will help you : https://unix.stackexchange.com/questions/31824/how-to-attach-terminal-to-detached-process?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – D'Arcy Nader May 03 '18 at 21:16
  • I see a <myfile.py.save> file in my directory, thanks @JeffSchaller, would you like to write an answer? – AAM111 May 03 '18 at 21:17
  • I would, but cannot right now. Please feel free to do so yourself. – Jeff Schaller May 03 '18 at 21:33
  • And next you'll get used to starting a screen session before doing any serious remote editing :) – ivanivan May 03 '18 at 21:50
  • Yeah, before I asked this question, I didn't even know what that is. However, now that I'm trying to run it, bash tells me it has no idea what screen means. – AAM111 May 03 '18 at 21:52
  • tmux is a functional alternative to screen – Jeff Schaller May 03 '18 at 22:26
  • tmux also not found @JeffSchaller – AAM111 May 04 '18 at 00:18

1 Answers1

2

In the comments, @JeffSchaller noted that a terminated nano process saves the unwritten file in file_path.extension.save.

If it is there, which it was for me, it is a simple matter of mving the file into its original name.

AAM111
  • 131