Command History Linux

The history command displays the last 500 commands you’ve entered (usually).

history

Like most other Linux commands, the output is sent to “standard out,” meaning it will display on the console unless you redirect it elsewhere (i.e. filter it).  For example, to filter it down to just the last 100 commands and then display them one screenfull at a time, use:

history | tail -100 | more

(Actually, the history command has a built-in tail feature.  So, you could just enter history 100 | more.)

One of the most common ways to filter the history is to search it using thegrep command.  For example,

history | grep java

This will come back with all of the commands that contain “java”, something like this:

172  java -jar jedit.jar
303  java -jar ~/java_libs/h2-1.0.74.jar
500  history | grep java

Notice that the command you just entered (history | grep java) is included (on line number 500, in this case).  This is because the command history is updated immediately before the history command is processed.

Leave a comment