感覺(jué)自己一直以來(lái)學(xué)習(xí)東西都是一半一半的,所以整理個(gè)學(xué)習(xí)筆記算是督促自己吧。
PS:學(xué)習(xí)是通過(guò)實(shí)驗(yàn)樓學(xué)習(xí)的。
1、Linux命令
?1.1 Linux中命令格式:
?command [options] [arguments] #中括號(hào)代表可選的,即有些命令不需要選項(xiàng)也不需要參數(shù)
? 選項(xiàng)是調(diào)整命令執(zhí)行命令的開(kāi)關(guān),選項(xiàng)的不同決定了命令結(jié)果的不同。
?參數(shù)是指命令的作用對(duì)象。
?1.2 man命令
?man是manul的縮寫(xiě),我們可以通過(guò)man man來(lái)查看man命令的幫助
幫助文檔包含:
1 Executable programs or shell commands(用戶(hù)命令幫助)
2 System calls (系統(tǒng)調(diào)用幫助)
3 Library calls (庫(kù)函數(shù)調(diào)用幫助)
4 Special files (usually found in /dev)
5 File formats and conventions eg /etc/passwd(配置文件幫助)
6 Games
7 Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7)
8 System administration commands (usually only for root)
9 Kernel routines [Non standard]
解釋如下:
1 Executable programs or shell commands(用戶(hù)命令幫助)
2 System calls (系統(tǒng)調(diào)用幫助)
3 Library calls (庫(kù)函數(shù)調(diào)用幫助)
4 Special files (usually found in /dev)
5 File formats and conventions eg /etc/passwd(配置文件幫助)
6 Games
7 Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7)
8 System administration commands (usually only for root)
9 Kernel routines [Non standard]
man命令可以結(jié)合grep命令和管道,可以多關(guān)鍵字查找:
man -k key1 | grep key2 | grep key3 | ...
?1.3 cheat命令
?cheat命令是在GNU通用公共許可證下,為L(zhǎng)inux命令行用戶(hù)發(fā)行的交互式備忘單應(yīng)用程序。它提供顯示Linux命令使用案例,包括該命令所有的選項(xiàng)和簡(jiǎn)短但尚可理解的功能。
?使用cheat命令作弊還是可以的。
?安裝參考:Cheat—— 給Linux初學(xué)者和管理員一個(gè)終極命令行"備忘單"
?1.4 與查找相關(guān)的核心命令
?find,locate,grep,whereis,which都是與查找相關(guān)的核心命令。
find查找一個(gè)文件或者目錄在系統(tǒng)的位置
locate是神速版的find(Windows中有個(gè)Everything和locate類(lèi)似)
grep可以對(duì)文件進(jìn)行全文檢索,支持正則表達(dá)式
whereis which 告訴你使用的命令工具安裝在什么地方
?1.5 有趣的命令
?banner命令是一個(gè)可以輸出圖形字符的命令。
?安裝放式如下:
$ sudo apt-get update
$ sudo apt-get install sysvbanner
效果圖:
自我想象-_--||
2、用戶(hù)以及文件權(quán)限管理
?2.1 查看用戶(hù)
?通過(guò)終端輸入命令who am i或者who mom likes
$ who am i
root pts/0 2018-11-16 15:13 (61.158.149.87)
#[偽終端用戶(hù)的用戶(hù)名] [pts代表偽終端 0是終端序號(hào)] [當(dāng)前偽終端的啟動(dòng)時(shí)間]
root用戶(hù)是系統(tǒng)最高用戶(hù),擁有至高無(wú)上的權(quán)限。一般登陸都是通過(guò)普通用戶(hù)登陸系統(tǒng)的。
?2.2 創(chuàng)建用戶(hù)
?創(chuàng)建用戶(hù)需要root權(quán)限或者是直接登陸root賬戶(hù)添加用戶(hù)(當(dāng)然你需要知道密碼)
?創(chuàng)建hanmimi用戶(hù)
jm:~/ sudo adduser hanmimi
?su <user>可以切換到user用戶(hù),不過(guò)需要用戶(hù)名和密碼,sudo <cmd>可以以高權(quán)限運(yùn)行cmd命令,但是需要當(dāng)前用戶(hù)在sudo用戶(hù)組,并且需要知道root用戶(hù)的密碼。
切換到hanmimi用戶(hù)
root:~/ su -l hanmimi
退出當(dāng)前用戶(hù),可以直接輸入exit然后敲擊回車(chē)。退出終端操作也是這樣。
hanmimi:~/ exit
?2.3 用戶(hù)組
?查看用戶(hù)所在的用戶(hù)組-1
$: groups lilei
lilei : lilei
#[第一列是用戶(hù)名稱(chēng)] {第二列是用戶(hù)所屬的用戶(hù)組名稱(chēng)]
?查看用戶(hù)所在的用戶(hù)組-2
$ cat /etc/group | sort
# | sort 表示將讀取的文本進(jìn)行一個(gè)字典排序再輸出
root:x:0:
bin:x:1:
daemon:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
lp:x:7:
mem:x:8:
kmem:x:9:
wheel:x:10:
cdrom:x:11:
mail:x:12:postfix
man:x:15:
dialout:x:18:
floppy:x:19:
games:x:20:
tape:x:30:
video:x:39:
ftp:x:50:
lock:x:54:
audio:x:63:
nobody:x:99:
users:x:100:
utmp:x:22:
太多了過(guò)濾掉它:
$ cat /etc/group | grep -E 'lilei'
lilei:x:1000:
?2.4 添加用戶(hù)到sudo用戶(hù)組
通過(guò)一條命令usermod -a -G sudo 用戶(hù)名
$ greoups lilei
$ usermod -a -G sudo lilei