[root@hanfeng ~]# mkdir shell [root@hanfeng ~]# cd shell/ [root@hanfeng shell]#
[root@hanfeng shell]# vi 01.sh #! /bin/bash //固定格式 echo "123" w ls 保存退出
[root@hanfeng shell]# sh 01.sh 123 22:45:12 up 14 min, 1 user, load average: 0.00, 0.01, 0.05 USER TTY LOGIN@ IDLE JCPU PCPU WHAT root pts/0 22:32 0.00s 0.05s 0.03s w 01.sh [root@hanfeng shell]#
[root@hanfeng shell]# chmod a+x 01.sh [root@hanfeng shell]#
7執行shell腳本 ./01.sh 能這樣執行,說明這些命令被解析了,被/bin/bash認識了linux
[root@hanfeng shell]# ./01.sh 123 23:11:21 up 41 min, 1 user, load average: 0.00, 0.01, 0.05 USER TTY LOGIN@ IDLE JCPU PCPU WHAT root pts/0 22:32 1.00s 0.05s 0.00s /bin/bash ./01.sh 01.sh [root@hanfeng shell]#
[root@hanfeng shell]# ls -l /bin/bash -rwxr-xr-x. 1 root root 960368 6月 10 2014 /bin/bash [root@hanfeng shell]# ls -l /bin/sh lrwxrwxrwx. 1 root root 4 10月 21 00:47 /bin/sh -> bash [root@hanfeng shell]#
[root@hanfeng shell]# /bin/bash 01.sh 123 23:21:43 up 51 min, 1 user, load average: 0.00, 0.01, 0.05 USER TTY LOGIN@ IDLE JCPU PCPU WHAT root pts/0 22:32 7.00s 0.03s 0.00s w 01.sh [root@hanfeng shell]#
[root@hanfeng shell]# /root/shell/01.sh 123 23:45:02 up 1:14, 1 user, load average: 0.00, 0.01, 0.05 USER TTY LOGIN@ IDLE JCPU PCPU WHAT root pts/0 22:32 6.00s 0.03s 0.00s w 01.sh [root@hanfeng shell]#
[root@hanfeng shell]# sh -x 01.sh + echo 123 123 + w 23:47:35 up 1:17, 1 user, load average: 0.00, 0.01, 0.05 USER TTY LOGIN@ IDLE JCPU PCPU WHAT root pts/0 22:32 7.00s 0.03s 0.00s sh -x 01.sh + ls 01.sh [root@hanfeng shell]#
[root@hanfeng shell]# sh -n 01.sh [root@hanfeng shell]#
[root@hf-01 ~]# date 2018年 01月 14日 星期日 06:13:14 CST [root@hf-01 ~]#
[root@hf-01 ~]# LANG=en 切換爲英文顯示 [root@hf-01 ~]# date Sun Jan 14 06:19:49 CST 2018 [root@hf-01 ~]# date +%Y 2018 四位的年 [root@hf-01 ~]# date +%y 18 兩位的年 [root@hf-01 ~]# date +%m 01 月份 [root@hf-01 ~]# date +%M 20 分鐘 [root@hf-01 ~]# date +%d 14 日期 [root@hf-01 ~]# date +%D 01/14/18 直接標記年月日,不過格式比較特殊 [root@hf-01 ~]# date +%Y%m%d 20180114 年月日 [root@hf-01 ~]# date +%F 2018-01-14 年月日,這種帶橫槓的 [root@hf-01 ~]#
[root@hf-01 ~]# date +%w 0 表示周幾 [root@hf-01 ~]# date +%W 02 今年的第幾周,今年的第二週 [root@hf-01 ~]# date +%h Jan 英文的月份 [root@hf-01 ~]# date +%H 06 小時 [root@hf-01 ~]# date +%S 04 秒 [root@hf-01 ~]# date +%s 1515882702 這是一個時間戳,距離1970總共過去多少秒
[root@hf-01 ~]# date +%T 06:24:36 [root@hf-01 ~]# date +%H:%M:%S 06:24:36 [root@hf-01 ~]#
[root@hf-01 ~]# cal January 2018 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 [root@hf-01 ~]#
[root@hf-01 ~]# date -d "-1 day" Sat Jan 13 06:47:30 CST 2018 [root@hf-01 ~]# date -d "-1 day" +%F 2018-01-13 [root@hf-01 ~]# date -d "+1 month" +%F 2018-02-14 [root@hf-01 ~]# date -d "+1 year" +%F 2019-01-14 [root@hf-01 ~]# date -d "+1 hour" +%T 08:09:05 [root@hf-01 ~]# date -d "+1 min" +%T 07:11:21
[root@hf-01 ~]# date +%s 1515885248 [root@hf-01 ~]# date -d @1515885248 Sun Jan 14 07:14:08 CST 2018 [root@hf-01 ~]#
[root@hf-01 ~]# date +%s -d "2018-01-13 07:14:08" 1515798848 [root@hf-01 ~]# date -d @1515798848 Sat Jan 13 07:14:08 CST 2018 [root@hf-01 ~]#
wc -l 1.txt