Using already used commands for autocompletion in bash terminal

how to store previously executed commands on terminal and later just search and use automatically
ChatGPT said:
To store and automatically reuse previously executed commands in the terminal, you can rely on your shell's history feature. Here's how to make it powerful and efficient:
✅ 1. Enable and Configure History Storage
For Bash:
Add the following to your ~/.bashrc
or ~/.bash_profile
:
bashCopyEdit# Increase history file size
HISTSIZE=10000
HISTFILESIZE=20000
HISTCONTROL=ignoredups:erasedups
HISTTIMEFORMAT='%F %T '
# Immediately append to history after each command
PROMPT_COMMAND='history -a; history -c; history -r'
Then run:
source ~/.bashrc
✅ 2. Searching Command History
Use reverse search:
Press Ctrl + R
and start typing a past command. It'll autocomplete as you type.
Example:
(reverse-i-search)`kubectl`: kubectl get pods -n dev
Keep pressing Ctrl + R
to cycle through matches.
✅ 3. View and Reuse with history
Command
history # Lists all saved commands with numbers
!123 # Re-executes command number 123
✅ 4. Use fzf
for Fuzzy Search
Install fzf:sudo apt install fzf # or brew install fzf on Mac
Then add to ~/.bashrc
:
Edit# Fuzzy search history
bind '"\C-r": "\C-a\C-k$(history | fzf --tac | cut -c 8-)\n"'
Now pressing Ctrl+R
gives you a fuzzy searchable interface.
✅ 5. Bonus: Save Across Sessions
Bash already saves command history in ~/.bash_history
. You can also manually view or edit this file.
Let me know your shell (Bash, Zsh, Fish) if you want shell-specific enhancements.
You said:
how to open ~/bashrc file in windows bash
ChatGPT said:
In Windows (like WSL or Git Bash), here's how you can open and edit the ~/.bashrc
file:
✅ If using WSL (Windows Subsystem for Linux):
Open WSL terminal (Ubuntu or Debian).
Run:
nano ~/.bashrc
Or use
vi ~/.bashrc
orcode ~/.bashrc
(if VS Code is installed and configured).
✅ If using Git Bash:
Open Git Bash terminal.
Run:
nano ~/.bashrc
If
nano
isn’t available, use:vi ~/.bashrc
Or open with Notepad:
notepad ~/.bashrc
✅ Alternative (in File Explorer):
To locate the file directly:
For WSL, it's usually under:
\\wsl$\Ubuntu\home\<your-username>\.bashrc
For Git Bash, it's typically:
C:\Users\<your-username>\.bashrc
Let me know if you're using WSL 1/2, Git Bash, or another terminal, and I can give more tailored help.
Subscribe to my newsletter
Read articles from Aditya Patil directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Aditya Patil
Aditya Patil
Hi, I'm Aditya — a Cloud & DevOps Engineer passionate about automating everything from CI/CD pipelines to multi-cloud infrastructure. I specialize in AWS, Kubernetes, Terraform, and GitOps tools like Argo CD. I’ve helped teams scale applications, cut cloud costs by 90%, and build disaster-ready infra. I love sharing real-world DevOps lessons, cloud cost optimization tips, and infrastructure design patterns. Let’s connect and simplify the cloud — one YAML file at a time ☁️⚙️