Read man page or file from certain row - linux

Is there a way to read a man page from a certain row?
I grepped for a specific flag in a man page and saw what line it was in, is there a way start reading the man form that line?

man uses $MANPAGER or $PAGER, so it depends on what you're using. To start reading the manpage for foo at the first match of 'pattern', you might try:
MANPAGER='less -p pattern' man foo
or (assuming ${MANPAGER-PAGER} is less):
LESS+='-p pattern' man foo

Related

use of <> in man page to indicate optional white space

I'm maintaining an old KornShell shell script and its man page.
The shell script's command line options include both -wwidth (no intervening space) and -w width (with intervening white space), which have the same effect. In the man page this is documented in the SYNOPSIS section as [-w<>width], apparently using <> to mean optional white space.
I haven't been able to find on the Web other UNIX or Linux man pages that use <> for this purpose, so I presume that this doesn't follow a convention that UNIX or Linux users expect, and thus users may be confused by <> in the man page.
Which of the following representations in a man page makes it most clear that white space between the -w and width is optional:
[-w<>width],
[-w[ ]width], or
[-wwidth|-w width]?
Is it better to just have one of either [-wwidth] or [-w width] in the man page, on the basis that they do the same thing so there is little or no value added to the user to document that both of these alternatives are available?
I would just document -w width because it's a universal convention that options with arguments can take the argument either in the same command-line argument (-w80) or the following command-line argument (-w 80).
Any tool/option that does not follow the convention should document it, but your case looks pretty standard.

How to bookmark most using linux command line

How i can bookmark my custom command line in linux (centos 6.2)?
I'm using history | grep keyword and then !command number now.
But is there any faster solution?
just use alias:
alias lala="ls -lrt|grep a"
Yes. You can define an alias, a function, or write a script in your bin folder.
Most shell's provides more complex history expansion. For example you can use
!?str
in zsh, bash etc. to execute the most recent command that contains str.
Another possibility to save keystrokes would be to use the incremental search of the history if you want a broader control over what you want to select.
To search the history backwards this feature is usually bound to <ctrl>-r, for forward search it's <ctrl>-s (at least in bash and zsh).
Just put a comment tag on it and you can search for the tag latter.
$ my-command # tag-bookmark-1
Then later you can grep or search history for tag-bookmark-1.
Use something shorter if you would like.
(I can't say about !, because I always use export histchars="")

What does "#$" mean in bash?

Say for example a script begins like this
#!/bin/bash
#$ -S /bin/bash
#$ -l hostname=qn*
and then later down the page the actual script comes into play. My question is what does the "#$" symbol mean or do?
Are you by any means running on a batch cluster? Like Sun Grid Engine? There might be special meanings in scripts intended to run as a batch job.
https://www.wiki.ed.ac.uk/display/EaStCHEMresearchwik/How+to+write+a+SGE+job+submission+script
Update:
above link blocks when used from stackoverflow.com (works from google.com)
alternatives:
http://www.cbi.utsa.edu/sge_tutorial
http://web.njit.edu/all_topics/HPC/basement/sge/SGE.html
Lines beginning with # are comments. The first line may begin with #!, but it's still a comment to bash and is merely used to indicate the interpreter to use for the file. All other lines beginning with # are absolutely unimportant to bash, whether the next character is $ or anything else.
They seem to be parameters for the Oracle (ex-Sun) Grid Engine, look at this SO question or this one.
They are heavily using these kind of comments.
Those line are important for queue systems like sbatch.

Dynamic abbrev expand for the shell

Is there a function on one of the linux shells like the emacs dabbrev-expand?
First to give a definition:
M-xdescribe-functionEnterdabbrev-expandEnter
...
Expands to the most recent, preceding word for which this is a prefix.
Given that bash seems to be most heavily influenced by Emacs, looking there first reveals a few possibilities:
man bash(1), readline section
dynamic-complete-history (M-TAB)
Attempt completion on the text before point, comparing the text
against lines from the history list for possible completion matches.
dabbrev-expand
Attempt menu completion on the text before point, comparing the text
against lines from the history list for possible completion matches.
By default (or my system at least), M-/ is already bound to complete-filename:
$ bind -l | grep /
"\e/": complete-filename
You could re-bind it by putting
"\e/": dabbrev-expand
in your ~/.inputrc or /etc/inputrc.
Note that it only seems to complete the first word (the command), and only from history, not from the current command line as far as I can tell.
In zsh, I can't see anything in the man page that does this, but it should be possible to make it happen by figuring out the appropriate compctl command (Google mirror).

How to get specific section inside a MAN page?

I want to get only specific sections of MAN page inside a shell (or perl) script and print it.
For eg: only the SYNOPSIS section of MAN page
Is there any standard way to do that?
Regards,
Anandan
Not as far as I know, but you can search by typing '/' followed by the text you want to search for, then press 'n' repeatedly to go to the next match, or 'N' to go to the previous match.
I haven't played with Linux/Unix in a long while, but perhaps you can perform a:
man MANPAGE|a2ps -m > grep -A 1000 SYNOPSIS
Type the '/' key, then type the string you want to search for (you'll see your query at the bottom of the terminal as you type) and press enter. It'll highlight all the matches and take you to the first one. After that, type '/' and press enter to go to the next match.
If you want to navigate to a specific section of a man page you can use this handy method:
Definition
man2() {
man -P 'less -p ^EXAMPLES' $1
}
Example
man2 stat
at the end of a man page you may find something like a command(some-number) where
that (some-number) is the section that contains that command in man pages
so I use the -K switch (note it is a big K) followed by the specified section number and it works for me:
`man -K section_number term_or_command`
i.e.
man -K 5 /etc/host.conf

Resources