Dreaded ctrl Z when editing the Shorewall rules file

gazchap

New Member
Joined
Jan 23, 2024
Messages
11
Reaction score
1
Credits
113
Hi guys.

I had the dreaded ctrl Z typo when editing a Shorewall rules file with Nano. I am aware that this accidental keystroke combo is not that uncommon and pushes the process into the background, but I find that all the usual command solutions of fg or % or jobs etc. just advise there is no process. However, if I try to edit the rules file again, I see the usual warning that the file is being edited by root and does show the PID of Nano. Question: is there a simple way to get back to the running Nano process, or if I try to just kill the process is that risky? FYI - I had accidentally pasted an IP address into the file when I when trying to copy it out of the console (not my best work), so there are no changes or edits that I need to keep, I just need to exit Nano without corrupting the file. Any advice or guidance would be very much appreciated. Thanks, Garry.
 


If you are referring to a terminal, to see the terminal line settings, you can run:
Code:
[tom@min ~/notes]$ stty -a
speed 38400 baud; rows 55; columns 65; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D;
eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q;
stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V;
discard = ^O; min = 1; time = 0;
<snip>
where, for this terminal, cntl+q will start the terminal again, after being stopped by cntl+s or suspended by cntl+z. Not all terminals however honour these commands.
 
Last edited:
Thanks for the reply, much appreciated. To keep me on the right track here, I ran the stty -a command and crtl q is indeed the assigned setting to start the terminal again. What I am not clear on is should I run that after trying to edit the file again where I get the warning that root is editing the document, or from the main terminal if I log back in via SSH? Sorry for dumb questions but I don't have a full grip on the terminal commands just yet. Below is what I see when trying to edit the file again.

Do I simply answer No then use ctrl Q to get back to Nano?

Thanks again, Garry.
1706686422516.png
 
No need for "sorry". I don't see these questions as "dumb". Most linux users likely once asked such like.

My understanding of your situation may not be accurate, but below is what comes to mind, and please feel free to correct misinterpretations.

It looks to me that you are inside nano rather than in the terminal, (though nano is running in the terminal), so the terminal commands will not have effect, rather, nano's commands will control the screen.

The following is the behaviour on this machine running nano as root in relation to cntl+z.
When opening a file in nano, the cntl+z command produces on screen a notice in red:
Code:
[ To suspend, type ^T^Z ]

Since I don't wish to suspend, I ignore the notice and continue writing text in the file.
The notice then disappears.
Then I continue in the normal nano manner to write the file, and exit with these commands:
ctrl+o - which brings up the name of the file to write;
<enter> - to write the file;
cntl+x - to exit nano and return to the terminal.

In your image of nano, I presume you wish to edit the file, in which case you can select Y for Yes, and then edit it, write it and exit.

The range of nano commands are available inside nano if you hit cntl+g, for "help". The info is terse, but one can experiment. To see all of the info in the help display one needs to page down to the end. You may be familiar with all of this, and wish to amend the interpretation.
 
No need for "sorry". I don't see these questions as "dumb". Most linux users likely once asked such like.

My understanding of your situation may not be accurate, but below is what comes to mind, and please feel free to correct misinterpretations.

It looks to me that you are inside nano rather than in the terminal, (though nano is running in the terminal), so the terminal commands will not have effect, rather, nano's commands will control the screen.

The following is the behaviour on this machine running nano as root in relation to cntl+z.
When opening a file in nano, the cntl+z command produces on screen a notice in red:
Code:
[ To suspend, type ^T^Z ]

Since I don't wish to suspend, I ignore the notice and continue writing text in the file.
The notice then disappears.
Then I continue in the normal nano manner to write the file, and exit with these commands:
ctrl+o - which brings up the name of the file to write;
<enter> - to write the file;
cntl+x - to exit nano and return to the terminal.

In your image of nano, I presume you wish to edit the file, in which case you can select Y for Yes, and then edit it, write it and exit.

The range of nano commands are available inside nano if you hit cntl+g, for "help". The info is terse, but one can experiment. To see all of the info in the help display one needs to page down to the end. You may be familiar with all of this, and wish to amend the interpretation.
Thanks for that, all great advice and info. I will tackle it tomorrow, 6.30 pm here in Darwin now. All of your help is very much appreciated. Cheers, Garry.
 
Isn't it just easier to use vi/vim?
 
I think you are the best with vim.

You can open our file with

vim /your/file.conf

than press i to edit the file

than press esc to close edit mode.

than press : than w than q ( :wq ) for write and quit.

Thats it problem solved
 

Staff online


Top