Linux小推车Linux基础

Linux Day7: Date/echo/print

2018-10-08  本文已影响9人  泥人吴

学习man,结合date一起学习:

date:时间管理
linux:rtc

硬件时间(clock),系统时钟(date)
hwclock
-w:
-s:
我的用户好像显示不出clock时间。

获得命令的帮助:

  • 内部命令:help COMMAND
  • 外部命令:COMMAND --help
  • 命令手册:manual(man COMMAND)

man 分章节:
1.用户命令
2.系统调用
3.库用户
4.特殊软件(设备文件)
5.文件格式(配置文件的语法)
6.游戏
7.杂项
8.管理命令(/sbin,/usr/sbin,/usr/local/sbin)

基本上,man page 大致分成底下这几个部分:


man命令.鸟哥

举例:man time

DATE(1)                             User Commands                             DATE(1)

NAME
       date - print or set the system date and time

SYNOPSIS
       date [OPTION]... [+FORMAT]
       date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]

DESCRIPTION
       Display the current time in the given FORMAT, or set the system date.

       Mandatory arguments to long options are mandatory for short options too.

       -d, --date=STRING
              display time described by STRING, not 'now'

       -f, --file=DATEFILE
              like --date; once for each line of DATEFILE

       -I[FMT], --iso-8601[=FMT]
等等...

同more/less一样,man最后也有个光标供你翻页:


man 翻页.PNG

man page常用的按键有:


man 按键,鸟哥.PNG

那么上面synopsis:说明可以设置的时间格式
date一下目前的时间:

date
Sun Oct  7 17:41:41 CST 2018

如果想要修改时间,那么可以按照[MMDDhhmm[[CC]YY][.ss]]的格式修改时间。按照DESCRIPTION中介绍:

$ date +%y
18
$ date +%Y
2018
$ date +%Y/%m/%d
2018/10/07
$ date +%H:%M
18:18
$ date +%T
18:21:58
$ date +%F
2018-10-07

练习echo、printf命令:
1.echo命令是内部命令还是外部命令?

$ type echo
echo is a shell builtin
  1. 作用?
$ man echo
 echo - display a line of text

3.如何换行显示

$ echo -e "this year is 2018.\n today is 08"
this year is 2018.
 today is 08
$ echo -e "this year is 2018.\n today is 08"
this year is 2018.
 today is 08
$ echo -e "this year is 2018./b today is 08"
this year is 2018./b today is 08
$ echo -e "this year is 2018.\b today is 08"
this year is 2018 today is 08
$ echo -e "this year is 2018.\t today is 08"
this year is 2018.   today is 08
$ echo -e "this year is 2018.\v today is 08"
this year is 2018.
                   today is 08

printf:

man printf
NAME
       printf - format and print data
$ printf "The year is 2018"
The year is 2018

$ printf "The year is 2018.\n Today is 08"
The year is 2018.
 Today is 08$ 
上一篇下一篇

猜你喜欢

热点阅读