Instructor: Shell history.
What a shell history is,
every command that you run in your Linux operating system
or in your terminal,
it creates a history of these commands.
This history command, I'm telling you, is so useful
that even when you are troubleshooting,
you are trying to find out what are the commands people ran
that actually brought your system down
or crashed your system,
or what is the command that was run that deleted a file?
All those commands that you run in Linux, just be careful,
those commands are recorded,
and those commands are recorded
and can be retrieved by simply running a history command.
So it's just the history command,
everything is lowercase, when you run it,
you'll get all the listing of your commands
that's been run by a specific user.
Let's try to run it.
I am already in here.
Who am I?
Myself, just confirm which directory I'm in
and which host I'm in.
Awesome, we have confirmed
that we are logged into the right system.
Now, I wanted to clear the screen and run history command.
Whoa, such a long list of history commands.
What it's telling me right here,
that I have, so far since I have logged into the system,
I have ran the history command 666 times.
These are the different commands I have ran
since I logged in or since as many times I logged in
since the system is built.
How do you view other commands?
Of course, if you are running Putty,
you could just scroll up,
but what if you wanted to see
all of them one page at a time?
Please tell me you know that.
History, pipe it, more it.
Yes, now it's gonna start listing all the commands
one by one, one by one.
The first command, when I logged into the system,
the very first time when I built a system was PWD.
Next command, I did exit, if config,
those are different commands, as if you could see,
you could check every single command that we did.
You could also run this command in your shell
and find out what are the commands it listed.
It's not only gonna list the command
that you ran successfully,
it'll also list the command
that you ran incorrectly or wrong command,
or command a that did not work.
So that's how the history command works.
Now, a coolest feature of history command,
which you're gonna love,
that if you wanted to run any of this command again,
you could copy and paste,
which you could do that,
but there's a chances that it's not gonna get copied
or it's not gonna get paste.
But if you wanted to create,
if you wanted to run a command again,
let's say I wanted to pick a command,
I wanted to pick a command, I want it to run last,
last tell you which users are logged in,
and awk, awk, it's gonna print out only the first column
of the output last,
and then it's gonna sort it out
and it's gonna unique it out.
Of course, it's a long command.
There's two ways you could do it,
is one, you could copy paste or you could just do 406,
remember 406, that this command,
the number of this command was 406,
and when you run it, how do you run it?
You just simply type bang, 406,
which is 406, you run it,
it ran that command
and it gave you the output of that command.
Isn't that cool, guys?
It is very cool.
I use it all the time.
And I love this, because this way,
I don't remember a command
that I typed maybe five months ago.
If I go into a history, I'll look into it right away.
And if you wanted to do history command,
and you remember that you ran a command that had awk in it,
you were looking for something that has awk in it,
so what do you do?
You just grab for awk,
and it will list all the commands
that I ran that has awk inside of it.
If you want to do history and grab
and you want to check all the commands
that has changed, modern it.
You get all those commands.
So again, try it, try it as many times as you want,
and please always run man on history,
and you'll find many information
and a lot more options that you could use.