Navigate Your Unix Shell History Like a Boss

Navigate Your Unix Shell History Like a Boss

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.


What Exactly is History?

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 running
  • HISTFILESIZE, 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

bash shell unix linux programming

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Linux Tutorial - Shell Bash Commands from the Beginning with Examples

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.

Bash Check If Shell Is Interactive or Not Under Linux / Unix Oses

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.

How to install bash shell in Alpine Linux

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.

Bash add pause in shell script with bash pause command

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.

Save terminal output to a file under Linux or Unix bash - nixCraft

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.