Time
5 hours 21 minutes
Difficulty
Beginner
CEU/CPE
6

Video Transcription

00:00
Hello and welcome to command line basics. In this video, we're gonna go over linens. File commands four. I'm Christopher holier, and let's begin.
00:09
So we're letting objectives for this video. We're gonna learn, sort command learned the unique command and understand the said commend. And these were a little more advanced, and that could be kind of difficult to understand. But when you understand these commands and how we can use previous commands, we've learned you convict come very, very efficient and sort of see
00:28
how much more useful using the command line to use thes repetitive task he's than the gooey.
00:35
So pre assessment. What can said be used for? Is it a make changes to file
00:40
be move folders to a new directory at sea and in the stream of text or D searched through funds?
00:47
Answer is C at it a string of text so said actually stands for stream editor and it is used so we can take that standard input and either replace or find things that we're looking for and spit it out into a new set of standard input. Very useful. And we need to keep that in mind. When we were working through the shell
01:07
said does not make changes to a file or move folders to a new directory
01:11
in the canal searched through files.
01:14
So sort sort is used to kind of organize some texts that we get for an output.
01:19
And it can either use a, uh, input from a file or a standard input from our standard output. Excuse me from a different command.
01:30
So this is a very useful way to organize text, and it can be you used to combine with other commands very easily.
01:37
So let's give a quick demonstration. I'm gonna put my Lennox box
01:41
and inside of this folder I have this file called Latin Words that t x t. So if I do cat on Latin words,
01:49
you'll see and we have all sorts of different words and they're not very ordered.
01:55
So if I want to see exactly how many of each word is inside of this file, I'm gonna use Thea Sort command. That way I can get them all in order first.
02:06
So I have this cat and I'm gonna do a pipe and sort,
02:10
and a sword by itself is just gonna take him and sort him that way. We have a mall in order, so check it out. It is in alphabetical order right now. So Thea, very clean and orderly, part inside of me is happy When I see this that way, it is all sorted and in order.
02:29
Now let's say we want to learn exactly how many of each word is inside of that file. So in order to do that, we're gonna use the unique command because what it will do is it will remove any text or string on each line. That is the same as the line before.
02:46
So it is usually used with sort because they were very powerful together. And it's very important to keep in mind that has to be in order. So you have to use the unique command after sort. Otherwise it won't work properly.
03:00
And with the unique we can also use the dash C switch and that'll give us a count of how many of these words are in the file.
03:10
So if you go back to our show
03:14
and we bring up our previous command, gonna add another pipe
03:19
and we're gonna do unique dash C
03:23
Now if you check it out we have all sorts accounts for the different words that were inside of this file.
03:30
So as you can see, we've got 13. But
03:34
to Vivi, Emma's four of all, but that you know, these are Latin words. Excuse my Latin. I'm not very good at it,
03:40
but that this is a very useful way to be able to see exactly how many of each string is inside of this file.
03:47
Now, in order to be able to, uh, organized again, can do another pipe and sort again
03:54
and check it out. Now we're having sorted by the number as well.
04:00
So this is a very useful way to keep in mind. That way we can see exactly how much of your specific words air inside of a specific file. So it's very useful work through
04:12
now. Said this is the stream editor that we learned about in the pre assessment. So is used to make changes to a stream of text, and the way it works is it will search and replace a text. And as you can see from the er
04:28
slide here we have a very special looking command. So this s and then slash
04:35
old slash news last year. The S stands for is search. So it's gonna search through that string
04:43
and it's gonna search for old.
04:46
And every time it finds the word old is gonna replace it with new
04:50
and the G stands for globally. So it's going to say for every time you find this, uh, old inside of this stream, replace it with new globally. If we did not have this g,
05:03
you would only replace the 1st 1
05:06
So if you want to replace the 1st 1 or you want to place everything, it's important to have that in mind.
05:12
Let's give it a quick demonstration. So I'm gonna echo
05:15
Old is new and new is old
05:20
and we see this output on our screen from the echo Commend.
05:25
I'm gonna put this into set
05:27
and let's say we want to change old to new,
05:30
so I'm going to do said
05:32
s slash old new
05:35
slash.
05:38
And as you could see, I didn't have the G in the end. So it only replaced the first old
05:43
and if, as new is new and new is old instead of old is new and new is old.
05:48
Now let's say we want to replace all of the old inside of this command. They're gonna bring up our previous command. But the G for the globally search
06:00
hit, enter and, as you can see, replaced old in both sponsor this string,
06:06
so there's plenty more you can do, it said.
06:09
But it is very, very useful to keep in mind.
06:13
Ah, heart. So post assessment. Which unique switch counts the number of hits for an entrance?
06:18
Is it a dash C
06:20
B dash, dash number C dash A or D dash dash? Unique
06:28
answer is a dash C.
06:30
This is very important because usually when you use the unique command, you're gonna want to be able to see exactly how much of each string is inside of a file or inside of an output. So using the dash C will give you a count very quickly. Super useful saves a lot of time.
06:48
The dash, dash number, dash A and dash dash. Unique or not, ballad switches for unique.
06:57
All right, so in this video we learned the sole command when the unique command and understood the set command. Like I said at the beginning of this video, these air a little more advanced kind of commands, but they're very, very useful. If you can get them down, feel comfortable with them. And you're gonna save a lot of time being able to use these commands at the command line.
07:15
And I hope to see you in the next video.

Up Next

Command Line Basics

In this course you will learn the fundamentals of Command Line, a fundamental tool for any user of Windows and Linux machines. Command line allows developers to manipulate files easily and quickly. Learning command line saves developers time and resources.

Instructed By

Instructor Profile Image
Christopher Haller
Senior Intelligence Operations Analyst at Centripetal
Instructor