Linux · Lesson

Linux · Lesson

Linux Symbols and Redirection Operators

Add the YouTube embed URL for this lesson in components/linux/linuxLessons.js.

Understanding Linux symbols

Linux shells provide special symbols and operators that help users combine commands, redirect output and manage command execution efficiently.

These symbols are extremely important in shell scripting, automation and day-to-day Linux administration tasks.

By mastering these operators, users can build powerful command combinations and process command outputs more effectively.

Core Linux symbol concepts

Command chaining

Symbols like semicolon allow multiple commands to execute sequentially.

Command piping

Pipes connect commands together by passing output from one command into another.

Output redirection

Redirection operators store command output into files for logging and processing.

Common Linux symbols

Execution symbols

  • Semicolon ';' executes multiple commands one after another.
  • Pipe '|' passes output from one command into another command.
  • These symbols help combine commands efficiently.

Redirection symbols

  • '>' overwrites content inside a file.
  • '>>' appends new content into a file.
  • tee and tee -a display output and save it into files simultaneously.

Important Linux symbols explained

Semicolon ';'

Runs multiple commands sequentially even if previous commands succeed or fail.

Pipe '|'

Sends command output as input to another command for advanced processing.

'>' and '>>'

Used for redirecting output into files by overwriting or appending data.

tee and tee -a

Display output on screen while simultaneously saving it into files.

Practical Linux examples

The following examples demonstrate commonly used Linux shell symbols and redirection operators.

1. Semicolon ';'

The semicolon allows multiple commands to run sequentially on a single line.

terminal — bash
linux-shell
[root@localhost usr]# cd
[root@localhost ~]# echo Hello; date; pwd; echo Done
Hello
Thu Dec 19 06:44:56 PM IST 2024
/root
Done
[root@localhost ~]#

2. Pipe '|'

The pipe symbol sends the output of one command as input to another command.

terminal — bash
linux-shell
[root@localhost ~]# ps aux | grep bash | wc -l
3
[root@localhost ~]#

3. Single greater than '>'

Redirect command output into a file and overwrite existing content.

terminal — bash
linux-shell
[root@localhost ~]# echo "Hello World!" > output.txt
[root@localhost ~]# cat output.txt
Hello World!
[root@localhost ~]#

4. Double greater than '>>'

Append command output to a file without removing existing content.

terminal — bash
linux-shell
[root@localhost ~]# echo "Hello Again" >> output.txt
[root@localhost ~]# cat output.txt
Hello World!
Hello Again
[root@localhost ~]#

5. tee command

Display output on the terminal and simultaneously write it into a file.

terminal — bash
linux-shell
[root@localhost ~]# echo "Hello with tee command" | tee output.txt
Hello with tee command
[root@localhost ~]# cat output.txt
Hello with tee command
[root@localhost ~]#

6. tee -a command

Append output into a file while also displaying it on the terminal.

terminal — bash
linux-shell
[root@localhost ~]# echo "Appending this message" | tee -a output.txt
Appending this message
[root@localhost ~]# cat output.txt
Hello with tee command
Hello with tee -a command
Appending this message
[root@localhost ~]#

Best practices while using symbols

Command handling

  • Verify commands before chaining multiple operations together.
  • Use pipes carefully to avoid unexpected command results.
  • Test commands individually before combining them.

File redirection safety

  • Use '>' carefully because it overwrites file contents.
  • Prefer '>>' when preserving existing data is important.
  • Use tee when output must be displayed and stored simultaneously.

Practice tasks for your Linux lab

  • Run multiple commands together using the ; symbol.
  • Use the pipe operator | to combine commands such as ps, grep and wc.
  • Create a file using output redirection with >.
  • Append additional text into the same file using >>.
  • Practice using tee and tee -a to save command output while viewing it on the terminal.

In upcoming lessons, you will continue learning advanced Linux shell operations, scripting and automation techniques.