CLH-010

I/O REDIRECTION

< Script House
operator@shadow:~
[SYSTEM] I/O redirection module loaded
[MISSION] Control data streams and create operational reports
> Mission: Master >, >>, |, and tee
Type help for available commands.
operator@shadow:~$

CURRENT OBJECTIVE

1
2
3
4
5

CAPTURE: Redirect Output to File

List the intel directory contents and save to reports/filelist.txt using output redirection.

$ ls intel > reports/filelist.txt

STREAM CONTROL

The Mission

Data streams are your communication channels. Control where data flows - to files, to other commands, or to multiple destinations at once.

Master I/O redirection to build powerful command pipelines.

> Output Redirect (Overwrite)

$ ls > filelist.txt
Writes output to file (overwrites existing)

>> Append Output

$ echo "new line" >> log.txt
Adds output to end of file

| Pipe

$ cat file.txt | grep "error"
Send output of one command to input of another
$ ls | wc -l
Count number of files

tee - Split Output

$ ls | tee filelist.txt
Write to file AND display on screen
$ cmd | tee -a log.txt
Append mode with -a flag

2> Error Redirect

$ cmd 2> errors.txt
Redirect only error messages
$ cmd > out.txt 2>&1
Redirect both stdout and stderr
PIPELINE POWER:

Chain multiple pipes: cat log | grep ERROR | sort | uniq -c

CAUTION:

> overwrites files! Use >> to append safely.