If you use a Mac or Linux terminal, chances are you’ve interacted with the shell history. Most people I know just use the up arrow to find a previously executed command, but this misses out on a serious amount of power.
If you use a Mac or Linux terminal, chances are you’ve interacted with the shell history. Most people I know just use the up arrow to find a previously executed command, but this misses out on a serious amount of power.
In this tutorial, I’m going to teach you how to navigate history like a boss.
Most Unix-style shells come with a history feature built in. This means when you type a command it is remembered by the shell and you can recall it later.
History isn’t magic, the commands are actually stored in memory and subsequently in a file. You can locate this with:
echo $HISTFILE
For me this prints:
/home/dir/.zhistory
To view the file contents we can run:
cat $HISTFILE
We can see this is just a flat list of commands. The number of commands stored is governed by two shell variables:
HISTSIZE
, which determines how many commands are stored in memory while a session is runningHISTFILESIZE
, which determines how many commands are stored in your history file.To save the last 1000 commands, add something like the following to your shell config file (usually ~/.bashrc
or ~/.zshrc
):
export HISTFILESIZE=1000
export HISTSIZE=1000
Linux Tutorial - Shell Bash Commands from the Beginning with Examples. Learn BASH command interpreter explained step by step and with examples. Learn what Linux is and how the command interpreter fits into the operating system. Get and install Linux. Understand the structure and syntax of Linux commands. Learn to manage the elements of the filesystem: files and directories. Learn to install software from official servers or from any compatible file.
Explains how to check and find out if a GNU/bash shell is interactive or not using various methods under Linux / macOS (OS X)/*BSD/Unix operating systems.
This page explains how to install bash shell in Alpine Linux using the apk command line options including setting up command-line tab-completion for bash.The postmarketOS project, which is designed to run on mobile devices, is based on Alpine Linux. Many Docker images are also based upon Alpine, and you may install bash shell in Docker-based images too.
Explains how to add pause prompt in a bash script with the read and sleep commands to pause the execution of the next command for a given amount of time.
Explains how to save terminal output to a file under Linux, macOS, *BSD, and Unix-like operating system when using BASH/KSH/CSH & other shells.