La terminal of commands of Windows, also known as CMD or Symbol of the system, remains one of the most powerful and versatile tools for any user who wants to take the next step. file management without leaving the command line. It often seems like a museum piece, but it's still there and can get you out of more than one tight spot.
If ever you wondered How to read, write, and manipulate text files from CMDHere's the ultimate guide: from the simplest operations like creating or viewing files to advanced commands for automating everyday tasks.
Why use CMD to manage text files?
You might ask yourself, Why bother using the console if Windows Explorer is there? And it's as simple as a double-click? There are several compelling reasons:
- Speed and efficiency: When you have a lot of tasks, commands allow you to do them in seconds, without having to open windows and menus.
- Automation possibilities: You can create scripts that perform repetitive tasks in a single step.
- Advanced Access: Some operations are only possible or more powerful from the command line, such as changing file permissions in bulk, editing text in batches, or controlling user processes.
- Low resource consumption: The terminal consumes minimal power, perfect for older devices or when you need full power for other tasks.
How to open the CMD terminal step by step
The first thing is to know How to enter the Command Prompt (CMD). It's very simple:
- From the Windows search bar: Click the Windows icon, type “cmd” or “command prompt,” and press Enter.
- Using the Run window: Press the keys Windows + R, type “cmd” and hit OK.
- As an administrator: If you need elevated permissions (some commands will ask for them), search for "cmd" in the Start menu, right-click, and select "Run as administrator."
Fundamental Concepts: Commands You Need to Know
Before we get into the nitty-gritty of reading, writing, and manipulating text files, it's a good idea to review a few things. essential CMD commands that will help you move like a fish in water:
- CD: Change directory (current folder). For example, cd Documents takes you to the “Documents” folder.
- DIR: Displays the contents of the current folder.
- MD: Create a new folder.
- RD: Deletes a folder (must be empty).
- TIME: Deletes a file.
- MOVE: Move files or folders from one location to another.
- COPY: Copies files from one directory to another or combines them.
- TYPE: Displays the contents of a text file on the screen.
These are just the tip of the iceberg, but they cover what you need to get started working with text files quickly.
Reading text files from CMD
View the contents of a text file It is possibly the simplest and quickest task from the command line. Here the absolute protagonist is the command TYPE.
For example, if you are in the path where your file is located and you want to see what “notes.txt” contains:
TYPE notas.txt
As soon as you press Enter, the entire text will be displayed on the screen. If you have multiple files and want to read them all at once, you can do so like this:
TYPE notas.txt resumen.txt
This will consecutively display the contents of both files as if they were one.
Other methods for reading files and working with content
If the file is very long and you are interested in consulting it little by little, you can combine TYPE with the command MORE:
TYPE notas.txt | MORE
Each page of content will be displayed until you press a key, allowing you to review the file in blocks.
Additionally, from the console you can redirect the output of a file to another command, for example, to search for a word:
TYPE notas.txt | FIND "palabra_clave"
This will locate lines containing “keyword” within the file.
Create new text files from CMD
To create an empty text file or with content, there are several paths, and all are equally valid:
- Using COPY and NUL file: If you just want to create an empty file:
COPY NUL archivo_nuevo.txt
This will create a file with that name in the current path.
- Create and write to the file directly: To create and write in one go, you can use COPY as follows:
COPY CON archivo_nuevo.txt
Escribe aquí el texto que quieras.
Cuando termines, pulsa Ctrl+Z y Enter.
The file will be saved with the written content.
Write and edit text files from the terminal
Editing an existing file from CMD is not as straightforward as in a graphical editor, but there are effective ways to do it:
- Replace the content completely: You can overwrite a file, creating a new one and replacing the old one:
echo Este es el nuevo contenido > archivo.txt
That command deletes everything that was previously in "file.txt" and replaces it with "This is the new content". If you like add text without deleting the above:
echo Otra línea de texto >> archivo.txt
The double greater than symbol (>>) indicates adding to the end of the file.
Useful commands for manipulating text files from CMD
The CMD provides you with a range of additional commands that will be useful for working with text:
- FIND: Search for a specific word or phrase in a file. Example:
find "error" log.txt
- FINDSTR: More advanced than FIND, it allows you to search by patterns or regular expressions.
findstr /i "palabra" archivo.txt
- FC: Compares two text files and marks the differences:
fc archivo1.txt archivo2.txt
- CLIP: Copies the output of a command to the clipboard. For example,
type archivo.txt | clip
to copy all its contents. - MORE: Displays the contents of a file page by page, ideal for long texts.
type archivo.txt | more
Copy, move, and delete text files
Traditional file management operations are still within reach, and using the console is even faster:
- COPY: Copy a file to another folder or rename it.
copy archivo.txt carpeta_destino\archivo.txt
- XCOPY: Ideal for copying entire directories, including subfolders and files.
xcopy carpeta1 carpeta2 /E
(the /E option also includes empty folders) - MOVE: Move a file to another folder or rename it.
move archivo.txt carpeta_destino\
- TIME: Delete files.
del archivo.txt
- REN: Rename a file.
ren archivo.txt nuevo_nombre.txt
Advanced Management: Text File Permissions and Attributes
With ATTRIB You can view and modify the attributes of any file, including text files. A practical example:
ATTRIB +R archivo.txt
This marks it as read-only. You can add other attributes like hidden (+H), system file (+S), etc. To remove an attribute, use the – (minus) sign:
ATTRIB -R archivo.txt
Automation: How to create batch scripts to work with text files
A great advantage of CMD is that you don't have to type each command every time. You can join several into one .bat or .cmd file and run them all together. For example, imagine you want to create a script that copies the contents of a text file, searches for it in another, and shows you the differences:
@echo off
type archivo1.txt > temporal.txt
findstr /v /i /g:temporal.txt archivo2.txt > solo_en_archivo2.txt
del temporal.txt
Simply save this in a .bat file and run it from the console. This way, you can create small, custom utilities for your daily text management.
Combining Commands: Useful Terminal Operators and Tricks
CMD allows you to run multiple commands at once or make the execution of one dependent on the previous one:
- &: Executes both commands, one after the other, regardless of whether the first one was successful.
comandoA & comandoB
- &&: The second command is only executed if the first one was successful.
comandoA && comandoB
- ||: The second command is only executed if the first one failed.
comandoA || comandoB
Essential stories and keyboard shortcuts to work faster
In the terminal, as in everything, There is gold. Some shortcuts and Tricks can make your life easier:
- Up and down arrows: : Scroll through the command history.
- F7: Displays a window with the command history.
- F3 and F1: Repeat the last command (F3 full, F1 letter by letter).
- Ctrl + C: Cancels the running command.
- Tabulator: Autocompletes file or folder names.
What to do if you need to manipulate files of other formats?
CMD can create, delete and move files of any type, but the Direct editing from the console is only possible for plain text files. If you need to work with documents of Become, PDF or other complex formats, you can create empty files or move them, but you cannot edit them from CMD. For this, there are commands like fsutil file createnew:
fsutil file createnew ruta\nombrearchivo.ext tamaño_en_bytes
But be careful, this command creates an empty file with the specified size; it doesn't fill it with useful data if you don't know how to structure that type of document.
Reading and writing files on other systems: the case of Octave
For those who work with different environments, like Octave, the function fopen () allows you to open files to read, write or add data, with different modes:
- 'r': Read only.
- 'r+': Reading and writing.
- 'w': Write (overwrites).
- 'w+': Read and write (overwrite).
- 'to': Write at the end (add).
- 'a+': Read and write at the end.
These modes are very similar to the typing and appending options in the ECHO and > / >> commands in CMD, making it easier to switch between the two systems if you need to.
Other useful and lesser-known commands
CMD has an almost endless list of commands, but there are also less common ones that can help you in specific situations:
- FC /a /c /w: Compares files ignoring case or whitespace.
- DIR /b: Shows only the names of files and folders in a directory, without further details.
- FINDSTR /S: Searches for a string in all files in a folder and its subfolders.
- DOSKEY / HISTORY: View the history of commands executed in the current session.
- TREE /F: Displays the hierarchy of folders and files in tree form.
UPDATE: The Edit command is back, and it's back as open source.
El The edit command in Microsoft refers to the text editor called MS-DOS Editor, a utility included in older versions of Windows (such as Windows 95, 98, and some console versions of Windows XP). Here's how to use it, assuming you're in a supported environment or emulating DOS (e.g., with DOSBox), or You can use Edit on Windows now that it's open source....
edit is a console-based text editor that allows you to view, create, and modify text files. basic syntax is
edit [file_name]
For example, to open the editor without any files:
edit
If you want to edit, create a file with a specific name, or edit an existing file named like this:
edit document.txt
If the document.txt file exists, it opens it for editing. If it doesn't, it creates it.
Simple graphical environment in text mode and you won't have much trouble using it. Remember that you can save with Alt + F, then S for Save. And to Exit with Alt + F, then X.
Passionate writer about the world of bytes and technology in general. I love sharing my knowledge through writing, and that's what I'll do on this blog, show you all the most interesting things about gadgets, software, hardware, tech trends, and more. My goal is to help you navigate the digital world in a simple and entertaining way.