Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Sometimes I want to search/filter help for particular commands for keywords.

history --help

gives list of options, sometimes it's overwhelming how much info is there. Can I filter it for keywork "clear" e.g.

history --help *clear*

Also sometimes I want all info from --help, but it's so long that some of the lines get lost and I cannot scroll up for them. How can I make it show screen by screen e.g. fill first screen then on key press fill second screen etc.

Question same for file listing command.

share|improve this question

3 Answers 3

--help is not a universal command (it's an argument to the command being called, and has to be provided explicitly by it), so there is no universal solution (in fact, history has no --help option on my system). You probably want something like history --help 2>&1 | grep -E '(^|[^[:alnum:]])clear' (the redirection is necessary for some commands that print their help/usage text on STDERR.

You could make this into a function like so:

helpgrep() {
    [ "$#" -eq 2 ] || return 1
    "$1" --help 2>&1 | grep -E "(^|[^[:alnum:]])$2"
}

Then run it with helpgrep command search-string.

As for your second issue, try piping it to less (or more if less is not available), for example, history --help | less.

share|improve this answer

To view the commands that have clear in them you could use grep:

history | grep clear

If the output is long you can view it on a page-page basis using pipe the output thru more:

 history | more

Of course you can combine these

history | grep clear | more

This is not specific to just history so can be applied to any other command where you want to filter results and/or view ouptut a screen height at a time.

share|improve this answer

history --help | grep clear shows you the lines that contain the word (or part of a word) clear. This is a pipeline, where the output of the first command (history --help) becomes the input of the second command (grep clear, and grep is a command to search for a pattern in some text). You can also browse the whole help by running history --help | less (less is a text file viewer) and use the / key in less to search for clear.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.