Member-only story

How to organize automatically your bash history ??

Xavier Pestel (Xavki)
2 min readDec 16, 2024

The bash history is a powerful tool. Remember when you begin a new job a reset your desktop and you need to start a new history. No ctrl+r and you lost your effiency.

In this post, I suggest you a tricks as an idea. I mean that it’s to give you something that you can adopt but also change for your use cases.

You can reformat and archive your bash history

In the most of time, the .bash_history makes a great job but you can improve it.

To do that you can edit the .bash_profile file in your home.

For example, you can change the format of the history to store in each line : the datetime, the location where the command was run and the entire command line.

And maybe you want to keep your history organize per month and keep only 10 months.

Ok let’s go !!!

Some commands

First, create the core line with the history

echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(history 1)" >> ~/.logs/bash-history-$(date "+%y-%m").log

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Already have an account? Sign in

Xavier Pestel (Xavki)
Xavier Pestel (Xavki)

Written by Xavier Pestel (Xavki)

Microservices architecture and opensource. I’m maintainer of xavki https://youtube.com/c/xavki-linux about opensource. My blog : https://xavki.blog/

No responses yet

Write a response