Date
“日期”命令中的“+”有什麼作用?
以下給了我一個日期:
$ date +%Y%m%d 20201012
這不會:
$ date %Y%m%d date: invalid date ‘%Y%m%d’
手冊頁說
+
前面有FORMAT
.+
除了正確的語法之外還有什麼重要性?date [OPTION]... [+FORMAT]
來自
info date
:If given an argument that starts with a ‘+’, ‘date’ prints the current date and time (or the date and time specified by the ‘--date’ option, see below) in the format defined by that argument, which is similar to that of the ‘strftime’ function. Except for conversion specifiers, which start with ‘%’, characters in the format string are printed unchanged. The conversion specifiers are described below.
例如,您可以這樣做:
date +"The year is %Y" The year is 2020
+
引入了日期格式字元串。