Page 1 of 1
the secret of "man"
Posted: Thu Jan 25, 2024 3:24 am
by Duliwi
I still have big problems with the man pages on Linux Bash. It seems that there is still a secret regarding "man" that I don't know yet.
Here is an example:
In this example I don't need "man" because I already figured out how it works with ChatGPT. But if I had only used the man page for advice, I would never have found out how to get there.
I want to use the "sed" command to insert lines at a specific position in an existing "config" file. The lines that were previously at this position should then be moved down (not deleted).
Thanks to ChatGPT I know that this can be done as follows:
Code: Select all
sed -i '/SearchPattern/a NewLine1\nNewLine2\nNewLine3' filename
If I wanted to inform myself via "man sed", I would search for "-i".
But under "-i" it only says the following:
Code: Select all
-i[ENDUNG], --in-place[=ENDUNG]
Edit files in place (creates backup if ENDUNG is specified)
Not a single word about the fact that you have to put the search pattern between / /:
/search-pattern/
Also not a single word about the fact that you need "/a" to insert the new lines.
So how can we know that? Precisely because I don't know, how the command works, I look it up in "man", but if man doesn't tell me how it works, it's useless.
Would appreciate if someone could share the secret with me. Thank you.
Re: the secret of "man"
Posted: Thu Jan 25, 2024 5:38 am
by ceeslans
Perhaps check out an online tutorial ?
How-ToGeek has a nice step-by-step tutorial
https://www.howtogeek.com/666395/how-to ... -on-linux/
Re: the secret of "man"
Posted: Thu Jan 25, 2024 6:14 am
by gimcrack
Great examples; Like this part.
The Power of sed
The sed command is a bit like chess: it takes an hour to learn the basics and a lifetime to master them (or, at least a lot of practice).
I also use other sources to see good examples of Linux commands. I usually use
https://www.geeksforgeeks.org/linux-commands/
Re: the secret of "man"
Posted: Thu Jan 25, 2024 7:44 am
by j2mcgreg
@Duliwi
The secret of man pages is that they are a relic from the early days of Linux where it was assumed that their audience would have the level of knowledge necessary to understand them. Today, there are many free bash tutorials available that make man pages redundant:
https://www.codecademy.com/catalog/language/bash
I know that you think that ChatGPT is a sort of panacea, but it's tendency to miss the nuances that make a language work means that it is still unreliable as a teaching aid.
Re: the secret of "man"
Posted: Thu Jan 25, 2024 8:28 am
by DukeComposed
Duliwi wrote: Thu Jan 25, 2024 3:24 am
If I wanted to inform myself via "man sed", I would search for "-i".
But under "-i" it only says the following:
Code: Select all
-i[ENDUNG], --in-place[=ENDUNG]
Edit files in place (creates backup if ENDUNG is specified)
Not a single word about the fact that you have to put the search pattern between / /:
/search-pattern/
You mean this section?
Code: Select all
The following address types are supported:
[snip]
/regexp/
Match lines matching the regular expression regexp.
Duliwi wrote: Thu Jan 25, 2024 3:24 am
Also not a single word about the fact that you need "/a" to insert the new lines.
Like this?
Code: Select all
Zero- or One- address commands
a \
text Append text, which has each embedded newline preceded by a backslash.
i \
text Insert text, which has each embedded newline preceded by a backslash.
Duliwi wrote: Thu Jan 25, 2024 3:24 am
So how can we know that? Precisely because I don't know, how the command works, I look it up in "man", but if man doesn't tell me how it works, it's useless.
There's a section at the bottom of the man page. It says
Code: Select all
The full documentation for sed is maintained as a Texinfo manual. If the info and se programs are properly
installed at your site, the command
info sed
should give you access to the complete manual.
"info sed" contains even more information about sed usage, including examples, and one of the examples is titled "7.9 Adding a header to multiple files" that looks very similar to what you obtained from an LLM.
Duliwi wrote: Thu Jan 25, 2024 3:24 am
Would appreciate if someone could share the secret with me. Thank you.
The secret is to keep learning and keep practicing. It isn't always easy to learn UNIX tools, particularly for the older and more advanced utilities. You could have achieved the same result by writing a Perl script or one-liner, but not knowing the procedure of using open(), write(), or close() is not necessarily the fault of the quite old, quite voluminous documentation that exists to explain it. Keep learning. Keep practicing.
Re: the secret of "man"
Posted: Thu Jan 25, 2024 8:34 am
by fehlix
Duliwi wrote: Thu Jan 25, 2024 3:24 am
I still have big problems with the man pages on Linux Bash. It seems that there is still a secret regarding "man" that I don't know yet.
Here is an example:
In this example I don't need "man" because I already figured out how it works with ChatGPT. But if I had only used the man page for advice, I would never have found out how to get there.
The information man provides depends on what you are looking for.
Esp. bash is the huge, some more details on internal functions/commands
may be shown with with bash's help-command instead.
help help
You may need read the sed's man twice - all the information is there.
Re: the secret of "man"
Posted: Thu Jan 25, 2024 1:33 pm
by timkb4cq
Duliwi wrote: Thu Jan 25, 2024 3:24 am
Not a single word about the fact that you have to put the search pattern between / /:
/search-pattern/
Actually you don't. You can use almost any one byte character instead of a /
In my case, I often use sed on web addresses. If I use / as the delimiter I have to escape all of them in the pattern so I use an alternate one |
Compare
Code: Select all
sed -i 's/^https:\/\/mxrepo.com\/Downloads\/fileone/wget http:\/\/la.mxrepo.com\/Downloads\/fileone/'
and
Code: Select all
sed -i 's|^https://mxrepo.com/Downloads/fileone|wget http://la.mxrepo.com/Downloads/fileone|'
and you can see how much easier it is to tell if the command is right. Or you can pick an common character like e instead of / or | and obfuscate your command with all the backslashes escaping each e.

