Hello and welcome to Command Line
Basics. In this video, we're going
to go over Linux file commands for
I'm Christopher Haler and let's
begin.
So we're learning objectives for
this video, sort command
and the unique command and
understand the said command.
And these are a little more advanced
and can be kind of difficult to
understand.
But when you understand these
commands and how we can use previous
commands, we've learned you can
become very, very efficient and
sort of see how much more useful
using the command line to use
these repetitive tasks than the
GUI.
So precise.
What Can said be used for?
Is it a make changes to file
B folders to a new directory
and see a stream of text
or d search through files?
The answer is C edit a string of
text. So it actually stands
for Stream editor and
it is used so that 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're working through.
The Shell said does not make changes
to a file or move folders to a new
directory and it can now search
through files.
So sorting sort is used
to kind of organize some text
that we get for an output and
it can either use a
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
used to combine with other commands
very easily.
So let's give a quick demonstration.
I'm going to put my Linux box.
And inside of this folder I have
this file called Latin Word
Static's.
So if I do cat on
Latin words, you'll see
we have all sorts of different words
and they are not very
ordered.
So if I want to see exactly
how many of each word is
inside of this file, I'm going to
use the sort command.
That way I can get them all in order
first.
So I have this cat and
I'm going to do a pipe and sort
and assort by itself is just going
to take them and sort them that
way. We have them all in order.
So check it out.
It is in alphabetical order right
now. So the
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 going
to use the unique command, because
what it will do is remove any
text or string on each
line that is the same as
the one before it.
So it is usually used
with sort because they were very
powerful together and is
very important to keep in mind that
has to be in order.
So you have to use unique
command after sort of otherwise
it won't work properly.
And with the unique we can also
use the C switch
and that will give us a count of how
many of these words are
in the file.
So if we go back to our
show and we bring
up our previous command, I'm going
to add another pipe
and we are going to do a unique
dash. See,
now, if you check it out, we have
all sorts of counts for the
different words that we're inside
of this file.
So as you can see, we got 13
to 15 lists
for VOV.
But these are all Latin words.
Excuse my Latin.
I'm not very good at it.
But 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
organize again, we can do
another pipe and sort
again and check it
out. Now we have them 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 specific
words are inside of a specific
file.
So it's very useful to work through
now said this is the stream, Ed,
that we learned about in the pre
assessment.
So it is used to make changes to
a stream of text.
And the way it works is it will
search and replace the text.
And as you can see from
the
the 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 going to search through that
string and it's going to search
for old.
And every time it finds the word
old, it's going to replace it with
new and the G
stands for globally.
So it's going to say for every time
we find this
old inside of this
stream.
So with new globally, if
we did not have this job,
it would only replace the first one.
So if you want to replace the first
one or if you want to place
everything, it's important to have
that in mind.
Now, let's give a quick
demonstration.
So I'm going to echo
old is new
and new is old.
And we see this output on our screen
from the Kookmin.
Now, I'm going to pipe this in to
set and let's say if you want to
change old to new.
So we're going to do said,
as old
knew Slash,
and as you can see, I didn't have
the G in the end, so we'd only
replace the first old
and it has new is new
and new is old and sort of old
is new and new is old.
Now, let's say we want to replace
all of the old inside
of this command.
So I want to bring up our previous
command.
But the G for the global search
and enter.
And as you can see, it replaced
old in both
spots of this string.
So there's plenty more you can do
with said, but it is very,
very useful to keep in mind.
So post assessment, which
uniques, which counts the number of
hits for an entry.
Is it A dash C,
B dash no.
C dash A
or D dash dash unique.
The answer is a dash
C.
This is very important because
usually when you use the unique
command, you're going to 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 account very
quickly. Super useful.
Saves a lot of time.
The dash dash no dash a
and dash tacheny or not valid
switches for unique.
All right. So in this video we learn
to sort command when the unique
command and understood the set
command.
Like I said at the beginning of this
video, these are a little more
advanced kind of commands, but
they are very, very useful if
you can get them down, feel
comfortable with them.
And you were going to 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.