Linux的基本原則:
1、由目的單一的小程序組成:組合小程序完成複雜任務
2、一切皆文件
3、儘量避免捕獲用戶接口
4、配置文件保存爲純文本格式
GUI接口:
雙擊鼠標
CLI接口:
命令提示符,prompt,bash(shell)
#:root
$:普通用戶
命令:命令會被shell送給內核,又內核判斷是否具有執行權限以及能否執行,從什麼地方開始執行。
[root@Smoke ~]# lss(通過shell返回的錯誤信息)
-bash: lss: command not found
命令格式:
命令 選項 參數
選項:修改命令的執行方式,選項可以有多個
短選項:一個橫槓"-"引導跟一個字符,-character,多個選項彼此可以組合。
例如:-a -b = -ab
長選項:兩個橫線"--"引導跟一個單詞,--word,長選項通常不能組合,必須要分開來寫。
參數:命令的作用對象,這個命令對誰生效,可以跟多個參數,多個參數彼此用空格隔開。
[root@Smoke ~]# ls(不帶選項)
anaconda-ks.cfg pam_mysql-0.7-0.12.rc1.el6.x86_64.rpm
cacti-0.8.8b.tar.gz Pictures
[root@Smoke ~]# ls -l(-l選項詳細信息)
總用量 310680
-rw-------. 1 root root 1394 4月 14 08:38 anaconda-ks.cfg
-rw-r--r-- 1 root root 2272130 5月 14 20:14 cacti-0.8.8b.tar.gz
drwxr-xr-x. 2 root root 4096 4月 15 21:27 Desktop
drwxr-xr-x. 2 root root 4096 4月 15 21:27 Documents
[root@Smoke ~]# ls -a(-a查看全部)
. .gnote Pictures
.. .gnupg Public
.abrt .gstreamer-0.10 .pulse
anaconda-ks.cfg .gtk-bookmarks .pulse-cookie
[root@Smoke ~]# ls -a -l(多個選項,-a顯示所有,-l詳細信息)
總用量 310848
dr-xr-x---. 31 root root 4096 5月 31 23:30 .
dr-xr-xr-x. 26 root root 4096 5月 21 20:43 ..
drwxr-xr-x. 3 root root 4096 4月 15 21:55 .abrt
-rw-------. 1 root root 1394 4月 14 08:38 anaconda-ks.cfg
[root@Smoke ~]# ls -al(多個選項組合使用)
總用量 310848
dr-xr-x---. 31 root root 4096 5月 31 23:30 .
dr-xr-xr-x. 26 root root 4096 5月 21 20:43 ..
drwxr-xr-x. 3 root root 4096 4月 15 21:55 .abrt
-rw-------. 1 root root 1394 4月 14 08:38 anaconda-ks.cfg
[root@Smoke ~]# ls /etc/(命令加參數,不帶參數顯示當前目錄)
abrt enscript.cfg ld.so.cache pinforc
[root@Smoke ~]# ls /root /var(命令跟多個參數使用)
/root:
anaconda-ks.cfg pam_mysql-0.7-0.12.rc1.el6.x86_64.rpm
cacti-0.8.8b.tar.gz Pictures
/var:
account crash db ftp
如何實現用戶登錄和切換:
使用憑證:驗證使用者身份。
Linux嚴格區分大小寫。
Smoke login:root(沒登陸時,登錄提示符)
Password:
[root@Smoke ~]#(命令提示符)
虛擬終端(terminal):
CTRL+ALT+F1-F6:默認6個終端。
[root@Smoke ~]# startx &(啓動圖形界面,&表示程序在後臺運行)
圖形終端:CTRL+ALT+F7
模擬終端:在圖形界面想執行命令點擊鼠標"右鍵"選擇"Open Terminal"可以打開一個終端。
或者通過菜單欄選擇"Applications"-->"Accessonries"-->"Terminal"打開模擬終端。
GUI類型:
1、Gnome:C開發
2、KDE:C++開發
3、Xface:簡介輕量式嵌入式桌面
CLI:讓用戶通過輸入命令,將命令結果取回到當前屏幕上來的一個用戶接口,或人機交互接口。
sh1、bash:用的最廣泛,功能最強大開源shell
2、csh
3、zsh
4、ksh
5、tcsh
只要跟shell相關的程序,只要shell關了,程序也會關閉。
切換用戶:
假如:裝完系統有三個用戶root,student,vistor怎麼完成用戶切換。
su:Switch User切換用戶。# su [-l] 用戶名:中括號[]表示可省略,
Linux另一個哲學思想能簡寫決不全寫。
[root@Smoke ~]# su student(切換到student用戶,半切換,有root)
[student@Smoke root]$ exit(退回原來的位置)
exit
[root@Smoke ~]# su -l student(切換到student用戶,-l完全切換,沒有root)
[student@Smoke ~]$
[student@Smoke ~]$ exit(退出用戶)
logout
更換密碼:# passwd:用於修改當前用戶密碼,對於管理員可以隨意改成其他密碼,對於普通用戶默認策略必須要符合密碼複雜性規則。
密碼複雜性規則:
1、使用4種類別字符中至少3種;
2、足夠長,大於7位;
3、使用隨機字符串;
4、要定義更換;
5、循環週期要足夠大;
[root@Smoke ~]# passwd(更改當前用戶密碼)
Changing password for user root.
New password:
BAD PASSWORD: it is based on a dictionary word
Retype new password:
passwd: all authentication tokens updated successfully.
Shelll:
GUI:Graphic User Interface圖形用戶界面
Windows:windows在2008之前桌面直接內置在內核中的,不用桌面就無法使用winodws。
X-Window:X指它的協議,圖形顯示協議,超級的意思,Linux的桌面僅僅是一個外圍軟件而已,X-Windows是C/S架構的,當前主機裝的是系統,另外一臺顯示器拿來做顯示圖形界面也完全是可以的,主機和顯示器完全是可以分離的,只不過顯示那端叫Server,請求顯示那端叫Client。
1、Gnome
2、KDE
3、Xface
CLI:Command Line Interface命令行接口
1、sh
2、bash
3、csh
4、ksh
5、zsh
6、tcsh
操作系統組成結構:
最底層是硬件,硬件資源是獨有的,在單顆CPU系統平臺上,爲了能夠實現在同一個計算機上同時近似的運行多個程序,有了通用管理軟件叫Kernel(內核),內核只是個平臺,它不提供特定的任務,僅僅將硬件所提供的計算能力抽象出來並提供給上層其他軟件,只不過它的提供方式叫做System call(系統調用),系統調用過於底層,所以使得程序員開發程序非常麻煩的,因此就有了庫,庫就是將一個或多個系統調用的功能封裝起來做成更高級的調用接口,庫是一個可執行程序,但是它卻無法獨立執行,必須被調用以後才能執行,在庫的上面就是各種應用程序,這些應用程序根據自己的需要是各種各樣的,比如shell是獨特的用戶界面,也有可能是web服務器,也有可能是IDE(開發環境)。
IDE:程序員在開發的時候所用到的開發環境。
Winodws系統的windows目錄很多的.dll文件就是windows的動態連接庫文件。
DLL:Dynamic Link Library動態鏈接庫。
Linux系統上的庫文件是.so結尾叫共享對象。
so:shared object共享對象。
dso:Dynamic shared object動態共享對象。
做一個操作系統:
需要提供一個內核,提供一些庫,或提供運行軟件,根據軟件依賴那些庫,將這些庫也提供好,還需要提供一個shell。
一個linux可以做成2-3M的樣子,內核1M,庫1M,shell1M。
login:(驗證用戶身份)
用戶名:用戶ID(用戶標識符)
計算機識別最快的不是字符而是數字。
每個用戶名都有ID的,用戶名是公開的,用戶名不能用作限定用戶是否能夠訪問資源的認證標識。
認證機制(Authentication):
認證的過程就是鑑別用戶或某個人就是它所聲稱那個人的過程。
認證並不代表全部,認證完成以後還需要資源訪問的授權。
授權(Authorization):
審計(Audition):日誌
Smoke login:root
Password:
[root@Smoke ~]#
promprt:命令提示符。
命令:即可以是二進制命令也可以是腳本。
magic number:魔數,標識二進制執行格式。
在winodws上執行程序的魔數和在linux上執行程序的魔數是不一樣的,它們所理解的二進制格式也是不盡相同的,所以就算兩者的庫完全一樣,在linux上編譯的程序未必能在windows上運行。
shebang
#!/bin/bash(指定魔數)
當一個程序被啓動的時候,這個程序的執行入口,這個程序被提交給內核,只有內核才能管理進程,當我們在命令提示符鍵入一個命令,敲回車的時候,這麼個程序就會由bash提交給內核,內核接着就去找這個程序執行的魔數,看它是不是一個可執行格式,以及是不是當前內核理解的可執行格式,如果是就執行起來,否則就拒絕運行,當然是不是會真正執行還要取決於權限和各種外圍機制。
命令的格式:# command options... arguments...
選項:修改命令執行特性。
短選項:可以合併
長選項:
參數:指定命令的作用對象,這個命令對誰生效,多個參數使用空格隔開。
在命令當中有些選項是可以帶參數的,選項的參數和命令的參數是兩碼事。
ls:list列表,列出;可以列出所指定目錄下的所有子目錄或者文件。
文件夾:winodws系統對目錄的誤導。
目錄:目錄也是文件,目錄並不是文件夾,它僅僅是一個路徑映射。
路徑:從指令起始點到目的地所經過的位置,路徑爲了實現層次化文件管理的機制。
文件系統:file system層次化管理文件的機制。
絕對路徑:從根開始找到對應文件。
相對路徑:相對於當前所處位置的路徑。
工作目錄:working directory登錄系統以後所處的目錄。
當前目錄:current directory當前所處的位置。
FHS:文件系統層級標準,規定那些目錄必須存在,而且這些目錄必須放那些文件。
[root@Smoke ~]# ls(列出當前目錄文件和子目錄)
anaconda-ks.cfg nagios-plugins-2.0.1 rrdtool-1.3.8-7.el6.x86_64.rpm
cacti-0.8.8b.tar.gz
pwd:Printing Working directory顯示當前目錄。
/:根目錄表示,各目錄節點間用/隔開。
藍色:目錄。
綠色:有執行權限。
紫色:套接字文件
常用的顏色有6種。
[root@Smoke ~]# pwd(顯示當前所處的目錄)
/root
[root@Smoke ~]# ls /root/(顯示/root目錄文件和子目錄)
anaconda-ks.cfg nagios-plugins-2.0.1 rrdtool-1.3.8-7.el6.x86_64.rpm
cacti-0.8.8b.tar.gz
ls:list列表,列出;可以列出所指定目錄下的所有子目錄或者文件。
-l:長格式,顯示完整信息,會顯示文件很多屬性。
文件完整信息解釋:
----------:10位,最左側一位是文件類型,後面9位表示權限,每3位一組,每一組裏面有:rwx(讀寫執行),如果沒有對應權限橫槓-表示。
文件類型:
-:普通文件(f)
d:目錄文件
b:塊設備文件(block)
c:字符設備文件(character)
l:符號鏈接文件(symbolic link file),也叫軟連接。
p:命名管道文件(pipe)
s:套接字文件(socket)
rwx:寫,寫執行。
r--:能讀,不能寫不能執行。
文件硬連接的次數:
權限後面的數字表示文件硬鏈接的次數。
文件的屬主(owner)
文件的屬組(group)
文件大小(size):默認單位字節。
時間戳(timestamp):這裏顯示最近一次被修改的時間,每隔文件都有三個時間戳,包括最近一次被訪問的時間,最近一次被修改的時間,最近一次被改變的時間。
訪問:access讀
修改:modify改變了文件的內容。
改變:change改變了文件的屬性或元數據。
一個文件有兩種數據,一種是文件自身的數據,另外一種是文件的屬性數據,屬性數據也叫元數據,
元數據:metadata
文件名:
-h:做單位轉換。
-a:all顯示所有文件,linux以.開頭表示隱藏文件。
.:藍色,代表目錄,表示當前目錄
..:藍色,代表目錄,表示當前目錄的上一級目錄,父目錄。
-A:顯示所有文件,但不包括當.前目錄和..上級目錄。
-d:顯示目錄自身屬性。
計算機識別用戶是通過數字來識別的,文件名也是如此,每一個文件都有一個唯一的數字標識符,這叫文件的inode(文件的索引節點)
inode:index node,
-i:顯示文件索引節點號。
使用ls查看目錄下的文件及子目錄,文件及子目錄的名稱是通過字母表排序的,而且是升序排序的。
-r:逆序顯示文件排序。
-R:遞歸(recursive)顯示,比較消耗資源。
[root@Smoke ~]# ls -l(顯示當前目錄文件子目錄完整信息,-l顯示完整信息)
total 310680
-rw-------. 1 root root 1394 Apr 14 08:38 anaconda-ks.cfg(普通文件)
-rw-r--r-- 1 root root 2272130 May 14 20:14 cacti-0.8.8b.tar.gz
drwxr-xr-x. 2 root root 4096 Apr 15 21:27 Desktop(目錄文件)
drwxr-xr-x. 2 root root 4096 Apr 15 21:27 Documents
[root@Smoke ~]# ls(list列表,列出;可以列出所指定目錄下的所有子目錄或者文件)
anaconda-ks.cfg nagios-plugins-2.0.1 rrdtool-1.3.8-7.el6.x86_64.rpm
cacti-0.8.8b.tar.gz
[root@Smoke ~]# ls -l /dev/(查看/dev目錄下的文件和子目錄完整信息,-l長格式,顯示完整信息,會顯示文件很多屬性)
total 0
crw-rw---- 1 root video 10, 175 May 21 20:43 agpgart(字符設備文件)
crw-rw---- 1 root root 10, 56 May 21 20:44 autofs
lrwxrwxrwx 1 root root 3 May 21 20:43 cdrom -> sr0(符號連接文件)
lrwxrwxrwx 1 root root 3 May 21 20:43 cdrw -> sr0
[root@Smoke ~]# ifconfig(查看主機地址)
eth0 Link encap:Ethernet HWaddr 00:50:56:3A:91:69
inet addr:172.16.100.1 Bcast:172.16.100.255 Mask:255.255.255.0
inet6 addr: fe80::250:56ff:fe3a:9169/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:40 errors:0 dropped:0 overruns:0 frame:0
TX packets:47 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4557 (4.4 KiB) TX bytes:5770 (5.6 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:868 errors:0 dropped:0 overruns:0 frame:0
TX packets:868 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:57236 (55.8 KiB) TX bytes:57236 (55.8 KiB)
使用Xshell 4登錄Linux系統:
Xshell:\> ping 172.16.100.1(測試能否ping通linux系統)
正在 Ping 172.16.100.1 具有 32 字節的數據:
來自 172.16.100.1 的回覆: 字節=32 時間<1ms TTL=64
來自 172.16.100.1 的回覆: 字節=32 時間<1ms TTL=64
172.16.100.1 的 Ping 統計信息:
數據包: 已發送 = 2,已接收 = 2,丟失 = 0 (0% 丟失),
往返行程的估計時間(以毫秒爲單位):
最短 = 0ms,最長 = 0ms,平均 = 0ms
Xshell:\> ssh 172.16.100.1(使用ssh連接linux主機)
[root@Smoke ~]# ls -l /tmp/(查看/tmp目錄下文件及子目錄完整信息)
total 44
-rw------- 1(文件硬連接次數) root(所有者) root 18009 May 29 19:44 yum_save_tx-2014-05-29-19-44KIYaTb.yumtx(能讀能寫不能執行)
drwx------. 2 Smoke Smoke 4096 Apr 14 01:19 pulse-8G34pGhBrYlR
drwxr-xr-x 2 root root 4096 May 29 19:39 puppet
srwxr-xr-x 1 root root 0 May 18 02:43 mapping-root(套接字文件)
[root@Smoke ~]# ls -l -h(查看當前目錄文件及子目錄完整信息並做單位換算,-l顯示完整信息,-h單位換算)
total 304M
-rw-------. 1 root root 1.4K Apr 14 08:38 anaconda-ks.cfg
-rw-r--r-- 1 root root 2.2M May 14 20:14 cacti-0.8.8b.tar.gz
drwxr-xr-x. 2 root root 4.0K Apr 15 21:27 Desktop
drwxr-xr-x. 2 root root 4.0K Apr 15 21:27 Documents
[root@Smoke ~]# ls -lh(查看當前目錄文件及子目錄完整信息並做單位換算,-l顯示完整信息,-h單位換算,組合選項)
total 304M
-rw-------. 1 root root 1.4K Apr 14 08:38 anaconda-ks.cfg
-rw-r--r-- 1 root root 2.2M May 14 20:14 cacti-0.8.8b.tar.gz
drwxr-xr-x. 2 root root 4.0K Apr 15 21:27 Desktop
drwxr-xr-x. 2 root root 4.0K Apr 15 21:27 Documents
[root@Smoke ~]# ls -a(顯示當前目錄的文件及子目錄所有文件包括隱藏文件,-a代表all顯示所有)
. .lftp
.. .local
[root@Smoke ~]# ls .(顯示當前目錄文件及子目錄)
anaconda-ks.cfg pam_mysql-0.7-0.12.rc1.el6.x86_64.rpm
cacti-0.8.8b.tar.gz Pictures
[root@Smoke ~]# ls ..(顯示上一級目錄的文件及子目錄)
bin dev home lib64 media mnt opt root selinux srv tmp var
boot etc lib lost+found misc net proc sbin shared sys usr
[root@Smoke ~]# ls -A(選項-A顯示所有文件,但不包括當.前目錄和..上級目錄)
.abrt .local
anaconda-ks.cfg .mozilla
[root@Smoke ~]# ls -ld /root/(顯示目錄自身完整信息屬性,-l顯示完整信息,-d顯示目錄自身)
dr-xr-x---. 31 root root 4096 Jun 1 14:43 /root/
[root@Smoke ~]# ls -i(顯示當前目錄的文件及子目錄的索引節點號,-i顯示索引節點號)
793872 anaconda-ks.cfg 786737 pam_mysql-0.7-0.12.rc1.el6.x86_64.rpm
793444 cacti-0.8.8b.tar.gz 790976 Pictures
[root@Smoke ~]# ls -R(遞歸顯示當前目錄下的文件及子目錄及子子目錄文件,-R遞歸顯示)
.:
anaconda-ks.cfg
cacti-0.8.8b.tar.gz
Desktop
[root@Smoke ~]# ls -r(逆序排列顯示當前目錄下的子目錄及文件,-r逆序顯示)
vmware-tools-distrib nrpe-2.15.tar.gz
Videos nrpe-2.15
cd:change directory切換當前工作目錄。
cd:不加任何參數,回到用戶的家目錄。
家目錄,主目錄,home directory
對於自己的家目錄用戶有所有的操作權限,每個用戶的家在bash當中都使用~波浪線表示。
cd ~:回到用戶自己的家目錄。
cd ~USERNAME:切換到指定用戶的家目錄,只有管理員纔有權限進別的家。
cd -:在當前目錄和前一次所在的目錄之間來回切換。
[root@Smoke ~]# pwd(顯示當前所處目錄,在/root目錄)
/root
[root@Smoke ~]# cd /usr/(切換到/usr目錄)
[root@Smoke usr]# pwd(顯示當前所在目錄,在/usr目錄)
/usr
[root@Smoke usr]# cd(cd不跟任何參數切換到用戶家目錄)
[root@Smoke ~]#
[root@Smoke ~]# cd /usr/(切換到/usr目錄)
[root@Smoke usr]# cd ~(cd加參數~波浪線回到用戶家目錄)
[root@Smoke ~]#
[root@Smoke ~]# cd ~student(cd加參數~用戶名,切換到響應用戶的家目錄)
[root@Smoke student]# pwd(顯示當前所在的目錄,在/home/student)
/home/student
[root@Smoke student]# cd(cd不跟任何參數切換到用戶家目錄)
[root@Smoke ~]# cd -(cd加參數-,在前一個目錄和當前目錄進行來回切換)
/home/student
命令類型:
內置命令:shell內置命令,內部,內建命令;我們登錄系統以後默認給我們一個登錄提示符,表示我們已經啓動了shell,這個shell爲了完成一些自身自我管理,就必須要內置一些基本命令。
外部命令:在文件系統的某個路徑下有一個與命令名稱相應的可執行文件
cd is a shell builtin:shell內建,內部命令。
which:查看命令文件所在目錄。
type:顯示指定命令屬於哪種類型
[root@Smoke ~]# type cd
cd is a shell builtin(shell內建,內部命令)
[root@Smoke ~]# type ls
ls is aliased to `ls --color=auto'(外部命令)
[root@Smoke ~]# type su
su is /bin/su(外部命令)
[root@Smoke ~]# which ls(查看命令文件所在目錄)
alias ls='ls --color=auto'
/bin/ls
當我們執行一個命令,並沒有告訴它執行那個路徑的下的什麼命令,它是如何知道的,系統怎麼能找到這個命令,按道理來講我們引用任何一個文件都必須給它一個全路徑,系統爲了能夠讓用戶能夠便捷在命令提示符下執行命令,它給我們內置了一種機制,這種機制是通過一個叫環境變量方式來實現的。
變量:
環境變量:命名的內存空間,在內存中劃分一段空間給它起個名字,我就可以向起了名的內存空間放數據了,用戶定義當前用戶的工作環境屬性。
變量賦值:放數據的過程,名稱只在當前程序中有用,變量既可以申請使用,還可以釋放。
NAME=jerry:等號=表示賦值。
聲明變量的過程:程序告訴操作系統給我一段內存,我等會要放數據,申請內存使用的過程。
堆棧:在編程當中堆叫做heap,棧叫做stack,它們用來放各自不同類型的數據,比如在棧當中通常本地生成一些變量和靜態變量等等,而其他用戶獲取申請保存數據不是變量需要申請一段空間保存數據,這個通常是堆,所以它們是兩種申請內存空間的不同機制,而且在地址空間中也是不同的。
無論是哪一種shell都有自己的環境變;
PATH:一堆使用冒號分隔的路徑,冒號隔開的次序很關鍵。
PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
當我們執行一個命令它會按次序從這些指定路徑下一個一個找,直到第一次找到爲止,如果兩個地方都有相同的命令比如ls,這兩個命令所在的路徑在PATH中那個路徑在前面以那個爲準。
如果要執行很多的命令,但是每次都要查找一遍,雖然計算機執行速度很快,但是每次都找也很慢,在系統上有成千上萬個命令,如果某個命令第一次執行的時候,它一定是實時去找的,如果找着了,第二次再執行同一個命令就不找了,會有一個緩存,在內存當中找一個地方將對應的命令和目錄緩存下來,bash有個緩存,在緩存當中記錄下來了此前用過的所有命令的路徑,並且再以後使用不會再去找,而是先去找緩存。
hash:查看命令緩存。
如果緩存下來如果內容非常多的話,找緩存的速度就一定比找文件的速度快嗎,緩存在這裏保存的是一個hash(哈希)列表,哈希是一個key value(建值段),是一個建值數據庫,在建值庫當中查找內容的速度是O(1)的。
O(1):衡量程序執行速度標準,我們從一個列表中查找一個數據的速度隨着列表長度變化而發生變化的比例,O(1)表示無論這個隊列有多長,我從中找一個內容的時間是一樣的。
如果我們開發一個程序放在某個路徑下,而那個路徑不再PATH=路徑當中,如果執行不跟路徑是不能執行的,所以我們的命令只要不帶路徑,就必須是PATH=指定路徑下的命令,要麼給它一個完整路徑,要麼把路徑加到PATH=路徑裏面來。
[root@Smoke ~]# /bin/ls(全路徑執行ls命令)
anaconda-ks.cfg pam_mysql-0.7-0.12.rc1.el6.x86_64.rpm
cacti-0.8.8b.tar.gz Pictures
[root@Smoke ~]# clear(清屏)
[root@Smoke ~]# clear
[root@Smoke ~]# printenv(顯示環境)
HOSTNAME=Smoke(主機名)
TERM=xterm(終端類型)
SHELL=/bin/bash(使用的shell類型)
HISTSIZE=1000
SSH_CLIENT=172.16.100.254 3901 22
QTDIR=/usr/lib64/qt-3.3
QTINC=/usr/lib64/qt-3.3/include
SSH_TTY=/dev/pts/0
USER=root
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.tbz=01;31:*.tbz2=01;31:*.bz=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:
MAIL=/var/spool/mail/root
PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
PWD=/root
LANG=en_US.UTF-8
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
HISTCONTROL=ignoredups
SHLVL=1
HOME=/root
LOGNAME=root
QTLIB=/usr/lib64/qt-3.3/lib
CVS_RSH=ssh
SSH_CONNECTION=172.16.100.254 3901 172.16.100.1 22
LESSOPEN=|/usr/bin/lesspipe.sh %s
DISPLAY=localhost:10.0
G_BROKEN_FILENAMES=1
_=/usr/bin/printenv
OLDPWD=/home/student
[root@Smoke ~]# hash(緩存的命令,hits代表命中多少次,使用多少次。)
hits command
4 /bin/touch
1 /usr/bin/printenv
13 /bin/ls
1 /usr/bin/clear
顯示系統時間:
date:時間管理,系統時間而非硬件時間,不帶任何選項查看當前系統時間。
Linux:rtc實時時鐘
ntp:網絡時間協議。
linux在開機的時候他會通過rtc讀取當前時間,一旦讀取成功了,就不再使用那個時間了,以後我們內核自身會通過軟件的方式模擬振盪器在系統內部來維持一個時鐘,只要我們操作系統在運行當中內核在CPU作用下就會自動進行計時的。
硬件時鐘:
系統時鐘:
clock:硬件時間,不帶任何參數查看當前硬件時間。
hwclock:硬件時間。不帶任何參數查看當前硬件時間。
練習:
使用date單獨獲取系統當前的年份、月份、日、小時、分鐘、秒
[root@Smoke ~]# date(顯示系統時間)
Sun Jun 1 20:07:38 CST 2014
[root@Smoke ~]# clock(顯示硬件時間)
Sun 01 Jun 2014 08:19:14 PM CST -0.393199 seconds
[root@Smoke ~]# hwclock(顯示硬件時間)
Sun 01 Jun 2014 08:19:51 PM CST -0.535787 seconds
如何獲得命令的使用幫助:
內部命令:
help COMMAND:獲取內部命令的幫助。
外部命令:
COMMAND --help:獲得外部命令的幫助。
命令手冊:manual
man COMMAND:不管內部命令還是外部命令都有公用的使用方式man幫助。
注意:內部命令man幫助,man的不是這個命令,而是這個命令所屬的shell,內部命令一般不會使用man幫助。
man分章節:顯示(1)表示第一章節,man常見的章節有8種。
1:用戶命令(/bin, /usr/bin, /usr/local/bin):表示所有用戶都可以使用的命令,包括普通用戶也是。
2:系統調用
3:庫調用:並非所有命令都有庫調用,只有庫纔有庫調用,如果碰巧一個命令和庫的名字相同,他倆纔會同時出現。
4:特殊文件(設備文件):設備文件都是特殊文件,它在磁盤上真正的數據區域沒有存儲任何內容,它只是作爲設備的訪問入口存在的。
5:文件格式(配置文件的語法):很多的命令爲了定義它的執行特性可以使用選項,有些命令它的選項可能不需要用戶每一次都指定,或者這個命令希望開機就能自動啓動,對於非常複雜的執行文件,它通常都有一個配置文件的文件,在這個配置文件中保存了以往可以通過選項指定了程序執行特性,所以這個配置文件都類似於變量,都是什麼=什麼的方式定義這個程序的執行屬性,解釋某個命令對應的配置文件語法。
6:遊戲
7:雜項(Miscellaneous):不便歸類的雜項。
8: 管理命令(/sbin, /usr/sbin, /usr/local/sbin):只有管理員才能使用的命令,會修改硬件參數及系統級別參數。
man NUMBERS COMMAND:如果一個命令在多個章節都有,指定顯示命令第幾章節內容,如果不指定的章節顯示1-7往過排,那一個先出現顯示那一個。
whatis COMMAND:顯示命令的摘要信息,以及出現在man幫助那些章節。
跟用戶帳號相關的兩個文件:
/etc/passwd
/etc/shadow
這兩個跟我們的命令是一個名字,所以這個文件是有格式的。
man對命令的描述:
<>:必選
[]:可選
...:可以出現多次
|:多選一
{}:分組
MAN:
NAME:命令名稱及功能簡要說明
SYNOPSIS:用法說明,包括可用的選項
DESCRIPTION:命令功能的詳盡說明,可能包括每一個選項的意義
OPTIONS:說明每一個選項的意義
FILES:此命令相關的配置文件
BUGS:
EXAMPLES:使用示例
SEE ALSO:另外參照
翻屏:
向後翻一屏:SPACE
向前翻一屏:b
向後翻一行:ENTER或j
向前翻一行:k
查找:
/KEYWORD: 向後查找
n: 下一個
N:前一個
?KEYWORD:向前查找
n: 下一個
N:前一個
q: 退出
在線文檔:
info COMMAND:獲取命令信息
PageUP:向上翻譯
PageDown:上下翻譯
文檔:/usr/share/doc:幾乎所有的命令文檔都有
google搜索
apache, hadoop官方手冊
[root@Smoke ~]# help cd(查看內部命令cd的幫助)
cd: cd [-L|-P] [dir]
Change the shell working directory.
Options:
-L force symbolic links to be followed
-P use the physical directory structure without following symbolic
links
The default is to follow symbolic links, as if `-L' were specified.
Exit Status:
Returns 0 if the directory is changed; non-zero otherwise.
[root@Smoke ~]# ls --help(查看外部命令ls的使用幫助)
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort.
Mandatory arguments to long options are mandatory for short options too.
-a, --all do not ignore entries starting with .
-A, --almost-all do not list implied . and ..
--author with -l, print the author of each file
-b, --escape print octal escapes for nongraphic characters
--block-size=SIZE use SIZE-byte blocks. See SIZE format below
-B, --ignore-backups do not list implied entries ending with ~
-c with -lt: sort by, and show, ctime (time of last
modification of file status information)
with -l: show ctime and sort by name
otherwise: sort by ctime
-C list entries by columns
--color[=WHEN] colorize the output. WHEN defaults to `always'
or can be `never' or `auto'. More info below
-d, --directory list directory entries instead of contents,
and do not dereference symbolic links
-D, --dired generate output designed for Emacs' dired mode
-f do not sort, enable -aU, disable -ls --color
-F, --classify append indicator (one of */=>@|) to entries
--file-type likewise, except do not append `*'
--format=WORD across -x, commas -m, horizontal -x, long -l,
single-column -1, verbose -l, vertical -C
--full-time like -l --time-style=full-iso
-g like -l, but do not list owner
--group-directories-first
group directories before files.
augment with a --sort option, but any
use of --sort=none (-U) disables grouping
-G, --no-group in a long listing, don't print group names
-h, --human-readable with -l, print sizes in human readable format
(e.g., 1K 234M 2G)
--si likewise, but use powers of 1000 not 1024
-H, --dereference-command-line
follow symbolic links listed on the command line
--dereference-command-line-symlink-to-dir
follow each command line symbolic link
that points to a directory
--hide=PATTERN do not list implied entries matching shell PATTERN
(overridden by -a or -A)
--indicator-style=WORD append indicator with style WORD to entry names:
none (default), slash (-p),
file-type (--file-type), classify (-F)
-i, --inode print the index number of each file
-I, --ignore=PATTERN do not list implied entries matching shell PATTERN
-k like --block-size=1K
-l use a long listing format
-L, --dereference when showing file information for a symbolic
link, show information for the file the link
references rather than for the link itself
-m fill width with a comma separated list of entries
-n, --numeric-uid-gid like -l, but list numeric user and group IDs
-N, --literal print raw entry names (don't treat e.g. control
characters specially)
-o like -l, but do not list group information
-p, --indicator-style=slash
append / indicator to directories
-q, --hide-control-chars print ? instead of non graphic characters
--show-control-chars show non graphic characters as-is (default
unless program is `ls' and output is a terminal)
-Q, --quote-name enclose entry names in double quotes
--quoting-style=WORD use quoting style WORD for entry names:
literal, locale, shell, shell-always, c, escape
-r, --reverse reverse order while sorting
-R, --recursive list subdirectories recursively
-s, --size print the allocated size of each file, in blocks
-S sort by file size
--sort=WORD sort by WORD instead of name: none -U,
extension -X, size -S, time -t, version -v
--time=WORD with -l, show time as WORD instead of modification
time: atime -u, access -u, use -u, ctime -c,
or status -c; use specified time as sort key
if --sort=time
--time-style=STYLE with -l, show times using style STYLE:
full-iso, long-iso, iso, locale, +FORMAT.
FORMAT is interpreted like `date'; if FORMAT is
FORMAT1<newline>FORMAT2, FORMAT1 applies to
non-recent files and FORMAT2 to recent files;
if STYLE is prefixed with `posix-', STYLE
takes effect only outside the POSIX locale
-t sort by modification time
-T, --tabsize=COLS assume tab stops at each COLS instead of 8
-u with -lt: sort by, and show, access time
with -l: show access time and sort by name
otherwise: sort by access time
-U do not sort; list entries in directory order
-v natural sort of (version) numbers within text
-w, --width=COLS assume screen width instead of current value
-x list entries by lines instead of by columns
-X sort alphabetically by entry extension
-1 list one file per line
SELinux options:
--lcontext Display security context. Enable -l. Lines
will probably be too wide for most displays.
-Z, --context Display security context so it fits on most
displays. Displays only mode, user, group,
security context and file name.
--scontext Display only security context and file name.
--help display this help and exit
--version output version information and exit
SIZE may be (or may be an integer optionally followed by) one of following:
KB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.
Using color to distinguish file types is disabled both by default and
with --color=never. With --color=auto, ls emits color codes only when
standard output is connected to a terminal. The LS_COLORS environment
variable can change the settings. Use the dircolors command to set it.
Exit status:
0 if OK,
1 if minor problems (e.g., cannot access subdirectory),
2 if serious trouble (e.g., cannot access command-line argument).
[root@Smoke ~]# man ls(查看ls命令的使用手冊)
LS(1) User Commands LS(1)
NAME(命令名字)
ls - list directory contents(簡要功能說明)
SYNOPSIS(使用格式說明)
ls [OPTION]... [FILE]...
DESCRIPTION(使用描述)
List information about the FILEs (the current directory by default). Sort entries
alphabetically if none of -cftuvSUX nor --sort.
Mandatory arguments to long options are mandatory for short options too.
-a, --all
do not ignore entries starting with .
-A, --almost-all
do not list implied . and ..
--author
with -l, print the author of each file
-b, --escape
print octal escapes for nongraphic characters
--block-size=SIZE
use SIZE-byte blocks. See SIZE format below
-B, --ignore-backups
do not list implied entries ending with ~
-c with -lt: sort by, and show, ctime (time of last modification of file status
information) with -l: show ctime and sort by name otherwise: sort by ctime
-C list entries by columns
--color[=WHEN]
colorize the output. WHEN defaults to 'always' or can be 'never' or 'auto'.
More info below
-d, --directory
list directory entries instead of contents, and do not dereference symbolic links
-D, --dired
generate output designed for Emacs' dired mode
-f do not sort, enable -aU, disable -ls --color
-F, --classify
append indicator (one of */=>@|) to entries
--file-type
likewise, except do not append '*'
--format=WORD
across -x, commas -m, horizontal -x, long -l, single-column -1, verbose -l, ver-
tical -C
--full-time
like -l --time-style=full-iso
-g like -l, but do not list owner
--group-directories-first
group directories before files.
augment with a --sort option, but any use of --sort=none (-U) disables grouping
-G, --no-group
in a long listing, don't print group names
-h, --human-readable
with -l, print sizes in human readable format (e.g., 1K 234M 2G)
--si likewise, but use powers of 1000 not 1024
-H, --dereference-command-line
follow symbolic links listed on the command line
--dereference-command-line-symlink-to-dir
follow each command line symbolic link that points to a directory
--hide=PATTERN
do not list implied entries matching shell PATTERN (overridden by -a or -A)
--indicator-style=WORD
append indicator with style WORD to entry names: none (default), slash (-p),
file-type (--file-type), classify (-F)
-i, --inode
print the index number of each file
-I, --ignore=PATTERN
do not list implied entries matching shell PATTERN
-k like --block-size=1K
-l use a long listing format
-L, --dereference
when showing file information for a symbolic link, show information for the file
the link references rather than for the link itself
-m fill width with a comma separated list of entries
-n, --numeric-uid-gid
like -l, but list numeric user and group IDs
-N, --literal
print raw entry names (don't treat e.g. control characters specially)
-o like -l, but do not list group information
-p, --indicator-style=slash
append / indicator to directories
-q, --hide-control-chars
print ? instead of non graphic characters
--show-control-chars
show non graphic characters as-is (default unless program is 'ls' and output is a
terminal)
-Q, --quote-name
enclose entry names in double quotes
--quoting-style=WORD
use quoting style WORD for entry names: literal, locale, shell, shell-always, c,
escape
-r, --reverse
reverse order while sorting
-R, --recursive
list subdirectories recursively
-s, --size
print the allocated size of each file, in blocks
-S sort by file size
--sort=WORD
sort by WORD instead of name: none -U, extension -X, size -S, time -t, version -v
--time=WORD
with -l, show time as WORD instead of modification time: atime -u, access -u, use
-u, ctime -c, or status -c; use specified time as sort key if --sort=time
--time-style=STYLE
with -l, show times using style STYLE: full-iso, long-iso, iso, locale, +FORMAT.
FORMAT is interpreted like 'date'; if FORMAT is FORMAT1<newline>FORMAT2, FORMAT1
applies to non-recent files and FORMAT2 to recent files; if STYLE is prefixed
with 'posix-', STYLE takes effect only outside the POSIX locale
-t sort by modification time
-T, --tabsize=COLS
assume tab stops at each COLS instead of 8
-u with -lt: sort by, and show, access time with -l: show access time and sort by
name otherwise: sort by access time
-U do not sort; list entries in directory order
-v natural sort of (version) numbers within text
-w, --width=COLS
assume screen width instead of current value
-x list entries by lines instead of by columns
-X sort alphabetically by entry extension
-1 list one file per line
SELinux options:
--lcontext
Display security context. Enable -l. Lines will probably be too wide for most
displays.
-Z, --context
Display security context so it fits on most displays. Displays only mode, user,
group, security context and file name.
--scontext
Display only security context and file name.
--help display this help and exit
--version
output version information and exit
SIZE may be (or may be an integer optionally followed by) one of following: KB 1000, K
1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.
Using color to distinguish file types is disabled both by default and with
--color=never. With --color=auto, ls emits color codes only when standard output is
connected to a terminal. The LS_COLORS environment variable can change the settings.
Use the dircolors command to set it.
Exit status:
0 if OK,
1 if minor problems (e.g., cannot access subdirectory),
2 if serious trouble (e.g., cannot access command-line argument).
AUTHOR(作者)
Written by Richard M. Stallman and David MacKenzie.
REPORTING BUGS(如果發現命令有BUG將信息發送給誰)
Report ls bugs to [email protected]
GNU coreutils home page: < http://www.gnu.org/software/coreutils/ >
General help using GNU software: < http://www.gnu.org/gethelp/ >
Report ls translation bugs to < http://translationproject.org/team/ >
COPYRIGHT(版權)
Copyright 2010 Free Software Foundation(自由軟件基金會), Inc. License GPLv3+: GNU GPL version 3 or
later < http://gnu.org/licenses/gpl.html >.
This is free software: you are free to change and redistribute it. There is NO WAR-
RANTY, to the extent permitted by law.
SEE ALSO(如果想獲得進一步信息請查看)
The full documentation for ls is maintained as a Texinfo manual. If the info and ls
programs are properly installed at your site, the command
info coreutils 'ls invocation'
should give you access to the complete manual.
GNU coreutils 8.4 March 2014 LS(1)
[root@Smoke ~]# man cd(內部命令man幫助,man的不是這個命令,而是這個命令所屬的shell)
BASH_BUILTINS(1) BASH_BUILTINS(1)
NAME
bash, :, ., [, alias, bg, bind, break, builtin, caller, cd, command, compgen, complete,
compopt, continue, declare, dirs, disown, echo, enable, eval, exec, exit, export, false,
fc, fg, getopts, hash, help, history, jobs, kill, let, local, logout, mapfile, popd,
printf, pushd, pwd, read, readonly, return, set, shift, shopt, source, suspend, test,
times, trap, true, type, typeset, ulimit, umask, unalias, unset, wait - bash built-in
commands, see bash(1)
[root@Smoke ~]# man 2 read(查看read第2章節系統調用章節)
READ(2) Linux Programmer's Manual(linux開發人員手冊) READ(2)
NAME
read - read from a file descriptor
SYNOPSIS
#include <unistd.h>(這是一個系統調用)
ssize_t read(int fd, void *buf, size_t count);
DESCRIPTION
read() attempts to read up to count bytes from file descriptor fd into the buffer start-
ing at buf.
If count is zero, read() returns zero and has no other results. If count is greater
than SSIZE_MAX, the result is unspecified.
[root@Smoke ~]# export LANG="en"(修改語言編碼方式爲english)
[root@Smoke ~]# man mount(查看mount的man幫助在第8章節)
MOUNT(8) Linux Programmer's Manual MOUNT(8)
NAME
mount - mount a filesystem
SYNOPSIS
mount [-lhV]
mount -a [-fFnrsvw] [-t vfstype] [-O optlist]
mount [-fnrsvw] [-o option[,option]...] device|dir
mount [-fnrsvw] [-t vfstype] [-o options] device dir
[root@Smoke ~]# whatis read(查看read命令man幫助在第幾章節)
read (1p) - read a line from standard input
read (2) - read from a file descriptor
read (3p) - read from a file
read [builtins] (1) - bash built-in commands, see bash(1)
[root@Smoke ~]# man 4 tty(查看第四章man幫助節特殊文件)
TTY(4) Linux Programmer's Manual TTY(4)
NAME
tty - controlling terminal(用於控制終端)
DESCRIPTION
The file /dev/tty(對應設備文件) is a character(字符文件) file with major number 5(主號碼) and minor number 0(次號碼), usually of
mode 0666 and owner.group root.tty. It is a synonym for the controlling terminal of a
process, if any.
In addition to the ioctl(2) requests supported by the device that tty refers to, the
ioctl(2) request TIOCNOTTY is supported.
[root@Smoke ~]# cat /etc/passwd(查看/etc/passwd文件內容,這個文件是由格式的通過冒號:隔開)
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
[root@Smoke ~]# man passwd(顯示的是命令的幫助)
PASSWD(1) User utilities PASSWD(1)
NAME
passwd - update user's authentication tokens
SYNOPSIS
passwd [-k] [-l] [-u [-f]] [-d] [-e] [-n mindays] [-x maxdays] [-w warndays] [-i inac-
tivedays] [-S] [--stdin] [username]
[root@Smoke ~]# man 5 passwd(顯示passwd每隔冒號是什麼意思,在第五章文件格式)
PASSWD(5) Linux Programmer's Manual PASSWD(5)
NAME
passwd - password file(用戶的密碼文件)
[root@Smoke ~]# man man(獲得man的man手冊)
man(1) man(1)
NAME
man - format and display the on-line manual pages
SYNOPSIS
man [-acdfFhkKtwW] [--path] [-m system] [-p string] [-C config_file] [-M pathlist] [-P
pager] [-B browser] [-H htmlpager] [-S section_list] [section] name ...
man對命令的描述:
[root@Smoke ~]# man date(查看date命令的man幫助)
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]](中間豎線表示二選一或多選一,只能選擇一個不能同時使用)
date:
date - print or set the system date and time
date [OPTION]... [+FORMAT](格式)
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]](修改系統時間,月日小時分鐘年.秒)
FORMAT(格式):
%D date; same as %m/%d/%y(顯示月日年)
%y last two digits of year (00..99)(顯示兩位年)
%Y year(顯示四位年)
%d day of month (e.g, 01)(顯示一個月的第幾天)
%n a newline(換行)
%T time; same as %H:%M:%S(顯示小時分鐘秒)
%F full date; same as %Y-%m-%d(顯示年月日)
%M minute (00..59)(分鐘)
%S second (00..60)(顯示秒)
%s seconds since 1970-01-01 00:00:00 UTC(時間戳,Unix元年計時法,從1970年01月01日00點00分00秒至此刻爲止經過的秒數)
[root@Smoke ~]# date 0601220514.30(更改系統時間爲6月1日22點05分14年30秒)
Sun Jun 1 22:05:30 CST 2014
[root@Smoke ~]# date +%D(顯示月日年)
06/01/14
[root@Smoke ~]# date +%Y(顯示四位年)
2014
[root@Smoke ~]# date +%y(顯示兩位年)
14
[root@Smoke ~]# date +"This year is %Y"(可以帶字符原封不動顯示年)
This year is 20
[root@Smoke ~]# date +"This year is %Y."(可以帶字符和標點符號原封不動顯示年)
This year is 2014.
[root@Smoke ~]# date +%d(顯示今天是這個月第幾天)
01
[root@Smoke ~]# date +"This year is %Y. Today is %d."(顯示年,並顯示今天是這個月第幾條,加入其他字符標點符號顯示)
This year is 2014. Today is 01.
[root@Smoke ~]# date +"This year is %Y. %nToday is %d."顯示年,並顯示今天是這個月第幾條,加入其他字符標點符號顯示,並通過%n換行顯示)
This year is 2014.
Today is 01.
[root@Smoke ~]# date +%T(顯示小時分鐘秒)
22:26:14
[root@Smoke ~]# date +%F(顯示年月日)
2014-06-01
[root@Smoke ~]# date +%Y-%m-%d(顯示年月日,橫線-隔開)
2014-06-01
[root@Smoke ~]# date +%H:%M(顯示幾點幾分,冒號:隔開)
22:29
[root@Smoke ~]# date +%H-%M(顯示幾點幾分,橫線-隔開)
22-30
[root@Smoke ~]# date +%s(顯示時間戳,從1970.01.01.00.00.00到現在經過的秒數)
1401633375
clock:查看硬件時間,等同於hwclock
hwclock:默認顯示硬件時間
-w: 將系統時間同步到硬件,改硬件時間
-s: 把硬件時間同步到系統時間,改系統時間
-r:顯示硬件時間,可以不加-r。
[root@Smoke ~]# clock(查看硬件時間)
Sun 01 Jun 2014 10:39:07 PM CST -0.220458 seconds
[root@Smoke ~]# hwclock -w(將系統時間同步到硬件,改硬件時間)
[root@Smoke ~]# clock(查看硬件時間)
Sun 01 Jun 2014 10:41:11 PM CST -0.127240 seconds
[root@Smoke ~]# date 03151132(更改系統時間爲錯誤時間)
Sat Mar 15 11:32:00 CST 2014
[root@Smoke ~]# hwclock -s(把硬件時間同步到系統時間,改系統時間)
[root@Smoke ~]# date
Sun Jun 1 22:43:11 CST 2014
[root@Smoke ~]# man hwclock(查看hwclock的man文檔)
[root@Smoke ~]# hwclock -r(顯示硬件時間)
Sun 01 Jun 2014 10:48:40 PM CST -0.112417 seconds
在線文檔:
info COMMAND
翻頁:
PageUP:向上翻譯
PageDown:上下翻譯
[root@Smoke ~]# info ls(查看ls命令的在線文檔)
文檔:/usr/share/doc:幾乎所有的命令文檔都有。
[root@Smoke ~]# cd /usr/share/doc/(命令手冊文檔目錄)
[root@Smoke doc]# ls(查看目錄下的文件及子目錄)
abrt-2.0.8 libstdc++-devel-4.4.7
abyssinica-fonts-1.0 libtar-1.2.11
cal: calendar日曆
[root@Smoke ~]# cal(查看日曆)
June 2014
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
[root@Smoke ~]# cal 2013(2013年的年曆)
2013
January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 5 1 2 1 2
6 7 8 9 10 11 12 3 4 5 6 7 8 9 3 4 5 6 7 8 9
13 14 15 16 17 18 19 10 11 12 13 14 15 16 10 11 12 13 14 15 16
20 21 22 23 24 25 26 17 18 19 20 21 22 23 17 18 19 20 21 22 23
27 28 29 30 31 24 25 26 27 28 24 25 26 27 28 29 30
31
April May June
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 1 2 3 4 1
7 8 9 10 11 12 13 5 6 7 8 9 10 11 2 3 4 5 6 7 8
14 15 16 17 18 19 20 12 13 14 15 16 17 18 9 10 11 12 13 14 15
21 22 23 24 25 26 27 19 20 21 22 23 24 25 16 17 18 19 20 21 22
28 29 30 26 27 28 29 30 31 23 24 25 26 27 28 29
30
July August September
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 1 2 3 1 2 3 4 5 6 7
7 8 9 10 11 12 13 4 5 6 7 8 9 10 8 9 10 11 12 13 14
14 15 16 17 18 19 20 11 12 13 14 15 16 17 15 16 17 18 19 20 21
21 22 23 24 25 26 27 18 19 20 21 22 23 24 22 23 24 25 26 27 28
28 29 30 31 25 26 27 28 29 30 31 29 30
October November December
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 5 1 2 1 2 3 4 5 6 7
6 7 8 9 10 11 12 3 4 5 6 7 8 9 8 9 10 11 12 13 14
13 14 15 16 17 18 19 10 11 12 13 14 15 16 15 16 17 18 19 20 21
20 21 22 23 24 25 26 17 18 19 20 21 22 23 22 23 24 25 26 27 28
27 28 29 30 31 24 25 26 27 28 29 30 29 30 31
[root@Smoke ~]# cal 12 2012(2012年12月日曆)
December 2012
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
練習:
1、echo是內部命令還是外部命令?
[root@Smoke ~]# type echo(查看echo命令類型,爲內部命令)
echo is a shell builtin
2、其作用?
[root@Smoke ~]# help echo(查看echo命令幫助)
[root@Smoke ~]# man echo(查看echo命令man文檔)
NAME
echo - display a line of text(顯示一行文本)
SYNOPSIS
echo [SHORT-OPTION]... [STRING]...
echo LONG-OPTION
[root@Smoke ~]# echo(打印文本,默認自動換行)
echo默認動作,不管輸入什麼文本都會打印並進行換行
-n:不換行.
[root@Smoke ~]# echo -n(顯示文本不換行)
[root@Smoke ~]# echo "The year is 2013. Today is 26."(顯示字符)
The year is 2013. Today is 26.
3、如何顯示"The year is 2013. Today is 26."爲兩行?
-e:開啓反斜槓轉義
\n:換行
\:顯示反斜槓自身
\b:退格鍵
\t:橫向製表符
\v:縱向製表符
[root@Smoke ~]# echo -e "The year is 2013. \nToday is 26."(顯示字符串,並通過-e選項開啓反斜槓轉義\n進行換行)
The year is 2013.
Today is 26.
[root@Smoke ~]# echo -e "The year is 2013.\bToday is 26."(顯示字符串,並通過-e選項開啓反斜槓轉義\b退一格刪除.點號)
The year is 2013Today is 26.
[root@Smoke ~]# echo -e "The year is 2013.\b\bToday is 26."(退格兩次)
The year is 201Today is 26.
[root@Smoke ~]# echo -e "The year is 2013.\tToday is 26."(顯示字符串,並通過-e選項開啓反斜槓轉義\t橫向tab空白)
The year is 2013. Today is 26.
[root@Smoke ~]# echo -e "The year is 2013.\vToday is 26."."(顯示字符串,並通過-e選項開啓反斜槓轉義\v縱向tab空白)
The year is 2013.
Today is 26.
[root@Smoke ~]# echo -n "The year is 2013."(顯示字符串,-n不換行顯示,默認自動換行_
The year is 2013.[root@Smoke ~]#
練習:
1、printf是內部命令還是外部命令?
[root@Smoke ~]# type printf(查看printf命令類型,內部命令)
printf is a shell builtin
2、其作用?
3、如何顯示"The year is 2013. Today is 26."爲兩行?
[root@Smoke ~]# man printf(查看printf命令man文檔)
NAME
printf - format and print data(格式化並顯示數據)
SYNOPSIS
printf FORMAT(格式) [ARGUMENT]...(參數)
printf OPTION
\n:換行符
[root@Smoke ~]# printf "The year is 2013."(格式化並顯示數據,默認不會換行)
The year is 2013.[root@Smoke ~]#
[root@Smoke ~]# printf "The year is 2013.\n"(格式化並顯示數據,使用\n換行;默認不會換行)
The year is 2013.
[root@Smoke ~]# printf "The year is 2013.\nToday is 26."(格式化並顯示數據,並通過\n將兩行字符串換行,但最後一行還沒換行)
The year is 2013.
Today is 26.[root@Smoke ~]#
[root@Smoke ~]# printf "The year is 2013.\nToday is 26.\n"(格式化並顯示數據,並通過\n將兩行字符全部換行)
The year is 2013.
Today is 26.
file命令及其用法:
file命令用來探測給定文件的類型。file命令對文件的檢查分爲文件系統、魔法幻數檢查和語言檢查3個過程。
語法
file(選項)(參數)
選項
-b:列出辨識結果時,不顯示文件名稱; -c:詳細顯示指令執行過程,便於排錯或分析程序執行的情形; -f<名稱文件>:指定名稱文件,其內容有一個或多個文件名稱時,讓file依序辨識這些文件,格式爲每列一個文件名稱; -L:直接顯示符號連接所指向的文件類別; -m<魔法數字文件>:指定魔法數字文件; -v:顯示版本信息; -z:嘗試去解讀壓縮文件的內容。
參數
文件:要確定類型的文件列表,多個文件之間使用空格分開,可以使用shell通配符匹配多個
[root@localhost ~]# file install.log
install.log: UTF-8 Unicode text
[root@localhost ~]# file -b install.log <== 不顯示文件名稱
UTF-8 Unicode text
[root@localhost ~]# file -i install.log <== 顯示MIME類別。
install.log: text/plain; charset=utf-8
[root@localhost ~]# file -b -i install.log
text/plain; charset=utf-8