How you can Entry Command Historical past on Linux

With a large and mature feature set, it's easy to see why Bash is the standard shell on many Linux distributions. However, it is in competition for power users through alternatives like Zsh.

A particularly useful feature of Bash and Zsh is their history mechanism, which makes it easy to recall commands you entered in the past. Find out how to save time and avoid manually searching for complicated commands by taking full advantage of your shell's command history.

What is Shell History?

Shell history is a list of commands issued on the command line. Bash saves this history in a file called .bash_history in your home directory. In Zsh it is called .zsh_history. You can use the … story Command to view the current contents of your history:

You can change the location of this file by editing the HISTFILE Environment variable.

You can set the maximum number of gradient elements with the HISTORIC FILE SIZE Environment variable:


This sets the size of the history file to 1,000.

Shell history is useful when you want to repeat or change a previously entered command without having to retype a line from scratch. the !! Command repeats the previously entered command. If you want to change anything in the previously named command, enter ^ old ^ new. Here "old" is the part of the command line you want to replace and "new" is its replacement.


If you want to list those /Container Directory after listing / with ls /so change the command:

^ / ^ / bin

It would be the same as if you typed ls / am.

See also: How to change the default shell on Linux with chsh

Command line editing

Bash and Zsh both support command line editing. This is a more flexible way of accessing your command history than the history extension. By default, the keyboard shortcuts correspond to those of the Emacs editor. You can toggle them to work more like Vim if you want. Note, however, that Vim shortcuts for command line editing are more cumbersome, although Vim is great as a general-purpose text editor.

Related: Top reasons to give the Vim text editor a try

When you want to get a command, just press the up arrow on your keyboard. You can press up to navigate through all of your previous commands, while you can press the down arrow to switch to your newer commands. You can also use Ctrl + P and Ctrl + N to scroll up and down your history.

To search backwards, press CTRL + R, and then start typing to search history until you see the command you want to edit. Press Ctrl + S to look forward.

To change a command line, use the right and left arrow keys to move back and forth across the line. Alt + F will go forward one word and Alt + B will move backwards. To go to the beginning of a line, press Ctrl + A. To get to the end, press Ctrl + E. To delete a line completely, press Ctrl + K.

You can now access the shell history

There are a few simple methods that you can use to find your shell history and change commands without retyping the entire line. Both bash and zsh have command line editing features that make it very easy. Under Linux you have the choice between shells. Which one is best for you? Read on to find out which Linux shell suits your work style.

Which Linux Shell is Best? 5 common mussels in comparison

Are you looking for a Linux bash shell alternative? Here is an overview of which Linux shell is the best: tsh, fish, KornShell, and Z-Shell.

Continue reading

About the author

David Delony
(64 published articles)

David is a freelance writer living in the Pacific Northwest but originally from the Bay Area. He has been passionate about technology since childhood. David's interests include reading, watching quality TV shows and movies, retro games, and collecting records.

By David Delony

Subscribe to our newsletter

Subscribe to our newsletter for tech tips, reviews, free e-books, and exclusive deals!

Click here to subscribe

Leave a Reply

Your email address will not be published. Required fields are marked *