WEBVTT

00:00.570 --> 00:02.160
Hello and welcome to Command Line.

00:02.640 --> 00:03.719
In this video, we're going to go

00:03.720 --> 00:05.100
over command redirection.

00:05.220 --> 00:06.220
I'm Christopher Haler.

00:06.240 --> 00:07.929
And let's begin this

00:08.250 --> 00:09.359
hour, learning objectives for this

00:09.360 --> 00:10.559
video. We're going to understand the

00:10.560 --> 00:12.177
purpose of redirection and why we

00:12.510 --> 00:14.039
should do it and how we can do it

00:14.040 --> 00:15.040
properly.

00:15.180 --> 00:16.503
Learn what this the greater

00:17.160 --> 00:19.079
than simple does, learn what

00:19.080 --> 00:20.549
the double greater than simple

00:21.000 --> 00:22.078
does and what the less

00:22.890 --> 00:23.890
than symbol does.

00:25.880 --> 00:28.069
So which operand appends

00:28.070 --> 00:29.210
to an existing file?

00:29.540 --> 00:30.540
Is it a single less

00:31.520 --> 00:32.520
than B A double less

00:33.530 --> 00:34.755
than C and double greater

00:35.600 --> 00:36.600
than or D a single

00:37.760 --> 00:38.760
greater than?

00:39.500 --> 00:41.299
The answer is C, the double greater

00:41.300 --> 00:43.129
than what this does is it will

00:43.130 --> 00:45.229
append to an existing file,

00:45.260 --> 00:46.969
whereas the single greater then will

00:46.970 --> 00:48.538
overwrite an existing file if it

00:48.950 --> 00:49.950
exists already.

00:50.540 --> 00:51.667
The single less than is

00:52.520 --> 00:54.559
used for input into

00:54.560 --> 00:56.689
a different command and the double

00:56.690 --> 00:58.939
less then is not a valid operand.

01:00.620 --> 01:02.329
So the redirection, the whole

01:02.330 --> 01:03.979
purpose of redirection from the

01:03.980 --> 01:05.839
command line is that we can use

01:05.840 --> 01:07.879
the output and either save

01:07.880 --> 01:09.889
it or we can direct input

01:09.900 --> 01:10.900
using the less than

01:11.840 --> 01:13.016
symbol so we can specify

01:14.180 --> 01:15.748
a different standard or standard

01:16.250 --> 01:17.720
error levels of redirection as

01:18.140 --> 01:19.999
well instead of just the normal

01:20.630 --> 01:21.630
output.

01:21.710 --> 01:23.779
So the useful way to be able to

01:23.780 --> 01:25.819
either gather information

01:25.820 --> 01:27.349
from the output of command that we

01:27.350 --> 01:28.918
can search through later or save

01:29.300 --> 01:30.830
it and keep it in a different place.

01:32.540 --> 01:34.059
So the single greater than what

01:34.430 --> 01:36.139
this does is it just simply takes

01:36.140 --> 01:37.700
the output from a command

01:38.040 --> 01:39.608
will stuff it into a file on the

01:39.650 --> 01:40.639
system.

01:40.640 --> 01:42.469
If the file does not exist,

01:42.470 --> 01:44.150
it will create it automatically.

01:44.690 --> 01:46.669
Now, the big thing to keep

01:46.670 --> 01:48.140
in mind single greater then is

01:48.590 --> 01:50.569
that it will overwrite a file if

01:50.570 --> 01:51.830
that file does exist.

01:52.050 --> 01:53.749
So that can be a problem

01:53.990 --> 01:55.849
if we want to keep the

01:55.850 --> 01:57.299
rest of the information that file

01:57.300 --> 01:58.300
already.

01:59.000 --> 02:00.829
So let's go ahead and give a

02:00.830 --> 02:01.880
quick demonstration.

02:03.160 --> 02:05.059
So I'm going to you there

02:05.140 --> 02:06.639
so we can see what's inside of this

