On Unix I'd just use vi, but I don't know what the command is on Windows. I am actually trying to edit files over SSH with Windows Server 2008.
edit filename
I won't vouch for its functionality and outdated GUI but it is installed by default, even on Windows 7.
Edit: Except 64 bit versions of Windows.
-
14
-
15Odd... evidently it's installed by default on Windows 7 32-bit, but not on Windows 7 64-bit. That's sad. – nhinkle Sep 10 '10 at 4:12
-
7@nhinkle: I seem to recall reading something about 16-bit apps being unavailable under 64-bit windows installs. – intuited Sep 10 '10 at 4:34
-
9Confirmed NOT working in Win 10... I really cant believe Windows is lacking such basic tools and nobody even seems to care – Rafael T Aug 30 '17 at 11:59
-
3This is just wrong answer when talking about "Windows" generally. Today, Windows is also Win7-64bit, Win8-64bit, Win8.1-64bit, Win10. "edit" cannot be the correct answer to the question from today's point of view. – Mehrdad Mirreza Nov 9 '17 at 10:40
The simplest solution on all versions of Windows is:
C:\> notepad somefile.txt
And, no extra software required.
-
48
-
4Ah. Right. Windows doesn't have a command-line editor built in. You'll probably need to install the Gnu version of the editor you want to use. Since you've already installed the
ssh
server, that should be no problem for you. – BillP3rd Sep 10 '10 at 4:27 -
11
-
13useless answer, both for ssh users and for those who wants to edit files IN cmd window, not outside it – vladkras Feb 14 '16 at 7:10
-
5This will not work in a Docker container based on 'windowsservercore' – Peter Mortensen Aug 28 '18 at 9:17
From a Windows command prompt enter copy con followed by the target file name. (copy con c:\file.txt
).
Then enter the text you want to put in the file.
End and save the file by pressing CTRL-Z then Enter or F6 then Enter.
If you want to change text in an existing file simply display the text by using the command type
followed by the file name and then just copy and paste the text in to the copy con
command.
-
12Hard core. Try not to make any typos, or you'll have to start over again. Well, backspace does work if you catch the mistake before you press Enter. – Kevin Panko Dec 3 '13 at 18:57
-
Doesn't seem to work with psexec. Tried to edit my hosts file with
copy con hosts
but ^Z doesn't save and ^C doesn't cancel! Had to close the cmd window to get out. The file was unchanged. – Iain Samuel McLean Elder May 27 '14 at 11:17 -
-
2In a Docker container based on 'windowsservercore' (CMD), Ctrl + C worked for the terminating key sequence. – Peter Mortensen Aug 28 '18 at 9:30
If you're used to vi and don't want to settle for the built-in editor you can get Vim for Windows. It'll run from a command shell. Or try WinVi.
-
3this should me marked as answer because
edit
has been removed from win 10 – Luke Jun 14 '18 at 18:36 -
4It is much better than that: It also works inside a Windows Docker container (it is easiest to get the "Win32 console executable", e.g. vim81w32.zip - unzip and copy
vim.exe
to wherever it is accessible in the Docker container). – Peter Mortensen Sep 15 '18 at 23:38
Believe it or not, EDLIN.EXE
is still around <shudder>
at least on this Vista system.
Excuse me while I sob softly to myself...
-
7
-
2
-
2edlin is a 16-bit program, therefore it is not available in 64-bit versions of Windows. However, I won't be surprised if someone here claims it's still present in the 32-bit version of Windows 10. – TSJNachos117 May 12 '15 at 7:54
-
1
-
I don't know about SSH, or anything (else?) server-related, so forgive me if this "solution" is useless. If you want to edit files in the command prompt, you can get the Windows version of Nano.
As a side note, those little ^
signs at the bottom of the window are supposed to represent the Ctrl button. For instance, ^X Exit
means that you can exit the program using Ctrl-X.
Also, Nano will sometimes add extra newlines when saving files. This seems to be some kind of bug with Nano's word wrapping.
I've also seen ports of vi for Windows, although I've used one that just seem to make command prompt window as small as it can be, leaving only a title bar (which means the rest of the window may as well be invisible, since you can't see what you're doing). However, the Windows version of Vim seems to work quite nicely.
-
2Before lookig for those "may work but are useless solutions" i thought for a Windows port of Nano. It's using cygwin.dll and nothing more. I've picket the lightest version i can, from netcologne.dl.sourceforge.net/project/nano/nano/1.0.8/…. Thank you. – m3nda Jan 26 '17 at 16:46
-
As @gman pointed out, if you have git installed, then you already have
nano.exe
. Also, it's pretty easy to install nano via the command line by using chocolatey ( chocolatey.org/install#individual ). After chocolatey is installed, install nano by typingchoco install nano
. – cowlinator Jul 17 '20 at 17:01
If you have git installed for windows then most likely nano and vim are both available at
C:\Program Files\Git\usr\bin\nano.exe
C:\Program Files\Git\usr\bin\vim.exe
To run from a command prompt (cmd.exe)
"c:\Program Files\Git\usr\bin\nano.exe" <filename>
To run in powershell
& 'C:\Program Files\Git\usr\bin\nano.exe' <filename>
They both work great even over ssh.
-
Thank you! Git imo is a more reasonable dependency that's likely already on the server, as opposed to WSL or other 3rd-party text editors. – Konafa Jul 12 '20 at 1:02
2020 UPDATE:
On Win10 just enable the linux subsystem then you'll have most of the linux stuff like vim
and nano
:
c:> bash
$: nano yourfile.txt
-
1
-
1OK, just googled this - good idea, but installing an entire linux distro to enable a terminal editor? It's a stretch. Still might try it tho' ;) – Thomas Kimber Aug 8 '20 at 10:30
If the remote computer has Windows Subsystem for Linux installed, you can type bash
to have the next commands interpreted by WSL. From here, you can type nano FILENAME
or vim FILENAME
or whatever your preferred Linux text editor is. To exit WSL and return to regular Command Prompt, type exit
or logout
.
This came in handy when I was accessing a Windows Jupyter Notebook server and wanted to edit .gitattributes
, a hidden file which isn't shown in the Jupyter GUI. This answer is based on SajanGohil's comment above.
Use vim or nano.
Install vim with with choco install vim
using the chocolatey package manager.
(There might be Scoop version available as well, but I haven't checked.)
Although nano also exists as choco package, it is very outdated. Instead manually install this nano. However, when using over SSH, nano control characters get a bit confused, so you may lose some, since windows use it's own API for controlling screen characters, and not POSIX. So although a lot of work is currently in progress for future Win10 compatibility.
Then you can run with: nano -cg some.txt
, but the cursor will only show up at the right location when you push CTRL-L
. (Which is why vim is preferred.)
-
2
-
cmd
then you can use notepad e.g. withnotepad myfile.txt
– ccpizza Aug 16 '19 at 13:25