How do I edit text files in the Windows command prompt?

101

26

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.

Casebash

Posted 2010-09-10T03:41:43.813

Reputation: 5 677

2

I think the accepted answer should be changed to squillman's (as it is the only one that will work on most contemporary PCs - and possibly inside Docker containers).

– Peter Mortensen – 2018-09-07T17:11:51.880

if you do have a graphic desktop but simply want to edit a file directly from cmd then you can use notepad e.g. with notepad myfile.txt – ccpizza – 2019-08-16T13:25:33.950

Answers

53

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.

Mike Fitzpatrick

Posted 2010-09-10T03:41:43.813

Reputation: 15 062

1It doesn't work on Win10 x64 as well. It seems then they don't have a DOS editor option for 64 bit windows. Now a days Notepad and other GUI editors seems to be the only option then. – RBT – 2016-11-01T09:22:59.430

How do I install it on Windows 7 64bit? – Lucas Soares – 2017-08-22T16:03:06.060

4Confirmed NOT working in Win 10... I really cant believe Windows is lacking such basic tools and nobody even seems to care – Rafael T – 2017-08-30T11:59:32.570

2This 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 – 2017-11-09T10:40:22.153

14On all versions of Windows? There is no "edit" on Windows 7 apparently. – Snark – 2010-09-10T03:53:31.033

14Odd... evidently it's installed by default on Windows 7 32-bit, but not on Windows 7 64-bit. That's sad. – nhinkle – 2010-09-10T04:12:06.290

This command only freezes when I try to call it! – Casebash – 2010-09-10T04:18:35.140

6@nhinkle: I seem to recall reading something about 16-bit apps being unavailable under 64-bit windows installs. – intuited – 2010-09-10T04:34:03.207

1this should not be the accepted answer. who uses 32bit nowadays? – F.H. – 2019-06-17T14:20:51.530

It doesn't work on win8 x64. – Jo Smo – 2014-02-28T13:58:20.237

73

The simplest solution on all versions of Windows is:

C:\> notepad somefile.txt

And, no extra software required.

BillP3rd

Posted 2010-09-10T03:41:43.813

Reputation: 5 353

My biggest problem with notepad is it doesn't handle different style newlines. – wisbucky – 2014-10-01T19:15:30.590

9useless answer, both for ssh users and for those who wants to edit files IN cmd window, not outside it – vladkras – 2016-02-14T07:10:17.390

30Nice, but not over SSH – Casebash – 2010-09-10T04:10:42.830

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 – 2010-09-10T04:27:50.893

5This will not work in a Docker container based on 'windowsservercore' – Peter Mortensen – 2018-08-28T09:17:52.613

Like BillP3rd said... just run cmd as administrator, then enter notepad filename, save it and that's it. ;) – Jo Smo – 2014-02-28T13:57:55.253

8Like OP said... "I am actually trying to edit files over ssh..." – daviewales – 2014-04-13T03:16:45.370

45

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.

Mordorf

Posted 2010-09-10T03:41:43.813

Reputation: 451

Note: F6 can be used instead of [Ctrl]-[Z] – MonoThreaded – 2014-09-13T09:58:55.640

In a Docker container based on 'windowsservercore' (CMD), Ctrl + C worked for the terminating key sequence. – Peter Mortensen – 2018-08-28T09:30:06.117

8Hard 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 – 2013-12-03T18:57:23.280

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 – 2014-05-27T11:17:46.447

16

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.

squillman

Posted 2010-09-10T03:41:43.813

Reputation: 5 676

this should me marked as answer because edit has been removed from win 10 – Luke – 2018-06-14T18:36:39.170

3

It 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 – 2018-09-15T23:38:05.477

9

Believe it or not, EDLIN.EXE is still around <shudder> at least on this Vista system.

Excuse me while I sob softly to myself...

Paused until further notice.

Posted 2010-09-10T03:41:43.813

Reputation: 86 075

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 – 2015-05-12T07:54:32.690

1@TSJNachos117 It is indeed in x86 Windows 10. – Brian Duddy – 2016-10-12T01:19:51.060

Not surprised at all. – TSJNachos117 – 2017-01-30T21:44:32.577

6It was finally deleted in Windows 7 (at least the 64-bit versions). – paradroid – 2010-09-10T07:11:25.680

1@jason404: It's still included in 32-bit Windows 7. – Paused until further notice. – 2010-09-10T15:08:56.077

8

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.

TSJNachos117

Posted 2010-09-10T03:41:43.813

Reputation: 291

2

Before 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 https://netcologne.dl.sourceforge.net/project/nano/nano/1.0.8/nano-1.0.8.zip. Thank you.

– m3nda – 2017-01-26T16:46:17.537