02:07.390 --> 02:08.699
now, let's say Echo

02:09.759 --> 02:10.759
hello, and we're

02:11.620 --> 02:13.237
going to use the single ampersand

02:13.990 --> 02:15.039
and put it into

02:15.820 --> 02:16.960
hello to you

02:19.300 --> 02:20.639
or excuse me, not an ampersand, but

02:20.650 --> 02:22.840
single grader then and now.

02:22.870 --> 02:24.469
If we do another year, we could see

02:24.530 --> 02:26.050
we have hello to text

02:26.530 --> 02:27.699
and let's do type

02:29.200 --> 02:31.030
hello. And we could see hello

02:31.040 --> 02:31.839
there.

02:31.840 --> 02:33.909
And now if we do this again

02:33.910 --> 02:34.960
but instead of hello

02:36.820 --> 02:38.939
we have hi

02:39.790 --> 02:41.554
now with the single grader then it's

02:41.770 --> 02:43.300
going to overwrite that low

02:45.310 --> 02:46.840
and now we can do type again.

02:46.870 --> 02:48.399
We can see the Hillo is gone and all

02:48.400 --> 02:49.559
we have left is a high.

02:51.790 --> 02:52.966
Now in order to overcome

02:53.950 --> 02:55.479
this, we can use the double grid in

02:55.480 --> 02:56.950
it. And what this does appends

02:57.880 --> 02:59.497
to the end of the file if it does

02:59.500 --> 03:01.659
exist. So we don't want to overwrite

03:01.660 --> 03:02.969
everything in the file already.

03:02.980 --> 03:04.646
We use the double greater than and

03:04.840 --> 03:06.099
we'll automatically put it at the

03:06.100 --> 03:07.815
bottom of the file so we don't keep

03:08.020 --> 03:09.429
overwriting something that we want

03:09.430 --> 03:10.500
to keep in there already.

03:10.930 --> 03:12.099
And just like the single greater

03:12.100 --> 03:13.668
than it will create a file if it

03:13.780 --> 03:14.919
doesn't exist already.

03:15.460 --> 03:17.319
So let's give a quick demonstration

03:17.320 --> 03:18.986
of the double greater then and how

03:19.210 --> 03:20.925
we can use it to not overwrite what

03:21.250 --> 03:22.250
we're working on.

03:23.380 --> 03:24.580
All right. So let's say

03:27.430 --> 03:29.350
this didn't overwrite

03:31.210 --> 03:32.650
and the double grader then

03:33.370 --> 03:34.619
and load up to 60.

03:35.650 --> 03:37.449
Now, if we do type four.

03:37.450 --> 03:38.920
Hello, we can see we have this

03:39.370 --> 03:41.229
didn't overwrite on the

03:41.230 --> 03:42.230
end of the file

03:43.210 --> 03:44.679
that was already there and it did

03:44.680 --> 03:46.150
not overwrite the high that we

03:46.570 --> 03:47.919
previously just did.

03:48.460 --> 03:50.229
So this is very useful to keep in

03:50.230 --> 03:51.699
mind as we are

03:52.840 --> 03:54.506
redirecting output into files that

03:54.760 --> 03:56.229
we don't want to override, things

03:56.230 --> 03:57.340
that we want to keep in there.

03:59.320 --> 04:00.669
And we had the single graded.

04:00.670 --> 04:02.238
And what this does is it is used

04:02.500 --> 04:04.539
to provide input from a file

04:04.690 --> 04:05.979
into a command.

04:06.430 --> 04:08.559
And this file must exist

04:08.560 --> 04:10.128
because you are providing it has

04:10.270 --> 04:12.159
input and it will not

04:12.160 --> 04:13.870
change the input of the file.

04:14.200 --> 04:15.199
So it will leave the file.

04:15.200 --> 04:16.817
The same will simply provide that

04:16.870 --> 04:18.699
file as input into

