How to Redirect Text Input/Output in Linux (cat, tee)
YouTube Viewers YouTube Viewers
267K subscribers
14,767 views
0

 Published On Sep 12, 2020

Redirecting text and data in the Linux command-line is an essential part of system administration. In this video you'll learn how to use cat, tee, and the Bash redirection symbols. This will let you pass data between the standard out, standard in, and standard error file descriptors.

Scripting is an essential part of cybersecurity. Almost every command line tool has some kind of text output, including error messages. If you want to capture these messages to a log file or pipe them to other commands, redirection is the answer.

In Linux, every is a file, from links, sockets, to devices. What's printed on the terminal (standard out) is a special device file located at /dev/stdout. Error messages (standard error) are stored in /dev/stderr. Terminal input (standard error) are in /dev/stdin.

To better access these buffers, bash conveniently provides several shortcuts that references them.
- The greater than arrow writes to standard out.
- The greater than arrow with a 2 before it writes to standard error
- The less than arrow reads from standard in.

When you display the contents of a file using the cat command, Bash actually passes the file's contents as input into the tool. Cat will then write the contents to the standard out file, which displays on the screen.

When you pipe a command's output to the tee command, it will write it to both standard out and a file of your choice.

In essence, anything that can be read or written from the terminal screen can be passed to a file. And vice versa.

00:00 Introduction
00:33 Key Principles for Bash Redirection
00:49 Linux File Descriptors
01:35 Redirecting Standard Output to a File
01:50 Displaying a File with Cat
02:00 Redirecting Data to Standard Input
02:55 Appending Output to a File
03:08 Truncating/Zeroing a File
03:27 Tee Command (Write to Standard Out and a File)
04:20 How to Use /dev/null
05:10 Redirecting Standard Error to Standard Out
05:40 Cat: Display Special Characters
07:57 How to Redirect Multiple Lines with Here Documents

We’re open to ideas and suggestions for more commands.

Let us know in the comments below!
____________________________________________
FOLLOW and SUBSCRIBE!
👉 YouTube:    / cyberspatial  
👉 Twitter:   / cyberspatial_hq  
👉 Facebook:   / cyberspatial  
👉 Instagram:
  / cyberspatial  
👉 LinkedIn:   / cyberspatial  

#Cyberspatial #LinuxTutorial #Bash

show more

Share/Embed