Linux Bash History – POFTUT

Linux Bash History


[rps-include post=6835]

Bash shell runs in terminals like gnome-terminal, konsole, getty, etc. To make things make easy bash provides some shortcuts and pragmatic operations. Here we will look details about them.

History

Busy system administrators writes a lot of bash commands. They have no time to write notes about the commands. But bash have a history to assist. Bash history holds commands written before. This is very helpful when you write long and rarely used command and needed right now.

Listing History

$ history 
    1  npm run
    2  cd ..
    3  ls
    4  npm run
    5  cd react-15.3.0/

I have cut the history is long as by default 1000 line. As you see bash lists all command we have issued.

Rerunning command

There is easy way to rerun previously issued command. As we see that history numbers commands. We will use these numbers to specify command like below.

$ !3
ls
Desktop  Documents  Downloads  workspace

We use !3 to rerun number 3 history command. As we see that rerunning command echoes issued command which is ls

Searching History

History provides a lot of commands. And finding a specific command in list may become hard. There is easy way to filter commands.

$ history | grep ls
    3  ls
    6  ls
   57  ls

We get help from grep command. It filters commands that provides ls and list them.

Clearing History

Some times we need to clear things we have done. For example if we provided a command with clear text password we may want to clear these commands.

$ history -c
$ history 
    1  history

Getting History Size

History is very helpful but if we are hardworking system administrator the size of the is may become small for us. By default history size is 1000 which means the last 1000 commands will be hold.

$ echo $HISTSIZE
1000

History size is hold as bash environment variable. By changing HISTSIZE environment variable the size may increased.

LEARN MORE  Linux Print History Command Without Line Numbers

Setting History Size

History is very helpful but if we are hardworking system administrator the size of the is may become small for us. By default history size is 1000 which means the last 1000 commands will be hold.

$ HISTSIZE=2000
$ echo $HISTSIZE
2000

History size is hold as a bash environment variable. By changing HISTSIZE  environment variable the size may increase.

[rps-include post=6835]

Leave a Comment