Boost Your Linux Productivity: 8 Powerful History Command Tricks
Learn how to master Linux command‑line history by displaying timestamps, reverse‑searching, re‑executing previous commands, running specific entries, adjusting history size, renaming the history file, clearing records, and even disabling history altogether, all with simple shell configurations and commands.
When you frequently use the Linux command line, leveraging the history command can dramatically improve productivity. This guide presents eight practical techniques.
1. Show timestamps with HISTTIMEFORMAT
Set the environment variable to prepend each command with a date‑time stamp:
export HISTTIMEFORMAT='%F %T '
history | less2. Search history with Ctrl+r
Press Ctrl+r and type a keyword to perform a reverse incremental search. For example, typing wget brings up the most recent command containing that word, which can then be executed by pressing Enter or edited further.
3. Repeat the previous command
Use !! to run the last command, or !-1 for the same effect.
4. Execute a specific command by number
Prefix an exclamation mark to the line number shown by history to re‑run that command, e.g., !4.
# Example output
[root@localhost ~]# !4
ss -tul
...5. Control total history lines with HISTSIZE
Check the current size: echo $HISTSIZE # 1000 by default on CentOS 8 Append a new size to .bash_profile and reload:
echo "HISTSIZE=200" >> .bash_profile
source ~/.bash_profile6. Change the history file name
Set HISTFILE to a custom path in .bash_profile:
echo "HISTFILE=/root/.cmd_hist" >> ~/.bash_profile
reboot7. Clear the history
Run the -c option to erase the current session’s history:
history -c8. Disable history entirely
Set both HISTSIZE and HISTFILESIZE to 0 in .bash_profile and source the file:
echo "HISTSIZE=0" >> .bash_profile
echo "HISTFILESIZE=0" >> .bash_profile
source ~/.bash_profileThese configurations let you tailor Bash history behavior to suit auditing, debugging, or privacy needs.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
