CBSE 2026 results are out, Mukul scored a perfect 100/100 in Computer ScienceSee all toppers →

KwickAcademy Course Topics · 6 min · free

I/O redirection and pipes

6 min1 KwickClipsFull text belowFree
Next lesson →Kajal Ma'am (MCA), teaching since 2004Remembered in this browser

Learn Linux I/O redirection and pipes: standard streams, overwrite, append, input and error redirection, the pipe, and using them together. A single greater-than sign overwrites a file, a double one appends, and a pipe sends one command's output into the next.

Follows the syllabus of: GSEB Std 11 Computer Studies

On screen in this lesson

Three standard streams

StreamNumberDefault
Standard input0keyboard
Standard output1screen
Standard error2screen

What is redirection?

Sending output to a file, not the screen
Taking input from a file, not the keyboard
Done with symbols: >, >>, <, 2>

Warning: > overwrites

If the file exists, old content is erased
Only the new output remains
No undo, so check the file name first

Redirection symbols

SymbolMeaningExample
>output, overwritels > list.txt
>>output, appenddate >> log.txt
<input from filesort < a.txt
2>errors to filecat x 2> e.txt

What is a pipe?

Symbol: the vertical bar key
Output of one command becomes input of next
No temporary file is needed
Like water flowing through connected pipes

Pause and predict

$ echo Hi > a.txt
$ echo Bye > a.txt
$ cat a.txt
What prints?

Quick answers

You save Hi, then Bye, in a.txt with a single greater-than sign. What does cat a.txt print?

Only Bye, because a single greater-than sign overwrites.

How do you save error messages to a file?

Use 2 followed by the greater-than sign, then the file name.

KwickClips from this lesson

Short clips, one idea each. Good for revision the night before.

The full lesson, in text

Hello students, welcome to Kwickprep. Can you save the output of a command into a file, or count logged-in users in one line? In Linux, yes. Today we will learn input and output redirection and pipes, and one small symbol that can wipe out a whole file.

Every Linux command works with three streams, which are paths for data. Standard input is where a command reads data, and by default it is the keyboard. Standard output is where normal results go, and by default it is the screen. Standard error is where error messages go, and it is also the screen. Each stream has a number: zero, one and two.

Redirection means changing where a stream goes or comes from. We can send the output to a file instead of the screen. We can also take input from a file instead of the keyboard. We do this with small symbols, like greater than, double greater than, less than, and two greater than.

The greater than symbol sends standard output into a file. Date greater than today dot txt prints nothing on the screen. Instead, the date is saved in the file today dot txt. If the file does not exist, Linux creates it. Cat today dot txt then shows the saved date.

Here is the trap from the start of the lesson. If the file already exists, the single greater than symbol erases its old content. Only the new output remains in the file. There is no undo, so always check the file name before pressing Enter.

To add to a file without erasing it, use double greater than, which means append. The first command creates marks dot txt with Riya eighty two. The second command uses double greater than, so Aman seventy five is added at the end. Cat shows both lines. If we had used a single greater than, only Aman would remain.

The less than symbol makes a command read from a file instead of the keyboard. Suppose names dot txt holds Riya, Aman and Neha. Sort less than names dot txt reads the file and prints the names in alphabetical order. Wc hyphen l counts lines, so wc hyphen l less than names dot txt prints three.

Error messages use stream number two, so we redirect them with two greater than. The file abc dot txt does not exist, so cat gives an error. Because of two greater than, the error goes into err dot txt, and the screen stays clean. Cat err dot txt shows the saved message, No such file or directory.

Let us put all the redirection symbols together. Greater than sends output to a file and overwrites it. Double greater than sends output and appends it at the end. Less than takes input from a file. Two greater than sends error messages to a file.

Now the second big idea, the pipe. The pipe symbol is the vertical bar key, found above the Enter key on most keyboards. It sends the output of one command straight into the input of the next command. So we do not need to save a temporary file in between. Think of water flowing through connected pipes, from one tank to the next.

Let us see pipes at work. Who lists the logged-in users, one per line. Pipe it into wc hyphen l, and we get the number of users, here three. Ls lists the files, and head hyphen two keeps only the first two lines. So only two file names are printed.

Several pipes joined together make a pipeline. Cat reads marks dot txt and sends its lines forward. Sort arranges the lines in order, so repeated lines come next to each other. Uniq removes the repeated lines that are next to each other. The final result appears on the screen.

We can use a pipe and redirection together. Ls lists the files, and the pipe sends them to wc hyphen l to count them. Then greater than saves the count into count dot txt. Our folder now has five files, including count dot txt itself, which the shell creates first. So the file holds five.

Pause and predict. The first command saves Hi in a dot txt. The second command uses a single greater than to save Bye in the same file. Then we run cat a dot txt. What prints? Only Bye, because a single greater than overwrites the old content.

Let us revise what we learned today. There are three streams: input is zero, output is one, and error is two. Greater than overwrites a file, and double greater than appends to it. Less than reads input from a file. Two greater than saves error messages in a file. And the pipe sends the output of one command into the next command.

Courses that teach this

CourseUnit
GSEB Std 11 Computer StudiesBasic Ubuntu Linux Commands

Voice-over in this lesson is AI-generated. The script is written and checked by Kajal Ma'am. Boards can revise a syllabus mid-year, so confirm anything you plan around against the official board circular. Keep your passwords, OTPs and ID numbers to yourself — we never ask for them. To reach Kajal Ma'am, use the WhatsApp button; sharing your number there is how we call you back.

Free to watch, no sign-up. Live classes with Kajal Ma'am are the paid course; these lessons stay free either way.

Want a plan that actually fits your board dates?

Ask Kajal Ma'am directly, 20+ years teaching computer science. Free demo class first, no payment.

Talk to Kajal Ma'am on WhatsApp

Or see the Class 12 Computer Science course →

Studying outside India?

We coach CBSE, IGCSE & international students across the globe, one-to-one, in your local time zone.

Visit International →