
red Command in Linux
In Linux, red generally refers to the ed text editor that runs in "restricted mode", which is where the name comes from. This restricted mode limits the editorâs functionality to prevent users from accessing or editing files outside of the specified scope. As a result, it enhances security in controlled environments.
The red editor is a minimalistic, line-based text editor designed for simplicity and efficiency. It is particularly useful for scripting or environments where a graphical interface is unavailable. Despite its simplicity, red offers powerful text-editing capabilities tailored for advanced users who are comfortable with command-line operations.
In this chapter, we'll explore what red is, its syntax, installation process, usage examples, best practices, and troubleshooting tips to help you make the most of this powerful tool.
Table of Contents
Here is a comprehensive guide to the options available with the red command â
- What is red in Linux?
- Syntax of red Command
- red Command Options
- How to Install Red Command?
- How to Use Red Command in Linux?
- Security Restrictions in Red: Disabled Shell Commands
- Best Practices to Use red Command in Linux
What is red in Linux?
red is a command-line text editor in Linux. It is derived from the ed editor and operates in a restricted mode. It is mainly used for editing text files line by line. This makes it suitable for environments with limited resources or scripting purposes.
red is not designed for filtering or manipulating data in pipelines like sed or awk. However, it is useful for automating repetitive text-editing tasks in shell scripts.
Although red is not pre-installed on all Linux distributions, it can be easily installed using package managers.
Syntax of red Command
The red command can be executed using the following basic syntax −
red [options] [file...]
Here, options represent optional flags or parameters and file indicates the file(s) you want to process. If no file is specified, red will read from the standard input.
In most cases, red is used in a pipeline, where the input is passed through the command from another command in the chain.
red Command Options
The red command comes with several options that are described in the following table −
Option | Description |
---|---|
-E, --extended-regexp | Enables the use of extended regular expressions. |
-G, --traditional | Operates in compatibility mode. |
-l, --loose-exit-status | Returns a status of 0 even if a command encounters an error. |
-p, --prompt=STRING | Sets the interactive prompt to the specified STRING. |
-r, --restricted | Executes the command in restricted mode. |
-s, --quiet, --silent | Hides diagnostic messages, byte counts, and the â!â prompt. |
--version | Displays the installed version of red. |
--help | Prints a help page summarizing the available options. |
For a detailed understanding of options, you can refer to the manual page −
man red

How to Install Red Command?
Red is essentially the ed text editor running in "restricted modeâ. It comes bundled with the ed package, so installing ed also makes red available on your system.
To install ed (and access red) on Debian/Ubuntu-based systems, use the following command −
sudo apt install ed
You can access red on Red Hat/CentOS-based systems by installing ed using the following command −
sudo yum install ed
Fedora users can utilize dnf package manager to install red on their systems −
sudo dnf install ed
Pacman can be used on Arch Linux to install and use red −
sudo pacman -S ed
If ed is unavailable in your distribution repository, you may need to add extra repositories or download the source code to build it manually.
How to Use Red Command in Linux?
Letâs go through some practical examples to understand the usage of the red command in Linux.
- How to Create a New File in red?
- How to View a File Content in Red?
- How to Edit Specific Lines in Red?
- How to Delete Specific Lines in Red?
- How to Search Specific Text in Red?
- How to Append New Text to File?
How to Create a New File in red?
Letâs create a file named exampleTutorials.txt −
red exampleTutorials.txt
Now add some content to it −
a tutorialspoint.com Welcome to tutorialspoint.com . w q
Here, âaâ enters append mode to add text after the current line. After this type your lines. â.â ends the append mode. âwâ writes (saves) the content to the exampleTutorials.txt file and q exits the editor −

In the above figure, the number 49 indicates the total bytes written to the file, including all characters, spaces, and newline characters.
How to View a File Content in Red?
To display the fileâs content use the following command −
red exampleTutorials.txt 1,$p q
Here, "1,$p" prints all lines from the first to the last ($ refers to the last line) −

How to Edit Specific Lines in Red?
We can update a specific line(s) using the red command, as follows −
red exampleTutorials.txt 2c Let's learn Linux commands with tutorialspoint . w q
In this example, we use "2c" to change the second line while "." ends the line change and "w" saves the changes −

The output shows that the updated byte count is 66.
How to Delete Specific Lines in Red?
We can use the d command to delete a specific line(s) −
red exampleTutorials.txt 2d w q
Here, 2d deletes the second line, and w saves the changes −

The update bytes verify the deletion of the second line.
How to Search Specific Text in Red?
To search for a specific word or phrase in the file, we can specify a regex −
red exampleTutorials.txt /tutorialspoint/ q
Here, /tutorialspoint/ searches for the word "tutorialspoint" in the exampleTutorials.txt file −

How to Append New Text to File?
Use the $a command in red to insert new text at the end of the file −
red exampleTutorials.txt $a Hi geeks! Welcome to tutorialspoint.com . w q
Here, we use $a to append text after the last line and w to save the updated content −

Security Restrictions in Red: Disabled Shell Commands
In red, commands like ! (to execute shell commands) are disabled for security reasons. If you try to use these commands in red, you will encounter an error −
! !ls
These commands will result in an error indicating shell commands are restricted in red.
Best Practices to Use red in Linux
To effectively use the red (restricted ed) command in Linux, consider the following best practices −
- Red works in a restricted mode. This limits the ability to run external shell commands, making text editing safer in controlled environments.
- Use red for simple text edits, one line at a time. It is ideal for low-resource systems or basic text manipulation tasks.
- Although red can handle different files, it works best with small or medium-sized text files. It is not suited for large datasets.
- Learn key commands like a (append), i (insert), d (delete), and w (write). These commands let you edit text easily without extra steps.
- Always make a backup of important files before editing. Red does not have an undo feature.
- Use red interactively for precise edits. Its restricted mode ensures safe and controlled changes without running external commands.
This sums up the use of the red command in Linux.
Conclusion
The red command in Linux offers a simple, line-based text editing experience that is ideal for environments where resources are limited or where security is a concern. Operating in restricted mode, red ensures a safe editing environment by preventing external commands from running.
While it is not intended for complex data manipulation tasks, it is highly effective for automating repetitive text-editing tasks in shell scripts. In this article, we explained how you can effectively use red for straightforward text-editing needs in Linux by understanding its basic syntax, installation process, and best practices.