Skip to content

How to access command line history on Linux?

Bash is the most common and widely used shell in Linux distributions. It provides multiple features and tools to the user for their tasks. One of the useful commands that bash shell provides is the history command. In this article, we will be covering how you can access the command line history on Linux.

Also read: How to change file permissions recursively using Chmod in Linux?


How to access command line history?

There are various ways using which you can access the command line history.


Arrow keys

You can access the command line history using the arrow keys. Using the down arrow key takes you to the recent command you issued, and using the up arrow key takes you to the older commands you issued.


Using file .bash_history

The shell history of the bash keeps track of all the commands issued into the terminal in a file named .bash_history. You can print the content of this file to view the command line history.

cat ~/.bash_history
Linux command line history

History command

Using the history command, you can view some of the commands that you issued during your session. You can also replay these commands as and when needed.

Linux command line history

You can change the number of commands the file can store using the HISTSIZE environment variable.

HISTSIZE=10
Linux command line history

Also read: How to exclude in Grep?


Command line editing

When you get the history of last some commands that you ran, you can see an index number written which each command. If you want to run any specific command from the history, all you need to do is run the “!<index number>” command in the terminal.

!<index number>
Linux command line history

Shortcut Keys

You can also use shortcut keys to traverse the list of commands that you’ve already run.

  • CTRL + P = scroll up through history
  • CTRL + N = scroll down through history
  • CTRL + R = Search backward in the history by typing the command until you see the one you want to use.
  • CTRL + S = Search forward in the history by typing the command until you see the one you want to use.
  • ALT + F = Move across the line, word by word in forward direction.
  • ALT + B = Move across the line, word by word in backward direction.
  • CTRL + A = It will take you to the beginning of a command line.
  • CTRL + E = It will take you to the end of a command line.
  • CTRL + K = Deleted the complete line.

Also read: Bashrc vs Bash_profile

Hello There!

If you like what you read, please support our publication by sharing it with your friends, family and colleagues. We're an ad-supported publication. So, if you're running an Adblocker, we humbly request you to whitelist us.

Share on facebook
Share on whatsapp
Share on twitter
Share on reddit
Share on linkedin
Share on pocket
Share on pinterest
Share on telegram
Share on stumbleupon
Share on digg
Share on tumblr
Share on email
Share on skype
Share on xing
Share on vk
Share on odnoklassniki
Share on mix






No more posts to show


>