- [Instructor] There might be times when we don't want
to add commands to our command history, in this case
we can set a shell variable called HISTCONTROL,
type in export space, HISTCONTROL, all uppercase letters
equals, ignore space and hit enter.
Let's test this by placing a space before the history
command and see if it shows up in the history.
Type in space, history and hit enter.
We can see that the history command is not recorded
in the history file.
Any time you don't want a command polluting your history
file, just prepend it with a space, this is a simple way
of keeping your history clean.
Another value for this option is ignore dups.
Type in export space, HISTCONTROL, equals ignore dups
and hit enter, ignore dups won't record duplicate entries.
Let's type in ls three times and check the history.
Ls enter, ls enter, ls enter, now let's type in
history and see the result, we only see one of the ls lines.
This doesn't however get rid of previous duplicates.
To get rid of all duplicates, including those in the past,
type in export space, HISTCONTROL, equals erase dups
and hit enter, now let's check our history again.
We're typing in history, you might notice that we
typed in history a couple of times but we only see one.
You can add more than one value to HISTCONTROL by separating
them with a colon.
If you wanted to erase duplicates and lines starting
with a space, type in export space, HISTCONTROL
equals double quote, erase dups colon, ignore space
double quote, and hit enter.
This will turn on both options.
There are some lines that you might never want to have
in the history, such as the history command itself.
To keep certain lines from being recorded, we can place
them in the hist ignore variable.
Type in export, space HISTIGNORE equals double quote,
history asterisk, this is going to ignore any lines
that start with the word history and are followed by
any number of characters, hit enter.
We can test this by typing in history again, and hit enter.
Let's test this by typing in history again, and hit enter.
We can see that there's no lines being added for the
command history, we can also add several patterns to
the HISTIGNORE variable by separating them with a colon.
Type in export space, HISTIGNORE, equals, double quote,
history, asterisk, colon, ls, asterisk,
double quote and hit enter.
Now it should ignore any lines starting with the word
history or the word ls.
If we want a better log of our commands and history,
including time stamps, we can change the variable,
HISTTIMEFORMAT, type in export space, HISTTIMEFORMAT,
equals, double quote, percent h space, percent d space,
percent uppercase H, colon, percent uppercase M,
colon, percent uppercase S, greater than space,
double quote, what this does is add the date and time
to your history items.
Type in history and hit enter.
To get the list of possible variables, check demand
page four strf time, by typing in man, space strftime
and hitting enter.
You can see the variables that are available to customize
your date and time format.
Press q to quit.
By default our history file's 1,000 lines.
If you'd like to increase this, we can change the value
of the HISTSIZE variable, type in export, space,
HISTSIZE equals 10,000 and hit enter.
If you wanted it unlimited, we can set it to a negative
value, such as negative 1.
If we want to turn off recording of our history,
we'd set it to zero, when we exit our shell,
our history is saved and the file named .bash_history,
in our home directory.
We can choose how many lines are saved in this file
by changing the HISTFILESIZE variable, type in
export space, HISTFILESIZE equals 10,000.
Set this to zero if you want to turn off saving
of your command history on the disk.
All of these changes we've made so far are just for
our current login session, to make them persistent so
they're set when we log in, we need to add them to our
bash profile using a text editor, I'll use VI for this.
Type in vi space tilda, slash dot bash underscore profile
and hit enter.
We'll want to go down to the bottom of the file,
go into insert mode by pressing the i, or the insert key
and hit enter, now let's add a few of our variables.
Type in HISTCONTROL equals double quote, erase, dups,
colon, ignore space, double quote.
We can also add a HISTIGNORE in here by typing HISTIGNORE
equals double quote, history, asterisk, double quote.
You can add the other variables as well if you'd like.
Now let's save this file by pressing escape,
colon, wq and hit enter.
We can change other attributes of the shell
by entering them in the bash profile as well.