ls | sort | head

Terminal Power User: Pipes, Redirects & Processes

Combine simple commands into powerful pipelines

1

The Unix Philosophy

Unix was built on a powerful idea: make small tools that each do one thing well, then combine them. This simple concept changed computing forever.

ls
list files
|
sort
order lines
|
head
first lines
>
file
saved!

Do One Thing Well

Each command has a single purpose. sort sorts. grep searches. wc counts. Simple and focused.

Text In, Text Out

Commands read text input and produce text output. This common format lets any command talk to any other.

Combine for Power

The pipe (|) connects commands together. One command's output becomes the next command's input.

Fun Fact
The Unix philosophy was defined by Ken Thompson in 1978. Nearly 50 years later, the same principles power everything from web servers to smartphones!
2

Pipes: Connecting Commands

The pipe operator | takes the output of one command and feeds it directly into the next. Build powerful pipelines by chaining simple commands together.

command1 | command2 | command3
Output flows left to right through each command
Examples
ls | sort # List files, then sort them
cat data.txt | grep apple # Show file, filter for "apple"
ls | wc # List files, then count them

Pipeline Builder

Click commands to build a pipeline and see the data transform at each step!

ls cat grep sort head wc uniq

Start with a source   Add transforms

Click commands above to build a pipeline
Output Build a pipeline to see results...
Pro Tip
You can chain as many commands as you want! Power users regularly build pipelines with 4-5 commands to transform data in a single line.
3

Redirects: Saving Output

By default, command output appears on your screen. Redirects let you save that output to a file instead.

Overwrite
>
Replaces file contents completely
Append
>>
Adds to the end of the file

See the Difference

Click each step in order to run it and watch how the file changes.

1 echo "hello" > output.txt
2 echo "world" > output.txt
3 echo "hello" >> output.txt
4 echo "goodbye" >> output.txt
📄 output.txt
(file does not exist yet)

Create or Overwrite

> creates the file if it doesn't exist, or completely replaces its contents if it does.

Append Safely

>> adds to the end of the file without destroying existing content. Great for log files!

4

Sort & Uniq: Data Wrangling

Transform messy data into organized information. sort puts lines in order, and uniq removes duplicates.

sort [options]
Sort lines of text. Default is alphabetical, ascending.
Options
sort # Alphabetical A-Z
sort -r # Reverse Z-A
sort -n # Numeric (1, 2, 10 not 1, 10, 2)
uniq [options]
Remove adjacent duplicate lines. Always sort first!
The Classic Pattern
sort | uniq # Remove duplicates
sort | uniq -c # Count occurrences

Sort Visualizer

Watch data transform as you apply different operations.

fruits.txt
Classic Pattern
The combination sort | uniq -c | sort -rn is one of the most useful pipelines ever. It counts how often each line appears and shows the most common ones first!
5

Top: Watching Your System

The top command gives you a live, updating view of what your computer is doing. See which processes are running, how much CPU and memory they use, and spot problems instantly.

top - 14:23:07 up 12 days, 3:42, 1 user
Tasks: 142 total, 2 running, 140 sleeping
%Cpu(s): 12.5 us, 3.1 sy, 0.0 ni, 83.2 id
MiB Mem : 7962.4 total, 2451.8 free, 3102.6 used
PID USER %CPU %MEM TIME+ COMMAND
1842 user 45.2 8.3 2:31.4 node
2156 user 12.8 4.1 0:45.2 python3
892 root 3.4 2.8 15:22.1 apache2
3201 user 1.2 1.5 0:12.8 bash
1 root 0.0 0.4 00:03.2 systemd
q Quit top
P Sort by CPU
M Sort by Memory
k Kill a process

CPU Usage

%CPU shows how much processing power each program uses. High values mean the program is working hard.

Memory Usage

%MEM shows RAM consumption. If total memory gets too high, your system slows down.

Process ID (PID)

Every running program has a unique PID. Use it to identify and manage specific processes.

Try It Yourself!

Use the terminal below to practice pipes, redirects, and more:

ls | sort echo "hi" > test.txt cat test.txt top
Practice Terminal
Try It
Type top in the terminal to see live processes. Press q to quit. Then try building your own pipelines with ls | sort or echo "hello" > file.txt!

Power User Unlocked!

You've mastered pipes, redirects, sort, uniq, and process monitoring. These tools turn beginners into power users!

0
Pipelines Built
0
Concepts Learned
0
Time Exploring

Unix Philosophy

Small tools that do one thing well, combined together for complex tasks.

Pipe Operator (|)

Send the output of one command directly into the input of another.

Redirects (> and >>)

Save command output to files. Use > to overwrite, >> to append.

Sort & Uniq

Organize and deduplicate data. The classic sort | uniq -c counts occurrences.

Process Monitoring

Use top to watch running processes, CPU usage, and memory in real time.

Ready to Create?

Put your new knowledge into practice!

Suggest a Correction