5 hours 21 minutes
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.
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
how much more useful using the command line to use thes repetitive task he's than the gooey.
So pre assessment. What can said be used for? Is it a make changes to file
be move folders to a new directory at sea and in the stream of text or D searched through funds?
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
said does not make changes to a file or move folders to a new directory
in the canal searched through files.
So sort sort is used to kind of organize some texts that we get for an output.
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.
So this is a very useful way to organize text, and it can be you used to combine with other commands very easily.
So let's give a quick demonstration. I'm gonna put my Lennox box
and inside of this folder I have this file called Latin Words that t x t. So if I do cat on Latin words,
you'll see and we have all sorts of different words and they're not very ordered.
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.
So I have this cat and I'm gonna do a pipe and sort,
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.
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.
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.
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.
So if you go back to our show
and we bring up our previous command, gonna add another pipe
and we're gonna do unique dash C
Now if you check it out we have all sorts accounts for the different words that were inside of this file.
So as you can see, we've got 13. But
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,
but that this is a very useful way to be able to see exactly how many of each string is inside of this file.
Now, in order to be able to, uh, organized again, can do another pipe and sort again
and check it out. Now we're having sorted by the number as well.
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
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
slide here we have a very special looking command. So this s and then slash
old slash news last year. The S stands for is search. So it's gonna search through that string
and it's gonna search for old.
And every time it finds the word old is gonna replace it with new
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,
you would only replace the 1st 1
So if you want to replace the 1st 1 or you want to place everything, it's important to have that in mind.
Let's give it a quick demonstration. So I'm gonna echo
Old is new and new is old
and we see this output on our screen from the echo Commend.
I'm gonna put this into set
and let's say we want to change old to new,
so I'm going to do said
s slash old new
And as you could see, I didn't have the G in the end. So it only replaced the first old
and if, as new is new and new is old instead of old is new and new is old.
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
hit, enter and, as you can see, replaced old in both sponsor this string,
so there's plenty more you can do, it said.
But it is very, very useful to keep in mind.
Ah, heart. So post assessment. Which unique switch counts the number of hits for an entrance?
Is it a dash C
B dash, dash number C dash A or D dash dash? Unique
answer is a dash C.
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.
The dash, dash number, dash A and dash dash. Unique or not, ballad switches for unique.
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.
And I hope to see you in the next video.