An ad-free and cookie-free website.
Learn to review and access command history at the Linux command line.
Videos can also be accessed from the Linux Essentials Playlist on YouTube.
Linux history Command Summary with Examples (3:37)
Our fifty-eighth word, or command to memorize is
history from our category
history allows you review command
||Clear the history list|
||Print the command at the line NUMBER|
Recall from video 28, we used the
tail command to look at my
video 56 on
bash command history?
Here we'll explore functionality in the
Before we start, it helps to think of commands as mini programs and
most follow this structure:
command -option(s) argument(s).
history command has
8 options and the argument can be a line number, file
name or search string.
Unlike most commands, help is not available with double-dash
history is a shell built-in (builtin),
so use the manuals page for both
history has a few advanced search
features, but for us
-c clears the history, and the
exclamation plus a number
pulls that line number.
So why is
history an important command?
Well, sometimes you remember you once had a stroke of genius and need
to hit the rewind button.
And now you know how to do that.
Okay, the best way to embed this in your memory is by typing in your own terminal window.
Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.
Here we go. Let's start with
Mine shows the last thousand. You can set how much history you'd like to save.
(Why is the terminal screen black on this video? Look at the date of recording ;)
Next, let's use a
tail command with
5 to see the last 5 lines in the
where this history is kept.
Notice these two don't match. Well the
history command shows more recent
entries, in this session and appends them to the history file on
logout. So if you need to see the most recent, use the
And last, let's pick a few random numbers and see my history. This could be scary. (I wouldn't suggest trying this at home, it is called history expansion and it executes previous commands. This can be helpful if you have a long command you don't want to take the time to type. It can be dangerous to do randomly like this, depending on what you've been doing ;)
I need to get a life.
Okay now you know how to use
And you know the syntax for commands, options and arguments.
One last tip about the
command. So searching in
its own syntax. You may find it easier in a text editor you know.
Okay, thanks for visiting today. I hope this was a helpful
introduction to the
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
If you like free opportunities to learn, subscribe, follow and tell a friend so the content keeps coming.
vimcommand, hit Back.
killcommand, click Next.
A newly-updated free resource. Connect and refer a friend today.