It is Quite Pathetic To Hold the Delete/Backspace Key of Any in Text Editor Like Nano or Vi in SSH Session. Here is a Practical Cheat Sheet. Is not it a common day to day fact which we need to do? Suppose, you want to copy the codes from Nginx HSTS Preload settings, what you normally do? Highlight all the text from code block and hitting Command and C or CTRL and C and pasting on your local computer’s plain text editor – TextEdit or Notepad. Then? To replace all the contents of a file which has been opened on Text Editor, we can never highlight and delete the text in Nano or Vi. Unless you use VNC, it is never possible to use the mouse in that way – there is no Graphical User Interface plus SSH will not support such risky thing. You can only copy from SSH session and paste on your local computer’s plain text editor – TextEdit or Notepad. Select and Delete All Text of a File In SSH Session With Cursor, in other words – not possible like we do in GUI. There are alternative ways.
Alternative To Select and Delete All Text of a File In SSH : SFTP is Easiest
We have so many server instances, that basically we need a GUI like thing to just copy-paste a part. We use SFTP software FileZilla along with iTerm2 / Terminal. Suppose I need to open and paste a new stuff on this file :
What I do is, keep the SSH session ON via iTerm2 / Terminal as root user and login to FTP as root user. Amazon and HP Cloud will not support FTP login in that direct way. Rackspace, DigitalOcean will support. If root login is possible via FTP, then simply to the location :
Double clicking on FileZilla will open on TextEdit. Do whatever you want, save changes on local computer, FileZilla will prompt you to change the copy on server. In the example, run nginx config test and reload nginx. Simple.
But, if root login on SFTP is not possible, then you will have to copy the file from SSH where the SFTP user can Edit and move the file from SSH. A bit roundabout way, but better than writing by hand. SFTP also gives a visual idea about the files and directories.
There is command line SFTP too, if you hate FileZilla GUI.
You can probably CUT on Nano from mICROSOFT windozzz with Putty.
Alternative To Select and Delete All Text of a File In SSH : Just Empty the File From SSH
If you want a full copy paste – that is replacing all the content. Officially, in Nano, to select text, you need move the cursor to the start of the place from where you want to select, then press the key combination to mark the starting, then move the cursor to the end of the section you want to select. Long story, worser than SFTP method. To empty a file, you can simply use this method I am telling you. If the file was
/etc/nginx/sites-available/default, which I will empty to paste full stuff, I would use this command :
echo " " > /etc/nginx/sites-available/default
A slight overdose is, how to PREVIEW a file on SSH without opening with nano or vi? Simply run cat :
cat is important pet for command line, you can run this funny command to read more :