By default, your terminal records past commands but hides one detail — the exact date and time. If you want to check linux history with timestamp output, a small configuration change is all it takes. This guide walks you through setting it up on any modern distribution.

Why Does Showing Date and Time in Linux History Matter?

The built-in history utility lists previous commands alongside line numbers. That output won’t tell you when something ran. Knowing the execution time helps with troubleshooting broken deployments, auditing server activity, and reviewing your daily workflow.

On shared servers where multiple users have sudo access, timestamps make it far easier to trace who ran what and when.

Common Use Cases for Command History Timestamps
Troubleshooting
92%
Security Audits
78%
Compliance Logs
64%
Workflow Review
53%

Configuring Linux History With Timestamp Using HISTTIMEFORMAT

A single environment variable controls this behavior: HISTTIMEFORMAT. Once defined, every recorded command displays its execution date and time.

Run this in your terminal:

export HISTTIMEFORMAT="%F %T "

The format specifiers break down like this:

SpecifierWhat It ShowsExample Output
%FFull date (Year-Month-Day)2026-02-23
%TClock time (Hour:Minute:Second)14:35:09

After running that line, type history again. You should now see dated entries beside each recorded command. If you need to install a specific package version later, the timestamps let you match the install to a known good state.

One catch: this change only lasts for your current session. Close the terminal, and timestamps vanish from future output.

Making Linux History With Timestamp Permanent

To keep timestamps across reboots, place the variable inside your shell configuration file. For Bash users, that means editing ~/.bashrc.

Open it with any text editor:

nano ~/.bashrc

Scroll to the bottom and paste this line:

export HISTTIMEFORMAT="%F %T "

Save the file and close the editor. Then reload the configuration:

source ~/.bashrc

From this point forward, every history call will print linux history with timestamp data — even after a system restart. This is the same .bashrc file where you’d add PATH directories for missing commands like wget.

Applying Timestamps for All Users on the System

The steps above only affect your own account. If you manage a shared server and want every local account to see dated command logs, place the variable inside /etc/profile instead.

nano /etc/profile

Add the same line at the end:

export HISTTIMEFORMAT="%F %T "

Save, then reload:

source /etc/profile

Now switch to any local account and run history. Dated entries should appear for that user too. On systems where you also need to open specific ports, having timestamps on every account speeds up incident response.

Removing Timestamps From Bash History

Changed your mind? Delete the HISTTIMEFORMAT line from whichever file you edited — ~/.bashrc or /etc/profile — and source it again. The output reverts to plain numbered entries.

A Quick Note on Older Commands

After first enabling this feature, you may notice that older entries all share the same date and time. That happens because timestamps were not recorded before the variable existed.

Only commands executed after you defined HISTTIMEFORMAT carry accurate timing data. Give it a few minutes, run some new commands, and correct values will appear going forward.

This behavior is specific to the bash shell history mechanism. Zsh and Fish handle history timestamps differently.

Summary

TaskFile to EditScope
Temporary timestampsNone (run export in terminal)Current session only
Permanent for one user~/.bashrcSingle account
Permanent for all users/etc/profileEvery local account

Enabling linux history with timestamp output takes under a minute to configure. It gives you a clear audit trail of every command you run — useful whether you’re debugging shared library errors, reviewing file permission changes, or tracking down when a missing tool was last used.

FAQs

Does HISTTIMEFORMAT work on Zsh or Fish shells?

No. HISTTIMEFORMAT is a Bash-specific variable. Zsh uses HIST_STAMPS in its .zshrc configuration, and Fish records timestamps by default without extra setup.

Can I use a custom date format for linux history with timestamp?

Yes. Replace %F and %T with any strftime specifiers. For example, "%d/%m/%y %I:%M %p " displays day/month/year with a 12-hour clock and AM/PM.

Why do all old history entries show the same timestamp?

Bash did not record time data before you set HISTTIMEFORMAT. Older entries default to the moment you enabled the variable. Only new commands carry accurate dates.

How do I increase the number of commands stored in bash history?

Set HISTSIZE and HISTFILESIZE in your ~/.bashrc. For example, HISTSIZE=10000 and HISTFILESIZE=20000 keep up to 10,000 entries in memory and 20,000 on disk.

Will timestamps increase the size of my .bash_history file?

Slightly. Each timestamp adds one extra comment line per entry. On a file with 1,000 commands, this adds roughly 15–20 KB — negligible on modern systems.

Willie has over 15 years of experience in Linux system administration and DevOps. After managing infrastructure for startups and enterprises alike, he founded Command Linux to share the practical knowledge he wished he had when starting out. He oversees content strategy and contributes guides on server management, automation, and security.