- 顯示日期與時鐘
[root@centos6 ~]# date #查看日期
Mon Jul 17 19:38:37 CST 2017
[root@centos6 ~]# clock #查看硬件時間
Mon 17 Jul 2017 07:39:04 PM CST -0.097558 seconds
[root@centos6 ~]#
[root@centos6 ~]# hwclock #查看硬件時間
Mon 17 Jul 2017 07:39:09 PM CST -0.595049 seconds
[root@centos6 ~]# date
Mon Jul 17 19:39:20 CST 2017
- 校準(zhǔn)時間
[root@centos6 ~]# clock -w #以系統(tǒng)時間為準(zhǔn)修改硬件時間
[root@centos6 ~]# clock -s #以硬件時間為準(zhǔn)修改系統(tǒng)時間
- 顯示Linux的日歷
[root@centos6 ~]# cal #顯示當(dāng)前月份的日歷
[root@centos6 ~]# cal 1995 #顯示指定的日歷
- 關(guān)機(jī)命令
- 關(guān)機(jī)
[root@centos6 ~]# halt #關(guān)機(jī)
[root@centos6 ~]# poweroff #關(guān)機(jī)并切斷電源
[root@centos6 ~]# shutdown -r # -r重啟 -h關(guān)機(jī)
[root@centos6 ~]# -h
[root@centos6 ~]# shutdown -r +1 # +1表示在一分鐘之后執(zhí)行重啟
Broadcast message from root@centos6.aubin.com
(/dev/pts/1) at 20:10 ...
The system is going down for reboot in 1 minute!
^C #當(dāng)前用戶按Ctrl+c取消重啟計(jì)劃
shutdown: Shutdown cancelled
- 指定具體的關(guān)機(jī)或者重啟時間
[root@centos6 ~]# shutdown -h 22:00
[root@centos6 ~]# shutdown -r 0718 22:00 #7月18號22:00重啟
[root@centos6 ~]# shutdown -r 180718 22:00 #18年7月18號重啟
- 2分鐘后關(guān)機(jī),并發(fā)送消息"will halt"給所有用戶
[root@centos6 ~]# shutdown -h +2 "will halt"
- 取消shutdown計(jì)劃
[root@centos6 ~]# shutdown -c
CentOS6與CentOS7的區(qū)別
#
[root@centos6 ~]# shutdown -r +1 "will halt" #CentOS6需要指定時間
#
[root@centos6 ~]# shutdown -r "will halt" #CentOS7默認(rèn)一分鐘
- 用戶登錄信息的查看
[root@centos6 ~]# who #查看用戶登錄信息
[root@centos6 ~]# w #查看詳細(xì)的登錄信息以及執(zhí)行的命令
[root@centos6 ~]# whoami #查看當(dāng)前的用戶名
[root@centos6 ~]# who am i #查看當(dāng)前登錄信息
#
#
[root@centos6 ~]# who
root tty1 2017-07-17 19:37 (:0)
root pts/0 2017-07-17 19:38 (:0.0)
root pts/1 2017-07-17 19:38 (192.168.0.1)
[root@centos6 ~]# whoami
root
[root@centos6 ~]# who am i
root pts/1 2017-07-17 19:38 (192.168.0.1)
[root@centos6 ~]# w
20:42:31 up 1:13, 3 users, load average: 1.12, 0.83, 0.39
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 :0.0 19:38 1:04m 0.05s 0.05s /bin/bash
root pts/1 192.168.0.1 19:38 1.00s 0.90s 0.53s w
- screen會話
- screen會話是獨(dú)立運(yùn)行的拦坠,只要沒有終止都是可以恢復(fù)的连躏。即使在遠(yuǎn)程時網(wǎng)絡(luò)連接中斷screen會話依然繼續(xù)運(yùn)行。
適用于長時間的遠(yuǎn)程操作贞滨,這樣不用擔(dān)心中途網(wǎng)絡(luò)問題而造成工作中斷入热。
安裝screen
[root@centos6 Packages]# rpm -ivh screen-4.0.3-19.el6.x86_64.rpm
- 創(chuàng)建一個screen
[root@centos6 ~]# screen -S aubin # -S為大寫
- 加入一個screen會話
[root@centos6 ~]# screen -x aubin
- 列出所有會話
[root@centos6 ~]# screen -ls
- 退出并關(guān)閉會話,關(guān)閉后強(qiáng)制已連接用戶退出會話
[root@centos6 ~]# exit
- 剝離會話-----剝離會話不是退出晓铆,進(jìn)程將繼續(xù)運(yùn)行
Ctrl+a, #先按Ctrl+a勺良,再按B
- 恢復(fù)會話
-------當(dāng)會話沒有用戶時screen -x aubin
恢復(fù)會話
-------當(dāng)會話中有用戶時使用screen -x
加入會話
[root@centos6 ~]# screen -x aubin
- 更新Linux時間
[root@centos6 ~]# netdate 223.6.6.6
- 命令替換之反單引號的使用
反單引號的作用與$()
的作用相同 - echo命令
echo默認(rèn)"為雙引號
" 雙引號識別變量,不識別命令
' 單引號不識別變量骄噪,不識別命令
` 反單引號識別變量郑气,識別命令
[root@centos6 ~]# echo echo $UID
echo 0
[root@centos6 ~]# echo "echo $UID"
echo 0
[root@centos6 ~]# echo 'echo $UID'
echo $UID
[root@centos6 ~]# echo `echo $UID`
0
echo [-neE] [字符串]
-e 啟用 \ 字符的解釋功(啟用轉(zhuǎn)義字符)
-E (默認(rèn))不支持 \ 解釋功能
-n 不自動換行
↓字符串
\a 發(fā)出警告聲
\b 退格鍵
\c 最后不加上換行符號
\n 換行且光標(biāo)移至行首
\r 回車,即光標(biāo)移至行首腰池,但不換行
\t 插入tab
\\ 插入\字符
\0nnn 插入nnn(八進(jìn)制)所代表的ASCII字符
echo -e '\033[43;31;5mmagedu\033[0m'
\xHH插入HH(十六進(jìn)制)所代表的ASCII字
- bc計(jì)算器
計(jì)算器默認(rèn)輸入尾组、輸出都為10進(jìn)制
[root@centos6 ~]# bc #打開計(jì)算器
bc 1.06.95
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
obase=16 #設(shè)置輸出為16進(jìn)制
ibase=2 #設(shè)置輸入為2進(jìn)制
11111111100001111 #輸入一個2進(jìn)制數(shù)
1FF0F #計(jì)算器返回16進(jìn)制數(shù)
- 命令行的擴(kuò)展
- 創(chuàng)建1-10的log文件
[root@centos6 test]# touch {1..10}.log
[root@centos6 test]# ls
10.log 1.log 2.log 3.log 4.log 5.log 6.log 7.log 8.log 9.log
- 輸出a-z
[root@centos6 test]# echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z
- 輸出從000到100的等差以.log結(jié)尾
[root@centos6 test]# echo {000..100..3}.log
000.log 003.log 006.log 009.log 012.log 015.log 018.log 021.log 024.log
027.log 030.log 033.log 036.log 039.log 042.log 045.log 048.log 051.log
054.log 057.log 060.log 063.log 066.log 069.log 072.log 075.log 078.log
081.log 084.log 087.log 090.log 093.log 096.log 099.log
- 創(chuàng)建一批1-5的log、txt文件
[root@centos6 /]# mkdir {1..5}.{log,txt}
[root@centos6 /]# rm -r {1..5}.{log,txt}
[root@centos6 /]# getent passwd