A powerful command-line tool to quickly search and retrieve commands from your shell history. Never scroll through your history again!
# Install
git clone https://github.com/abhijitkrm/findcmd.git ~/find-cmd && cd ~/find-cmd && ./install.sh
# Use
findcmd docker # Find docker commands
findcmd -i git # Interactive mode- Fast Search: Quickly find commands by keywords
- Multi-term Search: Search for commands containing multiple keywords
- Interactive Mode: Select and copy commands to clipboard
- Smart Filtering: Automatically removes duplicate commands
- Case-Insensitive: Default case-insensitive search (with case-sensitive option)
- Color Output: Easy-to-read colored output
- Cross-Platform: Works on Linux and macOS
- Multi-Shell Support: Compatible with Bash and Zsh
- Operating System: Linux or macOS
- Shell: Bash or Zsh
- Tools: Standard Unix tools (grep, sed)
-
Clone or download this repository:
cd ~ git clone https://github.com/abhijitkrm/findcmd.git find-cmd # OR download and extract the ZIP file
-
Run the installation script (IMPORTANT: use
./prefix):cd find-cmd chmod +x install.sh ./install.shNote: Always use
./install.sh, NOTsh install.shorbash install.sh -
Reload your shell configuration (or open a new terminal):
# For Bash source ~/.bashrc # For Zsh source ~/.zshrc
-
Verify installation:
findcmd --version
If you see "findcmd version 1.0.1", you're all set!
If you prefer to install manually:
-
Copy the script to a directory in your PATH:
mkdir -p ~/.local/bin cp findcmd ~/.local/bin/ chmod +x ~/.local/bin/findcmd
-
Add
~/.local/binto your PATH (if not already):For Bash - Add to
~/.bashrc:export PATH="$HOME/.local/bin:$PATH"
For Zsh - Add to
~/.zshrc:export PATH="$HOME/.local/bin:$PATH"
-
Reload your shell configuration:
source ~/.bashrc # or source ~/.zshrc
After installation, verify that findcmd is working:
findcmd --version
findcmd --helpfindcmd [OPTIONS] <search_term> [additional_terms...]Search for commands containing a specific keyword:
findcmd dockerThis will display all commands from your history that contain "docker".
| Option | Description | Example |
|---|---|---|
-c, --case-sensitive |
Enable case-sensitive search | findcmd -c Redis |
-n, --max <number> |
Limit number of results | findcmd -n 10 git |
-d, --duplicates |
Show duplicate commands | findcmd -d npm install |
-i, --interactive |
Interactive mode (select and copy) | findcmd -i docker |
-h, --help |
Show help message | findcmd --help |
-v, --version |
Show version | findcmd --version |
Interactive mode allows you to select a command and copy it to your clipboard:
findcmd -i dockerOutput:
Found 15 command(s) matching: docker
[1] docker ps -a
[2] docker build -t myapp .
[3] docker-compose up -d
...
Enter number to copy to clipboard (or press Enter to cancel): 2
✓ Copied to clipboard: docker build -t myapp .
Find all Git commands:
findcmd gitFind commands with both "docker" AND "compose":
findcmd docker composeSearch for exact case matches:
findcmd -c DockerfileShow only the 5 most recent npm commands:
findcmd -n 5 npmBrowse and copy a command:
findcmd -i kubectlInclude duplicate commands in results:
findcmd -d cdFind recent Redis commands, limit to 10:
findcmd -n 10 redis-clifindcmd postgres
findcmd mysql
findcmd mongodbfindcmd docker
findcmd docker-compose
findcmd docker buildfindcmd git commit
findcmd git push
findcmd git rebasefindcmd ssh
findcmd scp
findcmd rsyncfindcmd npm install
findcmd pip install
findcmd brew installfindcmd automatically detects your shell's history file:
- Bash:
~/.bash_history - Zsh:
~/.zsh_historyor~/.histfile
To get more results, increase your shell's history size:
For Bash - Add to ~/.bashrc:
export HISTSIZE=10000
export HISTFILESIZE=20000For Zsh - Add to ~/.zshrc:
export HISTSIZE=10000
export SAVEHIST=10000For interactive mode clipboard functionality:
- macOS: Uses
pbcopy(built-in) - Linux: Requires
xcliporxsel
Install clipboard tools on Linux:
# Ubuntu/Debian
sudo apt-get install xclip
# Fedora/RHEL
sudo dnf install xclip
# Arch
sudo pacman -S xclipTo remove findcmd from your system:
cd find-cmd
./uninstall.shThe uninstall script will:
- Remove the
findcmdbinary - Optionally remove PATH configuration from shell config files
- Create backups of modified files
Solution 1: Reload your shell configuration
source ~/.bashrc # or source ~/.zshrcSolution 2: Open a new terminal window
Solution 3: Manually verify installation
# Check if findcmd exists
ls -lh ~/.local/bin/findcmd
# Check if .local/bin is in PATH
echo $PATH | grep ".local/bin"Solution 4: Manually add to PATH
If ~/.local/bin is not in your PATH, add it manually:
For Zsh users:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrcFor Bash users:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrcThen verify:
findcmd --versionThis happens when the installer cannot auto-detect your shell. This is not a problem - just follow the manual PATH setup above.
Why it happens:
- Running installer with
sh install.shinstead of./install.sh - Using a non-standard shell
- Shell environment variables not properly set
Solution: Follow Solution 4 above to manually add to PATH.
Possible causes:
- Command doesn't exist in history
- History file is empty or not found
- Search term is too specific
Solutions:
- Check your history file:
cat ~/.bash_historyorcat ~/.zsh_history - Try a broader search term
- Make sure commands are being saved to history
Solution: Verify your shell's history configuration
# Check HISTFILE variable
echo $HISTFILE
# For Bash, ensure this is set
echo $HISTFILE
# Should output: /home/username/.bash_history
# For Zsh, ensure history is enabled
setopt HIST_SAVE_NO_DUPS
setopt HIST_IGNORE_ALL_DUPSOn Linux: Install clipboard utility
sudo apt-get install xclip
# or
sudo apt-get install xselOn macOS: Should work out of the box with pbcopy
Solution: Ensure the script is executable
chmod +x ~/.local/bin/findcmdA: No, findcmd only reads your history file. It never modifies or deletes anything.
A: Yes, but some special characters may need escaping. Try using quotes:
findcmd "docker run -p 8080:80"A: By default, findcmd shows up to 50 results. Use -n to change this:
findcmd -n 100 gitA: By default, searches are case-insensitive. Use -c for case-sensitive search:
findcmd -c RedisA: Currently, findcmd uses simple substring matching. Regular expression support may be added in future versions.
A: Currently, findcmd supports Bash and Zsh. Fish shell support may be added in the future.
A: Just add multiple terms separated by spaces:
findcmd docker nginx proxyThis finds commands containing all three terms.
A: Yes! Add aliases to your shell configuration:
alias fgit="findcmd -i git"
alias fdocker="findcmd -i docker"
alias fnpm="findcmd -i npm"Add these to your ~/.bashrc or ~/.zshrc:
# Interactive search aliases
alias fcd="findcmd -i cd"
alias fgit="findcmd -i git"
alias fdocker="findcmd -i docker"
alias fssh="findcmd -i ssh"
# Quick searches
alias fcmd="findcmd -i" # Generic interactive search
alias flast="findcmd -n 20" # Last 20 matching commandsUse findcmd output with other commands:
# Count matching commands
findcmd docker | wc -l
# Save results to a file
findcmd git > my-git-commands.txtFor even more powerful searching, combine with fzf:
findcmd git | fzfContributions are welcome! Feel free to:
- Report bugs
- Suggest new features
- Submit pull requests
- Improve documentation
MIT License - feel free to use and modify as needed.
Created to make command-line history searching easier and more efficient.