04:18.700 --> 04:20.559
the command so we can

04:20.560 --> 04:21.736
use the sort command and

04:22.480 --> 04:24.489
the less than to say, hey, I'm

04:24.490 --> 04:26.360
pushing this file that text

04:26.710 --> 04:27.910
into the sort command,

04:28.540 --> 04:29.889
so let's give a demonstration and

04:29.890 --> 04:31.299
then I'm going to pull up my Linux

04:31.300 --> 04:32.259
machine.

04:32.260 --> 04:33.429
And just like always, I'm going to

04:33.430 --> 04:35.350
type LS to see what is inside

04:35.590 --> 04:36.910
of this directory.

04:37.570 --> 04:39.370
And now let's say I want to sort of

04:39.460 --> 04:41.350
Latin words that you

04:41.590 --> 04:42.590
sort

04:43.600 --> 04:45.700
and Latin words that txt

04:45.790 --> 04:47.920
with my less than simple

04:48.820 --> 04:50.499
and look that goes ahead takes it as

04:50.500 --> 04:52.089
input sorts Morlot from

04:52.450 --> 04:53.450
pretty useful.

04:55.480 --> 04:56.852
And now we can also redirect

04:57.160 --> 04:58.870
standard error from

04:59.080 --> 05:00.501
commands as well, and this is

05:00.910 --> 05:02.139
something you may have seen already

05:02.140 --> 05:03.609
where if there's a lot of error

05:03.610 --> 05:05.079
text, especially if you're doing a

05:05.080 --> 05:06.220
search and

05:06.970 --> 05:08.649
the command doesn't have full access

05:08.650 --> 05:10.169
to the system, it will give you

05:10.240 --> 05:11.829
error saying, hey, I can't reach

05:11.830 --> 05:13.479
this. And that can take up a lot of

05:13.480 --> 05:14.620
screen information.

05:15.250 --> 05:16.769
So we can do is we can redirect

05:17.620 --> 05:19.188
that standard error into a place

05:19.600 --> 05:21.459
that doesn't exist on Linux.

05:21.460 --> 05:22.959
That is Dev no

05:23.800 --> 05:25.749
dev signal and anything sent

05:25.750 --> 05:26.750
to this directory on

05:27.670 --> 05:29.238
Linux is immediately dropped and

05:29.320 --> 05:30.320
just ignored.

05:30.460 --> 05:31.881
And now in order to specify a

05:32.110 --> 05:33.433
standard error, we're going

05:34.000 --> 05:35.950
to use the two and then the

05:35.960 --> 05:37.720
single greater then.

05:37.960 --> 05:39.430
And this says, hey,

05:40.420 --> 05:42.159
for any errors that you get while on

05:42.160 --> 05:43.599
this command is running, I want you

05:43.600 --> 05:44.727
to take it and spit the

05:45.490 --> 05:47.319
standard error into this

05:47.320 --> 05:48.643
specific location and using

05:49.420 --> 05:51.490
the div. No, it says

05:51.790 --> 05:53.110
just get rid of it.

05:53.560 --> 05:55.509
So this is a useful way to be

05:55.510 --> 05:56.735
able to ignore all of the

05:57.380 --> 05:58.380
error information.

05:58.870 --> 06:00.339
So let's say I'm going to use my

06:00.340 --> 06:01.509
Linux machine and I'm going to

06:01.510 --> 06:03.220
search for my program

06:03.340 --> 06:04.879
on the root of the drive.

06:05.470 --> 06:06.670
Now, as you'll see,

06:07.790 --> 06:09.429
let's take the report

06:09.670 --> 06:11.890
I my program

06:12.490 --> 06:13.690
forward, slash the route.

06:14.530 --> 06:16.629
Now you'll see I will have

06:16.630 --> 06:17.630
a lot of

06:18.580 --> 06:19.660
this, my bad history,

06:21.940 --> 06:23.889
and now I should have a lot of

