2-Minute Linux Tip: Learn how to use the history command

Network World | Apr 11, 2018

In today's 2-minute Linux Tip, we look at the bash history command – a tool that shows you commands you've recently used and allows you to use them again without having to retype them.

Similar
Hi, this is Sandra Henry-Stocker, author of the "Unix as a Second Language" blog on NetworkWorld.
In today’s 2-minute Linux tip, we’re going to look at the bash history command – a tool that shows you commands you’ve recently used and allows you to use them again without having to retype them. Here’s how the history command works:
Type “history” and you’ll see the commands you’ve run recently. How many commands you see will depend on the size of your history buffer. Generally, that will be the last 100 or 1,000 commands that you’ve typed.
$ history
59 history
60 who
61 cal
62 h
63 alias h=history
64 c
65 h
You can use the command “echo $HISTSIZE” to see how many commands your account is configured to remember.
$ echo $HISTSIZE
If you only want to look at the last few commands you’ve used, pipe the history output to a tail command like this:
$ history | tail 3
Note that the most recent commands are at the bottom of the history output.
You can reuse a command by pressing the up arrow key on your keyboard. When you reach the command you want to reuse, press enter.
You can also repeat a recent command by typing an exclamation mark following by the first letter or the number preceding the command in your history display.
$ !22
$ !e
You can also repeat a command, but make changes before you run it.
That’s your 2-minute Linux tip for today. If you liked this video, please hit the like and share buttons. For more Linux tips, be sure to follow us on Facebook, YouTube and NetworkWorld.com.
Popular