Unix & Linux Asked on October 31, 2021
I was wondering how to search commands in history without knowing the first few letters of the command?
When searching using Ctrl+R in bash
, one has to give the first few letters of the command. What if I only know some characters in the middle, or some at the beginning and some in the middle?
For example, to search cat myfile
, I only know there is at
in it, or c
at the beginning and my
in the middle somewhere. keywords have to be continuously positioned. For example, in cat myfile
, I would like to search for bothc
and my
, but Ctrl+R will not allow to specify both simultaneously.
Bash only has a simple string search, as far as I can see.
Consider switching to zsh, which has a history wildcard search. history-incremental-pattern-search-backward
and history-incremental-pattern-search-forward
aren't bound to keys by default, but you can bind them:
bindkey '^X^R' history-incremental-pattern-search-backward
bindkey '^X^S' history-incremental-pattern-search-forward
Then type Ctrl+X Ctrl+R ^c*my
.
Answered by Gilles 'SO- stop being evil' on October 31, 2021
Apropos(1) should also return a man for the subject if the man contains that word. Whatis(1) returns only absolute matches.
For reference: Apropos == man -k Whatis == man -f
These two should be a great help, along with wildcards * and ?
Answered by baweaver on October 31, 2021
If you are just looking to find the line (to jog your memory) you could just grep for the part of the command you remember:
history | grep "substring"
Answered by jasonwryan on October 31, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP