Quick Creation of Text Files From the Command Line

Quick Creation of Text Files From the Command Line

  • Comments 1
It's a sunny day here in the Seattle area, so let's have some command line fun.  :)

Have you ever needed to create a small text file while working at a command line?  I've been using the following technique since my MS-DOS days. 

Creating files at the command line is very simple, using the copy command.  Here's how:

  1. While in a Command Prompt window, navigate to your desired folder.  I will use c:\test in this example.
    C:\> cd test
  2. Instruct the copy command to copy the console (CON) data to your file (ex: notes.txt)
    C:\test> copy con notes.txt
  3. Type your desired text
    This is a simple file created via the copy command
  4. Save the file using Ctrl+Z and pressing the Enter key
    The console window will show the following
    ^Z
            1 file(s) copied.

If you decide you do not wish to create the file, you can cancel using Ctrl+C and pressing the Enter key.

It is important to note that once you press the Enter key (on any line of your file), it is not possible to go back and make changes.  For this reason, for any file longer than a line or two, I don't recommend this technique.  I suggest using Notepad or your favorite text editor instead.

I was searching the Microsoft Help and Support site while writing this and found the following additional tip:

Appending a Line to a File with COPY Con or ECHO

This tip is extremely cool if what you are looking to do is add a line or two to an existing file.

Enjoy!
-- DK

Disclaimer(s):
This posting is provided "AS IS" with no warranties, and confers no rights.

 

  • If you use cygwin (FWIW, it plays well with .bat scripts and regular .exe while letting you harness the true power of a unix command line) all you need to do is:

    echo "This is a simple file" > file.txt

    and if you want to append:

    echo "This is a simple addition" >> file.txt

    Now -- what's the equivalent when using the Monad shell? ;-)
Page 1 of 1 (1 items)