If you hit Ctrl+r, you will see a new prompt that you can use to search your command history. You can also search your commands using the reverse-i-search tool. :~$ history | grep lġ0 history | grep l Method 2: Use reverse-i-search Now, I am going to use the history command piped with the grep command to find entries containing the character l. Fortunately, you can use tools to search history to help find that complex command you used earlier. However, with the potential to have up to 1000 commands, things can get messy quickly.
Obviously, my history file is now fairly short since I’ve just cleared it. :~$ history -cġ history 5) Searching for commands in the history We can erase the entire history using the -c option. Maybe you want to get rid of more than one line. If you made a mistake, you can erase a specific item with the -d option followed by the line number. :~$ !8ĭesktop Downloads fontconfig Pictures Templatesĭocuments sktop Music Public Videos 3) Delete a command from history 2) Running a command from the history using indexĭid you notice that the commands were numbered when you ran the history command? To re-run a specific command quickly, type ! and then the number. In fact, new entries will not be reflected in the file until you close the shell.
bash_history file, plus a new entry for ‘history’. Looks familiar, right? This is the content from our. This will return a numbered list of your recently entered commands. We’re just going to enter the command and see what is returned. This is great for when you make a mistake while entering some long complex command. If you don’t already know, using your up/down arrow keys lets you quickly scroll through your command history.
Many of us don’t think of what the command line was like before we knew this trick. 1) Use arrow keys to scroll through history of commands Let’s see some examples of using history command in Linux.
Ls How to use the history command in Linux? There are several history file settings that are editable from this file including the location of the log file.īy default, command history is usually logged to ~/.bash_history. The settings for history are set by your bash profile (Normally ~/.bashrc). The typical default for the number of commands logged is 1000 on Ubuntu, but it can vary from system to system. To understand the history command better, we will look at what settings can be configured by the user. Where are the settings for history command stored in Linux? Let’s walk through some examples that will improve our command-line skills and make us more productive. You’d be surprised how often this tool can come in handy, though! This program keeps track of everything that we type into the command line. One example is the history command in Linux. Unlike us, computers are capable of near-perfect memory. Sometimes being forgetful can be very frustrating and lead to painful consequences. Let’s face it, us humans are not great at remembering things.