做業:自行學習以下命令node
date, clock, hwclock, cal,ls, cd, pwd, tty, whereis, which,stat, echo, shutdown, halt, reboot, poweroff,who, w, whoamimysql
date: 顯示系統時間, 【時間日期】linux
date 查看系統當前時間 參數-u顯示utc時間sql
格式化顯示年月日 用+號連起來如:date +%Y-%m-%d(若是咱們用date +%Y - %m - %d 會發現出錯,由於系統看見空格後的- 會覺得是一個參數。shell
這時候咱們要用""連起來date +%Y" - "%m" - "%d )vim
經常使用參數註解 bash
-d,--date 網絡
顯示指定字符串所描述的時間,而非當前時間 dom
-f,--file=日期文件 ssh
相似--date,從日期文件中按行讀入時間描述
-r, --reference=文件
顯示文件指定文件的最後修改時間
-s, --set=字符串
設置指定字符串來分開時間
-u, --utc, --universal
輸出或者設置協調的通用時間
日期格式化字符串列表:
%H : 小時(00..23)
%I : 小時(01..12)
%k : 小時(0..23)
%l : 小時(1..12)
%M : 分鐘(00..59)
%p : 顯示本地 AM 或 PM
%r : 直接顯示時間 (12 小時制,格式爲 hh:mm:ss [AP]M)
%s : 從 1970 年 1 月 1 日 00:00:00 UTC 到目前爲止的秒數
%S : 秒(00..61)
%T : 直接顯示時間 (24 小時制)
%X : 至關於 %H:%M:%S
%Z : 顯示時區 %a : 星期幾 (Sun..Sat)
%A : 星期幾 (Sunday..Saturday)
%b : 月份 (Jan..Dec)
%B : 月份 (January..December)
%c : 直接顯示日期與時間
%d : 日 (01..31)
%D : 直接顯示日期 (mm/dd/yy)
%h : 同 %b
%j : 一年中的第幾天 (001..366)
%m : 月份 (01..12)
%U : 一年中的第幾周 (00..53) (以 Sunday 爲一週的第一天的情形)
%w : 一週中的第幾天 (0..6)
%W : 一年中的第幾周 (00..53) (以 Monday 爲一週的第一天的情形)
%x : 直接顯示日期 (mm/dd/yy)
%y : 年份的最後兩位數字 (00.99)
%Y : 完全年份 (0000..9999)
若是咱們想使用跟多格式化時間能夠用date --help來看到更多的參數顯示日期,不須要root權限
簡單實例:
Just type the date command:$ date
Sample outputs:
Wed Apr 23 10:32:59 CDT 2014 Linux Display The Hardware Clock (RTC)
格式化輸出:
date +"%Y-%m-%d"
2015-08-21
輸出昨天日期:
date -d "1 day ago" +"%Y-%m-%d"
2015-08-20
2秒後輸出: date -d "2 second" +"%Y-%m-%d %H:%M.%S"
2015-08-21 10:05.49
傳說中的 1234567890 秒:
date -d "1980-01-01 1234567890 seconds" +"%Y-%m-%d %H:%m:%S"
2019-02-13 23:02:30
普通轉格式:
date -d "2015-08-08" +"%Y/%m/%d %H:%M.%S"
2015/08/08 00:00.00
加減操做:
date +%Y%m%d //顯示當前年月日
20150821
date -d "+1 day" +%Y%m%d //顯示後一天的日期
20150822
date -d "-1 day" +%Y%m%d //顯示前一天的日期
20150820
date -d "-1 month" +%Y%m%d //顯示上一月的日期
20150721
date -d "+1 month" +%Y%m%d //顯示下一月的日期
20150921
date -d "-1 year" +%Y%m%d //顯示前一年的日期
20140821
date -d "+1 year" +%Y%m%d //顯示下一年的日期
20160821
【設置時間】
date -s "20131213" 設置日期
date -s "18:38:00" 設置時間
date -s //設置當前時間,只有root權限才能設置,其餘只能查看
date -s 20160823 //設置成20120523,這樣會把具體時間設置成空00:00:00
date -s 01:01:01 //設置具體時間,不會對日期作更改
date -s "01:01:01 2016-08-23" //這樣能夠設置所有時間
date -s "01:01:01 20150823" //這樣能夠設置所有時間
date -s "2015-08-21 01:01:01" //這樣能夠設置所有時間
date -s "20150821 01:01:01" //這樣能夠設置所有時間
Use the following syntax to set new data and time:
# date --set="STRING"
For example, set new data to 2 Oct 2006 18:00:00, type the following command as root user:
# date -s "2 OCT 2006 18:00:00"
OR
# date --set="2 OCT 2006 18:00:00"
You can also simplify format using following syntax:
# date +%Y%m%d -s "20081128"
Linux Set Time Examples
To set time use the following syntax:
# date +%T -s "10:13:13"
Where,
10: Hour (hh)
13: Minute (mm)
13: Second (ss)
Use %p locale's equivalent of either AM or PM, enter:
# date +%T%p -s "6:10:30AM"
# date +%T%p -s "12:10:30PM"
clock與hwclock命令
clock命令,與hwclock命令是同一個命令,主要用來查詢和設置硬件時鐘(query and set the hardware clock (RTC))。RTC=Real Time Clock,也就是硬件時鐘。
在Linux中有硬件時鐘與系統時鐘等兩種時鐘。
硬件時鐘是指主機板上的時鐘設備,也就是一般可在BIOS畫面設定的時鐘。
系統時鐘則是指kernel中的時鐘。
clock:顯示硬件時間,
hwclock : hwclock -w 把系統時間同步到硬件/ hwclock -s 把硬件時間同步到系統時間,
顯示時鐘時間
# hwclock -r
OR
# hwclock --show
OR show it in Coordinated Universal time (UTC):
# hwclock --show --utc
Sample outputs:
Wed 23 Apr 2014 10:36:23 AM CDT -0.157239 seconds
簡單查看clock幫助信息
[root@localhost ~]#clock help
hwclock - query and set the hardware clock (RTC) //第一行就說明了與hwclock是同一個命令
用法: hwclock [function] [options...]
經常使用的參數有如下:
-r, --show 讀取並打印硬件時鐘(read hardware clock and print result )
-s, --hctosys 將硬件時鐘同步到系統時鐘(set the system time from the hardware clock )
-w, --systohc 將系統時鐘同步到硬件時鐘(set the hardware clock to the current system time )
示例: 顯示硬件時鐘
[root@localhost ~]# hwclock
2015年08月21日 星期五 18時42分07秒 -0.986791 seconds
[root@localhost ~]# hwclock -r
2015年08月21日 星期五 18時42分29秒 -0.425118 seconds
[root@localhost ~]# hwclock --show
2015年08月21日 星期五 18時42分50秒 -0.376585 seconds
設置當前時間爲系統時間
How do I set the Hardware Clock to the current System Time?
Use the following syntax:
# hwclock --systohc
OR
# hwclock -w
注:系統時間準確,最好仍是使用ntp服務進行同步
示例:使用ntpdate命令從網絡同步時間,再同步到硬件時鐘
ntpdate命令是使用NTP協議來從網絡同步時間的命令
NTP=Network Time Protocol 網絡時間協議
[root@localhost ~]# ntpdate -u 202.112.10.36
21 Aug 11:01:14 ntpdate[2533]: step time server 202.112.10.36 offset -6690347.700246 sec
[root@localhost ~]# date /注:上面已經作了修改
2015年 08月 21日 星期五 11:01:18 CST
[root@localhost ~]# hwclock -w /系統時間同步到硬件時間
cal:顯示日曆
cal 查看日曆,命令行方式輸出
查看cal命令簡單幫助信息 [root@localhost ~]# man cal
用法:cal [參數][月份][年份]
經常使用參數:
-1 顯示一個月的月曆
-3 顯示系統前一個月,當前月,下一個月的月曆
-s 顯示星期天爲一個星期的第一天,默認的格式
-m 顯示星期一爲一個星期的第一天
示例
顯示當前月份日曆
[root@localhost ~]# cal
八月 2015
日 一 二 三 四 五 六
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@localhost ~]# cal 9 2015
九月 2015
日 一 二 三 四 五 六
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
顯示整年日曆
[root@localhost ~]# cal 2015
2015
一月 二月 三月
日 一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六
1 2 3 1 2 3 4 5 6 7 1 2 3 4 5 6 7
4 5 6 7 8 9 10 8 9 10 11 12 13 14 8 9 10 11 12 13 14
11 12 13 14 15 16 17 15 16 17 18 19 20 21 15 16 17 18 19 20 21
18 19 20 21 22 23 24 22 23 24 25 26 27 28 22 23 24 25 26 27 28
25 26 27 28 29 30 31 29 30 31
四月 五月 六月
日 一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六
1 2 3 4 1 2 1 2 3 4 5 6
5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13
12 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20
19 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27
26 27 28 29 30 24 25 26 27 28 29 30 28 29 30
31
七月 八月 九月
日 一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六
1 2 3 4 1 1 2 3 4 5
5 6 7 8 9 10 11 2 3 4 5 6 7 8 6 7 8 9 10 11 12
12 13 14 15 16 17 18 9 10 11 12 13 14 15 13 14 15 16 17 18 19
19 20 21 22 23 24 25 16 17 18 19 20 21 22 20 21 22 23 24 25 26
26 27 28 29 30 31 23 24 25 26 27 28 29 27 28 29 30
30 31
十月 十一月 十二月
日 一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六
1 2 3 1 2 3 4 5 6 7 1 2 3 4 5
4 5 6 7 8 9 10 8 9 10 11 12 13 14 6 7 8 9 10 11 12
11 12 13 14 15 16 17 15 16 17 18 19 20 21 13 14 15 16 17 18 19
18 19 20 21 22 23 24 22 23 24 25 26 27 28 20 21 22 23 24 25 26
25 26 27 28 29 30 31 29 30 27 28 29 30 31
uptime 查看系統啓動可多久,和系統的負載
ls: 文件屬性:
-:普通文件
d:目錄文件
b:塊設備
c:字符設備文件
l:符號鏈接文件
p:命令管道
s:套接字文件
文件權限:
9位數字,每3位一組
文件硬連接次數
文件所屬主(owner)
文件的屬組(group)
文件大小(size),單位默認是字節
經常使用選項:
-l:顯示文件屬性,ls -l=ll //除了文件名以外,還將文件的權限、全部者、文件大小等信息詳細列出來。
-h:作相應的單位轉換顯示
-a:–all //列出目錄下的全部文件,包括以 . 開頭的隱含文件顯示全部文件
-A:顯示.和..覺得的全部文件
-d:–directory 顯示目錄自身屬性 //將目錄象文件同樣顯示,而不是顯示其下的文件。
-i:顯示文件的縮影接點號碼(index node ,inode)
-r:–reverse 逆序顯示文件列//依相反次序排列
-R:遞歸顯示文件,
[root@localhost ~]# man ls
ls - list directory contents /列出目標目錄中全部的子目錄和文件
用法:[選項] [目錄名]
經常使用參數比較多,有以下:
-c //配合 -lt:根據 ctime 排序及顯示 ctime (文件狀態最後更改的時間)配合 -l:顯示 ctime 但根據名稱排序不然:根據 ctime 排序
-C //每欄由上至下列出項目
–color[=WHEN] //控制是否使用色彩分辨文件。WHEN 能夠是'never'、'always'或'auto'其中之一
-d,
-D, –dired //產生適合 Emacs 的 dired 模式使用的結果
-f //對輸出的文件不進行排序,-aU 選項生效,-lst 選項失效
-h, –human-readable //以容易理解的格式列出文件大小 (例如 1K 234M 2G)
-k 即 –block-size=1K //以 k 字節的形式表示文件的大小。
-L, –dereference //當顯示符號連接的文件信息時,顯示符號連接所指示的對象而並不是符號連接自己的信息
-m //全部項目以逗號分隔,並填滿整行行寬
-R, –recursive //同時列出全部子目錄層
-s, –size //以塊大小爲單位列出全部文件的大小
-S //根據文件大小排序
-t //以文件修改時間排序
-u //配合 -lt:顯示訪問時間並且依訪問時間排序;配合 -l:顯示訪問時間但根據名稱排序;不然:根據訪問時間排序
-U //不進行排序;依文件系統原有的次序列出項目
-v //根據版本進行排序
-w, –width=COLS //指定屏幕寬度而不使用目前的數值
-x //逐行列出項目而不是逐欄列出
-X //根據擴展名排序
-1 //每行只列出一個文件
示例:
列出/var/log文件夾下的全部文件和目錄的詳細資料
[root@localhost /]# ls -l -R /var/log
/var/log:
總用量 1860
-rw-------. 1 root root 2368 8月 20 22:03 anaconda.ifcfg.log
-rw-------. 1 root root 34407 8月 20 22:03 anaconda.log
-rw-------. 1 root root 42974 8月 20 22:03 anaconda.program.log
-rw-------. 1 root root 190963 8月 20 22:03 anaconda.storage.log
-rw-------. 1 root root 139257 8月 20 22:03 anaconda.syslog
-rw-------. 1 root root 33233 8月 20 22:03 anaconda.xlog
-rw-------. 1 root root 119307 8月 20 22:03 anaconda.yum.log
drwxr-x---. 2 root root 4096 8月 20 22:04 audit
-rw-r--r--. 2 root root 2603 8月 21 14:32 boot.log
-rw-------. 1 root utmp 0 8月 20 21:52 btmp
drwxr-xr-x. 2 root root 4096 8月 20 22:05 ConsoleKit
-rw-------. 1 root root 14254 8月 21 15:40 cron
drwxr-xr-x. 2 lp sys 4096 7月 24 19:09 cups
-rw-r--r--. 1 root root 86435 8月 21 14:32 dmesg
-rw-r--r--. 1 root root 86435 8月 21 13:32 dmesg.old
-rw-r--r--. 1 root root 227554 8月 20 22:02 dracut.log
drwxrwx--T. 2 root gdm 4096 8月 21 14:32 gdm
drwx------. 2 root root 4096 7月 24 19:53 httpd
-rw-r--r--. 1 root root 145708 8月 21 14:33 lastlog
-rw-------. 1 root root 1669 8月 21 14:32 maillog
-rw-------. 1 root root 643394 8月 21 14:32 messages
drwxr-xr-x. 2 ntp ntp 4096 7月 24 18:56 ntpstats
-rw-r--r--. 1 root root 89 8月 21 14:32 pm-powersave.log
drwx------. 2 root root 4096 3月 16 16:51 ppp
drwxr-xr-x. 2 root root 4096 8月 20 15:33 prelink
drwxr-xr-x. 2 root root 4096 11月 6 2015 sa
drwx------. 3 root root 4096 8月 20 21:53 samba
-rw-------. 1 root root 10342 8月 21 14:33 secure
-rw-------. 1 root root 0 8月 20 22:04 spice-vdagent.log
-rw-------. 1 root root 0 8月 20 21:55 spooler
drwxr-x---. 2 root root 4096 7月 24 19:45 sssd
-rw-------. 1 root root 0 8月 20 21:50 tallylog
-rw-r--r--. 1 root root 0 8月 20 22:04 wpa_supplicant.log
-rw-rw-r--. 1 root utmp 36864 8月 21 14:33 wtmp
-rw-r--r--. 1 root root 35687 8月 21 14:33 Xorg.0.log
-rw-r--r--. 1 root root 37708 8月 21 14:23 Xorg.0.log.old
-rw-r--r--. 1 root root 31347 8月 20 22:05 Xorg.9.log
-rw-------. 1 root root 0 8月 20 14:21 yum.log
/var/log/audit:
總用量 232
-rw-------. 1 root root 233257 8月 21 15:40 audit.log
/var/log/ConsoleKit:
總用量 8
-rw-r--r--. 1 root root 6387 8月 21 14:32 history
/var/log/cups:
總用量 0
/var/log/gdm:
總用量 200
-rw-r--r--. 1 gdm gdm 504 8月 21 14:32 :0-greeter.log
-rw-r--r--. 1 gdm gdm 998 8月 21 14:23 :0-greeter.log.1
-rw-r--r--. 1 gdm gdm 836 8月 21 11:53 :0-greeter.log.2
-rw-r--r--. 1 gdm gdm 836 8月 21 11:52 :0-greeter.log.3
-rw-r--r--. 1 gdm gdm 836 8月 20 14:16 :0-greeter.log.4
-rw-r--r--. 1 root root 27242 8月 21 14:33 :0.log
-rw-r--r--. 1 root root 28752 8月 21 14:23 :0.log.1
-rw-r--r--. 1 root root 38869 8月 21 13:32 :0.log.2
-rw-r--r--. 1 root root 28752 8月 21 11:52 :0.log.3
-rw-r--r--. 1 root root 36898 8月 20 16:32 :0.log.4
-rw-r--r--. 1 root root 0 8月 21 14:32 :0-slave.log
-rw-r--r--. 1 root root 0 8月 21 13:33 :0-slave.log.1
-rw-r--r--. 1 root root 31 8月 21 11:53 :0-slave.log.2
-rw-r--r--. 1 root root 0 8月 21 10:01 :0-slave.log.3
-rw-r--r--. 1 root root 31 8月 20 14:16 :0-slave.log.4
/var/log/httpd:
總用量 0
/var/log/ntpstats:
總用量 0
/var/log/ppp:
總用量 0
/var/log/prelink:
總用量 56
-rw-r--r--. 1 root root 56381 8月 21 12:35 prelink.log
/var/log/sa:
總用量 168
-rw-r--r--. 1 root root 2460 11月 6 2015 sa06
-rw-r--r--. 1 root root 92904 8月 20 22:00 sa20
-rw-r--r--. 1 root root 62772 8月 21 15:40 sa21
/var/log/samba:
總用量 4
drwx------. 2 root root 4096 7月 24 11:16 old
/var/log/samba/old:
總用量 0
/var/log/sssd:
總用量 0
示例:列出當前/目錄中全部以「t」開頭的目錄的詳細內容
[root@localhost /]# ls -l t*
總用量 32
drwx------. 2 root root 4096 8月 20 22:05 keyring-8nQEth
drwx------. 2 root root 4096 8月 20 14:16 keyring-SDqtwB
drwx------. 2 gdm gdm 4096 8月 21 14:32 orbit-gdm
drwx------. 2 gdm gdm 4096 8月 21 14:32 pulse-8WdjQ60VOcZx
drwx------. 2 root root 4096 8月 21 11:53 pulse-hI8dPZuR8vK7
drwx------. 2 root root 4096 8月 20 14:16 virtual-root.ErfcRn
drwx------. 2 root root 4096 8月 21 11:53 virtual-root.Kt3kb3
drwx------. 2 root root 4096 8月 20 22:06 virtual-root.qpXn8K
-rw-------. 1 root root 0 8月 20 21:48 yum.log
示例:列出目前/var/log全部名稱是s 開頭的檔案,愈新的排愈後面
[root@localhost log]# ls -ltr s*
-rw-------. 1 root root 0 8月 20 21:55 spooler
-rw-------. 1 root root 0 8月 20 22:04 spice-vdagent.log
-rw-------. 1 root root 10342 8月 21 14:33 secure
sssd:
總用量 0
samba:
總用量 4
drwx------. 2 root root 4096 7月 24 11:16 old
sa:
總用量 168
-rw-r--r--. 1 root root 92904 8月 20 22:00 sa20
-rw-r--r--. 1 root root 64776 8月 21 15:50 sa21
-rw-r--r--. 1 root root 2460 11月 6 2015 sa06
示例:顯示當前目錄下隱藏文件
[root@localhost ~]# ls -a
. anaconda-ks.cfg .bash_logout .bashrc install.log .mysql_history satools .tcshrc .vimrc .. .bash_history .bash_profile .cshrc install.log.syslog .rnd .ssh .viminfo
示例:水平輸出文件列表
[root@localhost /]# ls -m
bin, boot, data, dev, etc, home, lib, lost+found, media, misc, mnt, opt, proc, root, sbin, selinux, srv, sys, tmp, usr, var
示例:顯示文件夾信息
[root@localhost /]# ls -ld /etc/
drwxr-xr-x. 116 root root 12288 8月 21 14:32 /etc/
cd:change directory
cd:回到用戶的家目錄
cd ~username:進入指定用戶的家目錄
cd - :在當前目錄和前一次所在的目錄來回切換
cd ..:切換至其父目錄,
[root@localhost ~]# man cd
用戶:cd [目錄名] //切換目錄
經常使用參數選項
-p 若是要切換到的目標目錄是一個符號鏈接,直接切換到符號鏈接指向的目標目錄
-L 若是要切換的目標目錄是一個符號的鏈接,直接切換到字符鏈接名錶明的目錄,而非符號鏈接所指向的目標目錄
cd命令有一些比較靈活的使用技巧,經常使用的以下:
cd 進入用戶主目錄
cd ~ 進入用戶主目錄
cd - 返回進入此目錄以前所在的目錄
cd .. 返回上級目錄(若當前目錄爲「/「,則執行完後還在「/";".."爲上級目錄的意思)
cd ../.. 返回上兩級目錄
cd !$ 把上個命令的參數做爲cd參數使用
pwd:--print name of current/working directory //顯示用戶當前工做目錄
pwd命令 // printenv 顯示當前環境變量
簡單查看pwd命令幫助文檔
[root@localhost ~]# man cd
pwd--print name of current/working directory //顯示用戶當前工做目錄
用法:pwd [目錄名]
示例:顯示當前用戶工做路徑
[root@localhost ~]# pwd
/root
tty:tty - print the file name of the terminal connected to standard input //顯示終端機鏈接標準輸入設備的文件名稱
用法:tty [OPTION]...
經常使用選項參數
-s或--silent或--quiet //不顯示任何信息,只回傳狀態代碼
示例:顯示終端輸入的設備名稱
[root@localhost ~]# tty
/dev/pts/0
whereis:
簡單查看whereis命令幫助信息
[root@localhost ~]# man whereis
whereis - locate the binary, source, and manual page files for a command //搜索、查找二進制、源文件
用法:whereis [選項][參數]文件
經常使用選項參數:
-b:只查找二進制文件
-B<目錄>:只在設置的目錄下查找二進制文件
-f:不顯示文件名前的路徑名稱
-m:只查找說明文件
-M<目錄>:只在設置的目錄下查找說明文件
-s:只查找原始代碼文件
-S<目錄>只在設置的目錄下查找原始代碼文件
-u:查找不包含指定類型的文件
示例:查找passwd相關文件
[root@localhost ~]# whereis passwd
passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man5/passwd.5.gz /usr/share/man/man1/passwd.1.gz
以二進制文件查找/etc/passwd
[root@localhost ~]# whereis -b /etc/passwd
passwd: /usr/bin/passwd /etc/passwd
[root@localhost ~]# whereis -m /etc/passwd
passwd: /usr/share/man/man5/passwd.5.gz /usr/share/man/man1/passwd.1.gz
[root@localhost ~]# whereis -s /etc/passwd
passwd:
which:
簡單查看which命令幫助信息
[root@localhost ~]# man which
which - shows the full path of (shell) commands //查找並顯示給定命令的絕對路徑
用法:which [選項] [參數] 文件
經常使用參數:
-n<文件名長度>:制定文件名長度,指定的長度必須大於或等於全部文件中最長的文件名
-p<文件名長度>:與-n參數相同,但此處的<文件名長度>包含了文件的路徑
示例:查找文件、顯示命令路徑
[root@localhost ~]# which pwd
/bin/pwd
[root@localhost ~]# which passwd
/usr/bin/passwd
stat:
查看stat命令幫助文檔信息
[root@localhost ~]# man stat
stat - display file or file system status
用法:stat[選項][參數]
經常使用的選項參數
-L:支持符號鏈接
-f:顯示文件系統狀態而非文件狀態
-t:以簡潔方式輸出信息
示例:
顯示var文件系統
[root@localhost /]# stat -f var
File: "var"
ID: 24776601f298d4cb Namelen: 255 Type: ext2/ext3
Block size: 4096 Fundamental block size: 4096
Blocks: Total: 7021609 Free: 6883938 Available: 6525590
Inodes: Total: 1794048 Free: 1783601
以簡潔方式輸出信息var文件
[root@localhost /]# stat -t var
var 4096 8 41ed 0 0 fd00 1179649 22 0 0 1440075283 1440079190 1440079190 4096
echo: 輸出信息
echo "abc"
echo "字符串" | passwd --stdin USERNAME:利用管道修改用戶密碼
Linux命令之echo
- 顯示文本、打印信息
簡單查看echo命令幫助信息
[root@localhost ~]# man echo
echo - display a line of text //打印信息
經常使用參數
-n 打印信息以後不換行。
-e 對字符串轉義。
示例:
打印當前PATH設置信息
[root@localhost ~]# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
輸出信息字符進行轉義
[root@localhost ~]# echo -e 'hello\n51CTO'
hello
51CTO
shutdown: [-akrhHPfnc] [-t secs] time [warning message]
shutdown:關機的命令
-r now:當即重啓
-t sec:幾秒以後
-h now:當即關機,
簡單查看shutdown幫助信息
[root@localhost ~]# man shutdown
shutdown - bring the system down //關閉系統
用法:shutdown [-dfinw]
經常使用參數:
-k: 不真正關機,只是向系統中的登陸用戶發出警告信息
-f:重啓系統時不執行文件系統檢查指令(fsck)
-F:重啓系統時執行fsck
-h:關機後不重啓,halt、poweroff
-r: 從新啓動系統
-n: 不調用init程序,有shutdown完成全部的關機操做。(不推薦)
-t: 關機操做延遲的秒數
-c:用戶取消正在執行的shutdown操做,如設置延遲1000秒關機
注意:shutdown在系統關機或重啓前,能夠向全部的登陸用戶發送通知,新的登陸指令會被禁止,還能夠指定關機時間。
shutdown –h HH:MM 警告信息
shutdown指令經過向init程序發送SIGTERM(終止軟件、進程)信號,而後發送kill信號,init改變系統的運行級別來完成相關操做。
示例:
當即關機
[root@localhost ~]# shutdown -n
設置1分鐘之後關閉計算機,並提示「1 minute after shutdown」
[root@localhost ~]# shutdown -h +1 "1 minute after shutdown"
Broadcast message from root@localhost.localdomain
(/dev/pts/4) at 14:22 ...
The system is going down for halt in 1 minute!
1 minute after shutdown
取消關機
[root@localhost ~]# shutdown -c
halt, poweroff命令
簡單查看halt、poweroff命令幫助信息
[root@localhost ~]# man halt
或
[root@localhost ~]# man poweroff
reboot or stop the system //重啓或者關機
用法:halt [選項]...
或 poweroff [選項]...
常見參數都有如下:
-w:不關閉OS,僅在wtmp(登陸和退出紀錄)中添加相應記錄。
-f:強制關閉系統。
-p:關閉OS而且切斷電源,即調用poweroff。
示例:
強制關機
[root@localhost ~]# halt -f
或
[root@localhost ~]# poweroff -f
reboot:
簡單查看reboot命令幫助信息
[root@localhost ~]# man reboot
reboot or stop the system //重啓或者關機
用法:reboot [-dfinw]
常見參數:
-n:重啓系統,不執行sync,不寫/var/log/wtmp
-w:不重啓,僅在/var/log/wtmp中添加相應記錄
-d:重啓系統,不寫/var/log/wtmp
-f:強制重啓,不調用shutdown
-i:重啓前,關閉全部網絡接口,能夠保證系統重啓過程當中不會有網絡用戶登陸系統。
示例
強制關機
[root@localhost ~]# reboot -f
who: 命令
簡單顯示who幫助信息
[root@localhost ~]# who --help
用法:who [選項]... [ 文件 | 參數1 參數2 ]
顯示當前已登陸的用戶信息。
常見的參數以下:
-b, --boot 上次系統啓動時間
-l,--login 顯示系統登陸進程
--lookup 嘗試經過 DNS 查驗主機名
-q, --count 列出全部已登陸用戶的登陸名與用戶數量
-u, --users 列出已登陸的用戶
示例:
顯示上次系統引導時間
[root@localhost ~]# who -b
系統引導 2015-08-21 18:01
顯示系統登陸進程
[root@localhost ~]# who -l
登陸 tty3 2015-08-21 10:01 2144 id=3
登陸 tty2 2015-08-21 10:01 2142 id=2
登陸 tty5 2015-08-21 10:01 2148 id=5
登陸 tty4 2015-08-21 10:01 2146 id=4
登陸 tty6 2015-08-21 10:01 2150 id=6
顯示已登陸用戶以及次數
[root@localhost ~]# who -q
root root root root root
# 用戶數=5
w:命令
簡單顯示who幫助信息
[root@localhost ~]# man w
w - Show who is logged on and what they are doing. //顯示目前登入系統的用戶信息。
用法:w [-fhlsuV][用戶名稱]
常見參數:
-f 開啓或關閉顯示用戶從何處登入系統。
-h 不顯示各欄位的標題信息列。
-s 使用簡潔格式列表,不顯示用戶登入時間,終端機階段做業和程序所耗費的CPU時間。
示例:
顯示root用戶登入系統信息
[root@localhost ~]# w -f root
11:40:45 up 1:39, 5 users, load average: 0.00, 0.00, 0.00
USER TTY LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 10:06 1:32m 0.06s 0.06s -bash
root pts/1 10:08 1:30m 0.07s 0.07s -bash
root pts/2 10:10 1:27m 0.07s 0.07s -bash
root pts/3 10:13 31:39 0.16s 0.01s man cal
root pts/4 11:13 0.00s 0.10s 0.01s w -f root
whoami:命令
簡單顯示who幫助信息
[root@localhost ~]# man w
whoami - print effective userid:顯示用戶名稱。
用法:whoami [OPTION]...
該命令比較簡單,示例
[root@localhost ~]# whoami
root