How to Redirect Text Input/Output in Linux (cat, tee)

preview_player
Показать описание
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!
👉 Instagram:

#Cyberspatial #LinuxTutorial #Bash
Рекомендации по теме
Комментарии
Автор

very interesting playlist, loved it despite already knowing linux basics

fakihakhan
Автор

You made it, you finally got 11k subs I was the guy who posted a comment on UR video when u was like 500 or 1k subs I really don't know but yeah I posted a comment on the learn VirtualBox video. You really work hard on your videos you deserve even more subs keep going like this!!!

xEvD
Автор

kudos for the efforts you put in making these videos

shobhitsharan
Автор

Loving the videos! Really interested in all this

TadTheTame
Автор

Hey what's the music you use in the background. Sounds relaxing. Great video btw!

uniquechannelnames
Автор

hey there loved this video series a lot !!! I have a request to make... an informative video for digital forensics and roadmaps for it would be awesome as there is not a single channel giving clear descriptions for the same..Cheers !!!

krutikpednekar
Автор

Hey bro one more great content bro
Which video editor ur using is that open source

imuser
Автор

To be honest, I love it! Such a wonderful video! Thanks alot, I'm really grateful 🎉❤❤❤

AmusaVictorAyo
Автор

Hey Ricky great video literally understand everything.. Please make more videos like this. Doing good job thanks bro

amolkale
Автор

Nice presentation! At 1:57 though, I think the statement on standard input and cat is not quite accurate.
Although, `command somefile' and `command < somefile' will most of the time produce the same result,
it is not exactly the same, at least as far as I understand it. In the former case, the file `somefile' acts as
an argument to the command, whereas in the latter one it operates on the standard input. In general, the
ommission of `<' is not simply a shorter form of writing the command as is the case in dropping the `0'
in `0<'. For example, consider the `tr' command; it can only act on standard input, but cannot take a file as
an argument. Or take `wc' as another example, which as `cat' can take a file as argument and also can
operate on standard input. However, the output is not identical. For instance, let's assume you want to
determine the number of lines in a file named `somefile' (let us further assume that `somefile' consists
of 23 lines). Passing `somefile' as an argument to `wc' yields:
$ wc --lines somefile
23 somefile
On the other hand, operating on standard input results in:
$ wc --lines < somefile
23
In this case, the file name is not appended to the right side of the line count, which may be advatageous
in some command substitution use cases.

hpp
Автор

Loved it so much as I learned a lot
Many thanks

mohammedalbatati
Автор

Thanks for this video .
It will be great if you make tutorials in bash !

maheshrajpandit
Автор

Really nice and simple for a beginner to understand. I had a suggestion, you can use dos2unix which comes in busybox to convert Windows text files to Linux. Nice video Cyberspatial

cygmoid
Автор

Can you please tell me how to redirect builded c program output to a text file? (From Bangladesh)

Banga
Автор

I installed kali Linux on windows powershell and downloaded the wsl 2 and all done but it's still shows system has not been boot with systemmd (pid1)
Userd service openvas start but not worked. what's the problem

santhosh
Автор

Am I the only one to notice that the poem at 9:06 has a different indentation at line 5?

Jo_Wick
Автор

Is fhere a significant difference between an ethical hacker and a cyber forensics guy?

armincal
Автор

How about outputting both stdin and err by &>

Jure
Автор

From where to start to become a cyber security specialist

akshitchauhan
Автор

Please if possible stop appearing while showing terminal because is really distracting. Thank u for the videos

muhammadtijjani