Table of contents
Get the industry’s fastest, most secure VPS hosting ◦ 99.99% uptime
◦ Comprehensive security
◦ 24/7 support

VPS → Bash History

Bash history: Linux command guide for VPS management

Running a VPS on Linux gives you flexibility and control, but only if you know how to command it. And when you’re deep into server setup, debugging cron jobs, or configuring your firewall rules, being able to track, reuse, or edit previous Bash commands can save hours.

That’s where Bash history comes in. It’s not just a log—it’s a superpower for Linux users. Want to re-run a perfect command from earlier today without typing it all over again? Or trace back something you did yesterday that just broke your config? History has your back.

This guide walks through the essentials of managing your Bash history on a Linux VPS. We’ll cover how to view, search, customize, and even scrub your history. Perfect if you’ve already been working in Linux, but want to get way more efficient.

Get premium VPS hosting

High-performance VPS hosting that delivers unrivaled power

How to view bash history

Using the history command

To get started, open your terminal and type:

You’ll see a numbered list of your previously run commands. Each line represents one command, with its corresponding history number on the left.

This is the simplest way to review what you’ve been doing recently. It’s especially handy when debugging something or retracing steps in a deployment.

Additional viewing options

Want to get more specific? Here are a few powerful ways to dig into your Bash history:

Show the last n commands 

To see only the last 20 commands, for example:

This is useful when you’re only interested in your recent activity, like a deployment or system update you just ran.

Search history with grep

This is great for finding a specific command (or type of command) without scrolling endlessly. For example:

Pipe to less for scrollable viewing

This lets you page through your command history one screen at a time. Especially helpful when looking through a large session.

Scrolling the bash history

Sometimes the simplest way is still best:

How to delete .bash_history

When would you want to delete history?

Options for clearing history

Each method serves a slightly different purpose:

Clear the history for this session

This is useful if you want to start fresh during a current terminal session.

Delete a specific line from history

This replaces command 203 with nothing. Ideal for removing just one risky or incorrect entry.

Clear the saved history file

This wipes the .bash_history file. Use it when you’re ready to permanently delete all saved commands between sessions.

.bashrc and configuring bash settings

.bashrc is a hidden config file in your home directory. Bash runs it every time you open a new terminal session. It’s where you can customize your environment—aliases, prompt behavior, and importantly, how Bash handles history.

Set the number of commands that history recalls

By default, Bash saves the last 500 commands, but you can change that.

This is useful if you run a lot of terminal commands and want a longer audit trail.

Keep all your bash histories

By default, your last terminal session can overwrite earlier ones. To append history (instead of replacing it), add this to .bashrc:

This is essential when working across multiple tabs or SSH sessions.

Add commands to history immediately

Normally, Bash writes history only when a session ends. To write every command as soon as it’s executed:

PROMPT_COMMAND=’history -a’

This is helpful if your VPS crashes mid-session or if you want to see commands live in other sessions.

Exclude certain commands from bash history

You might want to skip storing things like ls or cd.

HISTIGNORE="ls:cd:pwd:exit"

Useful for reducing clutter and focusing on commands that actually matter.

Bash history with timestamp

Normally, Bash writes history only when a session ends. To write every command as soon as it’s executed:

This adds YYYY-MM-DD HH:MM:SS before each command when you run history.

Bash history search tips and tricks

Why search your bash history? Because retyping complex commands is a pain. Searching lets you quickly reuse or tweak something you’ve done before—especially during VPS maintenance, config, or scripting.

Searching bash history

Press and hold CTRL+R, then start typing. Bash will auto-complete the most recent match.

Execute a command from search (without copying it)

!keyword

For example:

 !nginx
… instantly re-runs the most recent command that starts with nginx.

Additional bash history search commands

Once you’re comfortable with search, these shortcuts can really speed things up:

CTRL+S: Searches forward through history (reverse of CTRL+R).

Note: In some terminals, this suspends the session. To fix:

Bash history search mid-command

Already halfway through typing something? Use reverse history in terminal like this:

This method is super useful when you’re trying to repeat a multi-flag command like rsync or tar.

Bash history expansion commands

History expansions are shortcuts that let you reuse parts of previous commands without typing them all over again. They’re fast, efficient, and especially handy on VPS where you’re scripting or installing tools.

There are two main types: designators (which pull up past commands) and modifiers (which edit those commands on the fly).

Event designators

Used to recall previous commands.

!!: Repeat the last command

!n: Run command number n from your history—for example:
!205

!-n: Run the command n lines before the current one—for example:
!-3

^old^new: Replace old with new in last command—for example:
^dev^prod

!*: Grab all arguments from the last command—for example:

# becomes cp foo bar

Word designators

Use these to pull specific parts (words) from the last command.

For example:

# runs: echo archive.tar.gz

Modifiers

Used to tweak command parts:

For example:

# returns /var/www/html/index

Additional resources

VPS: A beginner’s guide →

A complete beginner’s guide to virtual private servers

Protect your VPS from DDoS attack →

9 steps to harden your virtual server

Expert tips for managing your VPS →

A complete guide to help you run your VPS with confidence

Image

Brooke Oates is a Product Manager at Liquid Web, specializing in Cloud VPS and Cloud Metal, with a successful history of IT/hosting and leadership experience. When she’s not perfecting servers, Brooke enjoys gaming and spending time with her kids.