06:24.130 --> 06:25.769
permission denied, not go.

06:26.290 --> 06:27.939
So there's way too much going on

06:27.940 --> 06:28.940
right here.

06:29.410 --> 06:31.599
It's taken over my entire terminal.

06:31.610 --> 06:32.982
I, I'm going to use controls

06:33.490 --> 06:34.862
to stop this before it takes

06:35.410 --> 06:36.488
up more space and then

06:37.270 --> 06:39.389
do clear Nancy

06:39.400 --> 06:41.115
less so that I can get back to that

06:41.350 --> 06:42.526
kind of default position

06:43.420 --> 06:44.509
on the terminal.

06:45.070 --> 06:46.600
Now, if I do

06:47.830 --> 06:50.080
too, Divx

06:50.980 --> 06:51.980
know the saying,

06:53.230 --> 06:54.699
I want you to take these standard

06:54.700 --> 06:56.589
error and push it into Dev.

06:56.590 --> 06:57.590
No.

06:57.880 --> 06:59.850
So as we'll see, we won't get all

06:59.860 --> 07:01.420
those errors because it's

07:01.780 --> 07:03.639
all the error messages that

07:03.640 --> 07:05.110
it gets automatically sends to

07:05.470 --> 07:06.309
that.

07:06.310 --> 07:08.199
There's no directory

07:08.200 --> 07:09.449
where it is dropped by the limbic

07:09.520 --> 07:10.479
system.

07:10.480 --> 07:12.244
So that way we can focus on directly

07:12.610 --> 07:13.610
just what the output

07:14.800 --> 07:15.800
we have.

07:15.880 --> 07:17.920
So here we go. So we can already see

07:18.220 --> 07:19.220
some different

07:21.310 --> 07:22.779
information coming back.

07:22.780 --> 07:23.799
And we don't have all these error

07:23.800 --> 07:25.389
messages coming all over the screen

07:25.390 --> 07:26.619
and taking over our

07:27.580 --> 07:29.739
our our command

07:29.740 --> 07:30.850
window. Excuse me,

07:31.930 --> 07:33.547
I supposed to system, which often

07:33.850 --> 07:35.319
overrides an existing file.

07:35.710 --> 07:37.540
Is it a single less than

07:37.780 --> 07:39.240
the less than

07:39.850 --> 07:41.679
C a single greater

07:41.680 --> 07:43.749
then or D a double greater than

07:45.070 --> 07:46.638
the answer is C a single greater

07:46.750 --> 07:48.514
than this will overwrite an existing

07:48.790 --> 07:49.790
file and it will not

07:50.860 --> 07:52.379
append to the end of the double

07:52.690 --> 07:54.309
greater than will append to the end

07:54.310 --> 07:55.779
of a file if you want to keep it.

07:56.140 --> 07:57.579
But if you don't care too much about

07:57.580 --> 07:59.589
it, or you just need to create

07:59.590 --> 08:01.029
a new file, the single greatest

08:01.300 --> 08:02.800
work, exactly what you needed to do,

08:03.400 --> 08:04.576
and the single less than

08:05.230 --> 08:07.059
is used to provide input

08:07.150 --> 08:08.800
to a command not to

08:09.670 --> 08:11.080
get the output for it.

08:12.360 --> 08:13.479
All right. So in this video, we

08:13.480 --> 08:15.039
learned the purpose of redirection

08:15.040 --> 08:16.389
and how we can use at the command

08:16.390 --> 08:17.811
line, learned what the single

08:17.950 --> 08:19.518
greater then does learn with the

08:19.600 --> 08:21.159
double greater than does and how it

08:21.160 --> 08:22.659
happens to the file and keeps the

08:22.660 --> 08:24.549
file and understood with the single

08:24.550 --> 08:26.529
less than does and how we can use

08:26.530 --> 08:27.530
it to our advantage.

08:27.760 --> 08:29.410
And I hope to see in the next video.

