I have read the date
command manual. There are many format controls like %a
, %b
, %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.
The first few lines of
man date
give:man
in Ubuntu usesless
, which has powerful searching features.You've clarified that you already had a command that ran
date
and included+
, and you were trying to figure out how that command worked and why the+
was needed.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.By default,
man
in Ubuntu usesless
as its pager. One way to learn aboutless
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 runningless --help
or just by pressing h anytime you're already inless
(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 thatless
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 intoRegex-off /
and you can type in text that will be matched literally.General Information About Searching in
less
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\
character.If you're typing in text to search for but you decide not to search after all, just press Esc.
Searches in
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 runless --help
or just press h anytimeless
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 inless
's help, too. Although the title is capitalized, that search will find it, because searching inless
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 alsoman
), as usual.