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.

  • 4
    Although this doesn't directly address what you're asking here, you should run just date +%s, not echo $(date +%s). You don't need command substitution when your goal is just to see the output of a command. – Eliah Kagan Dec 9 '17 at 14:44
  • That's right. It is my mistake cause I was doing "sudo rtcwake -m no -t $(date +%s -d 'tomorrow 08:00')". Then I need to ask the part of command that I don't understand. I was confused. I should have asked it as a complete question. – Smile Dec 9 '17 at 14:52
  • 3
    Possible duplicate of how to change default date output format in date command? – muru Dec 9 '17 at 16:01
  • 2
    The manual says ... date [OPTION]... [+FORMAT] In my eyes it is a + instruction. – Soren A Dec 9 '17 at 16:32
  • @Soren You are late. – Smile Dec 9 '17 at 23:45

The first few lines of man date give:

       date - print or set the system date and time

       date [OPTION]... [+FORMAT]
| improve this answer | |
  • This is embarrassing and scary. I feel like I'm gonna make this kind of mistake a lot. Is there anything else I should be aware for this kind?? Thanks. – Smile Dec 9 '17 at 13:24
  • 2
    SS64 Bash man page has more comments about each command. It's not a bad idea to search there. Even I get confused from time to time with bash parameters – Redbob Dec 9 '17 at 14:11
  • 1
    @Smile you can usually go to one of the last section of man pages, showing exemples – Olivier Dulac Dec 9 '17 at 14:13
  • @Redbob Is it more detailed version of ubuntu manuals?? – Smile Dec 9 '17 at 14:41
  • 2
    @Smile SS64 is usually less detailed than manpages; its goal is to give useful summaries. But it sometimes has more examples. For more details, you can go to the end of a manpage (Shift+G if you're reading it in a terminal) to see what provides it, and some have a SEE ALSO section too. The end of the date manpage shows "GNU coreutils 8.25" and its SEE ALSO section suggests running info '(coreutils) date invocation'. For GNU software like Coreutils you can also read the full docs online. – Eliah Kagan Dec 9 '17 at 14:54

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.

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 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 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 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.

| improve this answer | |
  • Thanks, this answer is very informative. I didn't recognize manpage is actually derived from less command. Now I'm kind of proficient with less for your help. Just one thing, though, I marked some part of man page, then I turned off my system. After coming back to the manpage, the mark is not there at all. What happened?? – Smile Dec 10 '17 at 0:45
  • 1
    @Smile "I didn't recognize manpage is actually derived from less command." Usually what people mean when they say one program is derived from another is that it incorporates source code from the other. That's not the case with man and less, which are quite different kinds of programs. man looks up and formats manpages, then uses a pager like less to show them. The reason it defaults to using less for that in Ubuntu is that the alternatives system has /usr/bin/pager pointing to /etc/alternatives/pager which points to /bin/less. – Eliah Kagan Dec 10 '17 at 4:36
  • 1
    @Smile "I marked some part of man page" I'm not sure I know what you mean. less has a feature called marking where you can type m and a letter, then later type ' and that letter to go back to the "mark." But those markings aren't related to anything I talked about here, and they don't cause text to be highlighted. The closest thing to "marking" that I described was less's behavior of highlighting text that matches your search terms. (I also described using Esc, then u, to turn off the highlighting.) Neither marks nor search result highlighting will persist after you quit less. – Eliah Kagan Dec 10 '17 at 4:47
  • Alright. That is pointing. Okay. I'm gonna make another question for marking. Thanks for detailed answers. :) – Smile Dec 10 '17 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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