Linux shells like Bash and Z shell provide powerful features for:
- Command history
- Auto-completion
- Faster command execution
- Productivity improvement
1. Command History
What is Command History?
Linux stores previously executed commands in a history file.
This allows users to:
- Reuse commands
- Avoid retyping
- Track previous operations
- Speed up administration work
View Command History
Basic Command
History
Run Previous Commands
Run Specific History Command
!4
Executes command number 4.
Repeat Last Command
!!
Repeat Last Command Starting with Specific Text
!docker
Runs latest command starting with docker.
History Navigation
Use keyboard:
| Key | Purpose |
|---|---|
| ↑ | Previous command |
| ↓ | Next command |
Very commonly used in daily Linux work.
Search History Interactively
Reverse Search
Press:
CTRL + R
Then type:
docker
Searches previous docker commands.
History File Location
For Bash:
~/.bash_history
For Zsh:
~/.zsh_history
Configure History Size
Temporary
HISTSIZE=5000
Permanent
Edit:
nano ~/.bashrc
Add:
export HISTSIZE=10000
export HISTFILESIZE=20000
Reload:
source ~/.bashrc
Ignore Duplicate Commands
Add in .bashrc:
export HISTCONTROL=ignoredups
Clear History
Current Session
history -c
Delete History File
rm ~/.bash_history
Real-World Usage of History
Kubernetes
history | grep kubectl
Find old Kubernetes commands.
Docker
history | grep docker
Troubleshooting
history | grep nginx
Check previous server changes.
2. Command Completion
What is Auto-Completion?
Auto-completion automatically completes:
- Commands
- File names
- Directories
- Variables
- Kubernetes resources
Mainly done using:
TAB key
Basic Completion Example
Type:
cd Doc
Press:
TAB
Becomes:
cd Documents/
Bash Completion Package
Advanced completion support package.
Install:
Ubuntu/Debian
sudo apt install bash-completion -y
Enable Bash Completion
Edit:
nano ~/.bashrc
Add:
source /usr/share/bash-completion/bash_completion
Reload:
source ~/.bashrc




















