[No audio]
Terminal commands.
There are some terminal commands that are used
to help you manage your terminal more efficiently.
Now number one command that I have
listed here is a clear command. So clear command,
when you log into your
terminal, you run certain commands.
You could just simply type clear to clear your screen.
The next command we have is the exit command.
exit command allows you to exit
out of session, a shell session.
If you have gone into different shell terminals, you can
exit out to come back to your original session.
Or you could exit out of the terminal that you have
opened up, or you could exit out of a user session.
So if you have become a different user by switching
it to, su to a different user, you can simply
type exit to come back to your own session.
Then the last one is the script.
script is very helpful command.
It's a command that stores terminal activities in a
log file that can be named by a user.
You could run it and you
can name anything that you want.
When a name is not provided by the user,
then the default file name is used, and that
is typescript, the name of the file.
So let's try all these three commands
one by one in our Linux machine.
[No audio]
Okay, so when you run ls -ltr, whoami,
and bunch of other stuff,
ls -ltr on the tmp directory, all
that stuff that comes up.
So you could hit enter, enter , enter, enter, enter to clear up
your screen, or simply just type clear.
This will clear your screen.
And many times when people run scripts, the first
thing they put it in the script is clear.
So the output will clear up everything on your
screen and then start from a new line.
Then you have the next command is exit.
exit is simply, when you type exit,
it will exit out of your script,
if there is any script it was running before.
So I'm just going to clear that.
So I'm going to type exit again, one more time,
and there you go.
It has exited out.
I had a few scripts commands that were running
previously, that's why I couldn't get it out earlier.
But anyway, the last one got me out.
So I'll open up a terminal again and this time
I'm typing exit again to exit out of the terminal,
because this will explain better how the exit works.
If you become a different user, let's say su
spider, you put in the password, now you see,
you are logged in as spider.
What if you want to go back into your original
session, which is iafzal, you just type simply exit,
and you could become back again to yourself.
So this is what the exit command is mostly used for.
And the last command, which I personally like, because
it records everything that you do on your session.
So what it does is when you run script,
[Author typing]
you have to specify the name I will put
in transaction or, you know what, logfile-activity.
.log.
When I hit enter, it says
Script started, file is logfile-activity.log.
And that log file is created within
the same directory that you are in.
So when you run ls -ltr, you'll see at the
end, it has created a file called logfile-activity.
I just ran this command ls -ltr.
This output of this command will be recorded in that.
So if I go into another directory, let's say etc slash,
cd /etc, run ls -ltr, clear my screen, type history command,
or type pwd, and whatever that I am doing in
my session, everything is recorded in my log file.
Right now, you'll see, if I do cd, and if you go back
to my home directory, type pwd, and I do ls -ltr,
you see the logfile-activity, the sizes keep
increasing because it does keep recording all the commands, and all
the output that's coming from those commands.
So now if I want it to be done
with this script command, I'll just simply type exit.
Once I do exit, it will tell me Script done,
file is logfile-activity.log.
It means now it is not recording anything.
It has finished capturing the output of your session.
Now you could view, let's clear the screen, and you
could view the log activity, which is right here,
when I do more on the file,
I hit enter, and you will see,
the first command when I ran after running
the script command was the ls -ltr.
It recorded the command, recorded
the output of the command,
keep going,
and then I went to etc directory
and I did ls -ltr, it recorded everythingI did.
See all the commands, everything that I did
while I was running the commands after the script.
The reason that I use the script command most of
the time is because when I am troubleshooting an issue
or if I am creating some tools or creating some
scripts, this would record everything for me.
So in case a month from now or a year from now,
and I wanted to perform the same tasks, I don't have to
look up the commands to execute that on the terminal.
I could just simply go into my logfile-activity,
and I will view that and remember, oh
yeah, these are the commands I ran, awesome.
It's like a log book, a recording way,
it records all your commands in a log file.
[No audio]