Re: the secret of "man"
Posted: Thu Jan 25, 2024 2:17 pm
by Charlie Brown
@timkb4cq Thank you for that, really nice and useful trick :)
Re: the secret of "man"
Posted: Fri Jan 26, 2024 3:26 am
by Duliwi
This are all great links, hints and great stuff. Thank you all.
Re: the secret of "man"
Posted: Sat Feb 17, 2024 11:23 pm
by trawglodyte
At one time I downloaded a package that allowed me to do man -H <packagename> and it would open the man in default browser, making it much easier to read, scroll, and search. But it may have only worked for the conky man and a few others. They had to have an entry somewhere for it to work. I thought this was a common thing, and I was just the last to know. Now I can't remember what the package was or how to get it again. I love the mans and use them all the time, but some are written better than others.
Re: the secret of "man"
Posted: Sat Feb 17, 2024 11:51 pm
by xaol
trawglodyte wrote: Sat Feb 17, 2024 11:23 pm
At one time I downloaded a package that allowed me to do
man -H <packagename> and it would open the man in default browser, making it much easier to read, scroll, and search. But it may have only worked for the conky man and a few others. They had to have an entry somewhere for it to work. I thought this was a common thing, and I was just the last to know. Now I can't remember what the package was or how to get it again. I love the mans and use them all the time, but some are written better than others.
that sounds like it might be the package
troffcvt. after installing it in an mx 23 virtual machine,
opens the man manual page in firefox. as does
--html=firefox in place of
-Hfirefox. it worked for the few different pages i tried (ls, parted, man).
Re: the secret of "man"
Posted: Sun Feb 18, 2024 12:07 am
by DukeComposed
trawglodyte wrote: Sat Feb 17, 2024 11:23 pm
I love the mans and use them all the time, but some are written better than others.
Please remember that man pages were a pretty revolutionary concept when they were created. Instead of an actual big, thick paper operator's manual, which came with a computer same as you'd get when you buy an automobile, you could get the same information represented electronically, through a consistent "man" interface.
man pages were designed to be familiar to the people who were used to only previously having the paper version. After a couple of decades, you just get used to them.
Also be aware that "info" was created to modernize man pages and bring them into the 1990s. The format of an info page is decidedly HTML-ier. I imagine in a few years we'll have a tutorial system that divulges the important bits about how to use "ps" in under 60 seconds and is formatted like a TikTok video.
Re: the secret of "man"
Posted: Sun Feb 18, 2024 8:03 am
by Greg Brannon
@xaol, post #11
This is a great tip! I was struggling with 'man rsync' just yesterday and could have used this since the man pages are so long and detailed, yet unsearchable in a terminal session. I had to do some research to get man -H to work, and this is what I learned:
Your post mentioned that a package had to be install to use the man -H option. My research pointed to the package 'groff' as being required. I tried man -H several different ways -- none worked with unhelpful errors -- before stumbling on the requirement for groff. Once groff was installed, the man -H option works great!
Thanks for mentioning!
Greg.
Re: the secret of "man"
Posted: Sun Feb 18, 2024 8:08 am
by trawglodyte
xaol wrote: Sat Feb 17, 2024 11:51 pm
that sounds like it might be the package
troffcvt. after installing it in an mx 23 virtual machine,
opens the man manual page in firefox. as does
--html=firefox in place of
-Hfirefox. it worked for the few different pages i tried (ls, parted, man).
troffcvt it is! and -Hfirefox is great to know too because somehow my www-browser default got changed. I definitely need to make a note of this and add it to my must haves. Thanks.
p.s.
troffcvt includes
groff and a few others as depends. On my machine I had tried
groff and few of the others while trying to remember, but
troffcvt was the one I was missing that got it working.
Re: the secret of "man"
Posted: Tue Feb 27, 2024 8:01 am
by trawglodyte
man -H <command> was opening with elinks text browser. man -Hfirefox <command> was opening with firefox, but I'm too lazy to type -Hfirefox all the time. export BROWSER=firefox made firefox the default CLI www-browser, so now I can just do man -H <command> to get a man in firefox. I think you can export BROWSER=google-chrome-stable or whatever browser you want.
Somebody told me if I knew how to properly use a terminal I wouldn't have to open the man's in a browser to read, search, and scroll while I was figuring this out. lol, oh well. I'm happy for now!
Re: the secret of "man"
Posted: Tue Feb 27, 2024 11:01 am
by MXRobo
Is this page relevant?
https://us-browse.startpage.com/av/prox ... b0f227dec0
Reason for odd URL & JUST FYI: I can't access distrowatch when using the VPN unless I use Startpage's Anonymous View
Re: the secret of "man"
Posted: Tue Feb 27, 2024 12:00 pm
by DukeComposed
Greg Brannon wrote: Sun Feb 18, 2024 8:03 am
This is a great tip! I was struggling with 'man rsync' just yesterday and could have used this since the man pages are so long and detailed, yet unsearchable in a terminal session.
The '/' key starts a string search. Type the search string and press Enter.
trawglodyte wrote: Tue Feb 27, 2024 8:01 am
Somebody told me if I knew how to properly use a terminal I wouldn't have to open the man's in a browser to read, search, and scroll while I was figuring this out. lol, oh well. I'm happy for now!
Using the terminal is an art, kind of like calligraphy. It shouldn't be too upsetting not being great at using it these days for the same reason people aren't upset that they don't know how to churn butter or make their own powdered wigs, either. 40 years ago terminals were all there were and so things like pressing '/' to search or moving around with h, j, k, and l were necessary skills to have to function. I'm happier that you've shown me that man content can be piped to Firefox more than I'd be sad you weren't stuck in an 80x25 monochrome window.