How to See Command History in Linux

This tutorial is about How to See Command History in Linux. We will try our best so that you understand this guide. I hope you like this blog, How to See Command History in Linux. If your answer is yes, please do share after reading this.

So lets keep reading for intertesting info:

Check How to See Command History in Linux

The Linux shell keeps track of every command you issue and can search for you to issue the same command more than once. Your productivity can increase a lot after you learn how to use the Linux history command. In Linux, we can see the history of the commands we have executed in the terminal using the history command. In your .bashrc file, you can specify the maximum number of items that BASH should keep in its history. Most Linux users regularly use the command line. We use command lines for a variety of purposes, including data management, server control, and installing new programs. But how many of the commands we use regularly can we remember when we need to use one that we last used some time ago? We are fortunate to have a useful Linux utility at our disposal. The history command will be a useful tool for you, whether you’re a novice who needs help remembering previously used commands or an experienced user who doesn’t want to risk entering a complex command incorrectly.

How to view command history in Linux

$ which historywhat: no history in (/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/local/sbin)

Your computer can’t find the history command because it’s a built-in keyword of your shell. Because it’s written in the shell you’re using, there may be some variation in history behavior depending on whether you’re using Bash, tcsh, Zsh, dash, fish, ksh, etc. This article is based on Bash’s history implementation, so some features may not work in other shells. However, most of the basic functions are the same.

history 101

To see the history in action, open a terminal program on your Linux installation and type:

$ history

Here is the response I got:

1 clear2 ls -al3 sudo dnf update -y4 history

The history command shows a list of the commands entered since you started the session. The joy of the story is that now you can play any of them using a command like:

$ !3

The !3 command at the prompt tells the shell to rerun the command at line 3 of the history list. You could also access that command by entering:

$ !sudo dnf

This tells history to look for the last command that matches the pattern you provided (in this case, that pattern is dnf) and run it.

Search history

You can also use history to rerun the last command you entered by typing !!. By combining it with grep, you can search for commands that match a text pattern, or by using it with tail, you can find the last commands you ran. For example:

$ history | grep dnf 3 sudo dnf update -y 5 history | dnf grep

$ history | queue -n 34 history5 history | grep dnf6 history | queue -n 3

Another way to access this search functionality is to type Ctrl-R to invoke a recursive search of your command history. After typing this, the notice changes to:

(reverse-i-lookup)`’:

You can now start typing a command and matching commands will be displayed for you to execute by pressing Return or Enter.

Change an executed command

You can also use history to rerun a command with a different syntax. You can review history with history. For example, if I want to change my previous command history | grep dnf to history | grep ssh, I can run the following at the prompt:

$ ^dnf^ssh^

The command is executed again, but with dnf replaced by ssh. In other words, this command is executed:

$ history | grep ssh

deleting history

There may come a time when you want to delete some or all of the commands in your history file. If you want to remove a particular command, enter history -d . To clear the entire contents of the history file, run history -c. The history file is stored in a file that you can also modify. Bash Shell users find it in their home directory as .bash_history.

Next steps

There are a number of other things you can do with the story:

  • Set the size of your history buffer to a certain number of commands
  • Record the date and time of each line in the history
  • Prevent certain commands from being recorded in the history

Final words: How to See Command History in Linux

I hope you understand this article, How to See Command History in Linux. If your answer is no, you can ask anything via the contact forum section related to this article. And if your answer is yes, please share this article with your friends and family to give us your support.

James Hogan
James Hogan
James Hogan is a notable content writer recognized for his contributions to Bollyinside, where he excels in crafting informative comparison-based articles on topics like laptops, phones, and software. When he's not writing, James enjoys immersing himself in football matches and exploring the digital realm. His curiosity about the ever-evolving tech landscape drives his continuous quest for knowledge, ensuring his content remains fresh and relevant.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related Articles

Hubspot Service Hub review 2024: a comprehensive platform

When it comes to customer support operations, HubSpot Service Hub is an all-encompassing customer service platform that is meant to...
Read more
When players on Windows 11 or 10 try to log in to Steam, they may get the error code E87....
Users of Windows 11 or 10 may find it frustrating to deal with the error number 147-0 in Microsoft Office....
The Microsoft Store is an important part of the Windows operating system because it gives users a single place to...
It can be hard to find the right balance between usefulness, durability, and cost when it comes to kitchen storage....
Both AirDroid and Vysor are well-known tools that help Android users control their devices and mirror them. One of the...