I have read the
date command manual. There are many format controls like
%c, and so on. After reading through the manual I did
echo $(date %s) to know the absolute time. It was not correct form.
echo $(date +%s) is the correct one. This might be a stupid question, but how do people know there should be the
+ before the
%s parameter?? In the manual there is no
+ instruction at all. Thanks for reading.
I have read the
The first few lines of
man date give:
NAME date - print or set the system date and time SYNOPSIS date [OPTION]... [+FORMAT]
TL;DR: When you don't see what you're looking for in a manpage, you can try searching its contents. Normally you search by pressing /, typing your search term, and pressing Enter. Some punctuation characters are treated specially, though, including
+. To search for those, you can escape each with a backslash (
\+) or you can instead press Ctrl+r after /. If you press h while viewing a manpage, you get interactive help that includes information on searching.
man in Ubuntu uses
less, which has powerful searching features.
When you're looking in a manual page for how something you've seen works, and you don't notice anything for it, you can search inside the manual page for it. Having not initially seen the
+, searching would have revealed it. Although it appeared near the top, it was somewhat difficult to see because it appeared inside
] and next to other text. I have personally often missed things in manpages that were even more prominent than that, but found them by searching ahead with /. Usually searching a manpage is very easy, but searching for characters like
+ is slightly more complicated.
man in Ubuntu uses
less as its pager. One way to learn about
less is to read its own manpage, but ironically its manpage is quite long and complicated. I recommend instead using its built-in help, which you can access by running
less --help or just by pressing h anytime you're already in
less (including while viewing any manpage).
To search for text in
less, press /. Normally you can just type the text in that you want to find and press Enter. However, this text is actually a regular expression, so characters that have special meaning in regular expressions--like
+--do not automatically stand for themselves.
One way to search in less (including in manpages) for text that contains regular expression metacharacters like
+ is to escape each one with a backslash before it. That is, after pressing /, you would type
\+ instead of just
+, and press Enter. If you needed to search for
++, then you would type
Another way is to tell
less not to interpret your search pattern as a regular expression. This works for most text, including
+. (It will only fail if you type something that
less interprets as telling it to do something, rather than as part of the search pattern.) To do this, after pressing /, press Ctrl+R. The
/ displayed at the bottom of the terminal will turn into
Regex-off / and you can type in text that will be matched literally.
General Information About Searching in
Normally you don't have to type
\ or press Ctrl+r. Normally all you have to do is press / and enter your search term. It is only when your search term contains regex metacharacters that you don't want interpreted as such, that you have to do more. Note also that if you do use Ctrl+r, then
\ itself will no longer have its special meaning as the character that removes special meaning from the next character. So if you use Ctrl+r then you should not also type
\ unless you are actually searching for a
If you're typing in text to search for but you decide not to search after all, just press Esc.
less are case-insensitive by default. You get the first match at or below your current position when you search. To move down to another match, press n. To move up to another match, press Shift+n. If you know you want to search backward in the first place, you can use ? (which is Shift+/ in some keyboard layouts) instead of /.
All matches are highlighted by default. Sometimes this makes reading difficult, so you may want to tell
less to turn off the highlighting once you've found what you need. To do that, press Esc followed immediately by u.
I recommend reading the section in
less's help about searching. After you run
less --help or just press h anytime
less is running, you can scroll down a couple pages to the section called SEARCHING. Or you can search for it! If you type
/searching and press Enter, that will bring you to it, since searching works in
less's help, too. Although the title is capitalized, that search will find it, because searching in
less is case-insensitive.
It is handy to be able to refer back to that section while reading a manpage. I sometimes do this, when I need to use search features I don't regularly use. If you press h while reading a manpage, you can read about the search features you need, then press q, which brings you back to the manpage. Pressing q again quits
less (and thus also
man), as usual.