Thuta Learning
IntermediateDevOps & Toolsbeginner

Pipes (|) and Redirection (>, >>, <)

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Get comfortable with pipes (|) and redirection (>, >>, <) — no need to fear them
  • Practice running the commands yourself in the terminal
  • See how these commands come in handy on a real server or project

Let's think about it this way for a second

A pipe (|) sends one command's output directly into the next command's input — just like connecting a water pipe. ls -la | grep txt sends ls's output to grep, which then catches only the lines containing 'txt'. Redirection sends output to a file instead of the terminal — > overwrites the file (deletes the old content and writes fresh), while >> appends to the end of the file (adds on without deleting). < tells a command to read data from a file as its input.

Let's connect this to a real-world scenario

ls -la > filelist.txt saves ls's output into filelist.txt instead of showing it on screen. echo "log entry" >> app.log adds a new line without deleting the log file's old content — you should always use >> for log files, since using > by mistake can wipe out your entire log history. A command chain like ps aux | grep python | wc -l does three jobs in a single line: list the processes, catch the lines containing python, and count how many lines there are in total.

Let's try it together in the terminal

bash
ls -la | grep txt
ps aux | grep python
echo "first line" > log.txt
echo "second line" >> log.txt
cat log.txt        # ၂ ကြောင်းစလုံးမြင်ရမည်
You should see
The log.txt file will contain two lines: first line and second line.

5-Minute Try-It

Run ls -la | grep .txt in your practice folder and write down what the results show. Then try out the difference between > and >> yourself using echo.

A Quick Word of Caution

If you accidentally use > on an important file, the entire contents can vanish instantly — and there's no Recycle Bin to save you, just so you know.

Easy traps

  • Using > instead of >> and wiping out an entire old log file
  • Not noticing when the two commands on either side of a pipe (|) aren't compatible (e.g. ls | cd — this doesn't work because cd doesn't accept input)

Now Try It Yourself

Run ls -la | grep .txt in your practice folder and write down what the results show. Then try out the difference between > and >> yourself using echo.

You'll know it worked when: The log.txt file will contain two lines: first line and second line.

Pipes (|) and Redirection (>, >>, <) | Thuta Learning