What i开发者_开发知识库s the command for printing the year, month, and date with a horizontal tab between the fields in unix? is the followin answer correct??
%date +"%y %m %d"
i know tat $ date +"%y-%m-%d" will give 88-05-21
If you use the bash shell:
$ date +"%y"$'\t'"%m"$'\t'"%d"
10 12 15
Note the $'\t'
shell notation which produces a literal horizontal tab character.
EDIT:
Many commands, such as printf(1)
support some kind of notation to specify any special characters like a horizontal tab:
$ printf 'x\ty\n'
x y
If the command does not support something like this, the way to deal with it is to embed a literal horizontal tab in the format string. Unfortunately the shell tends to treat the tab key specially e.g. to perform auto-completion.
In bash (and perhaps other sh-like shells) there is a convenient notation like $'\t'
to get around this issue.
Another way is to invoke the "quote mode" of the shell. In many shells (including bash and tcsh) this can be done by pressing Ctrl-V before pressing the special character. This will enable the shell's quote mode for the next character only:
$ echo 'x q'
x q
The result above can be achieved by pressing Ctrl-V after the x and before pressing the tab key.
To print the date with spaces in between all you need to do is: date "+%y %m %d"
. I highly recommend you check out the man page (man date
) for date
.
精彩评论