################################
####### 一.linux系統結構 ########
linux是一個倒樹結構
linux中所有的東西都是檔案 “一切皆檔案”
這些檔案都在系統頂級目錄“/” /就是根目錄
/目錄以下為二級目錄這些目錄都是系統裝機時系統自動建立的
二級目錄的作用
/bin ##二進制可執行檔案也就是系統指令
/sbin ##系統管理指令存放位置
/boot ##啟動分區,負責系統啟動
/dev ##裝置管理檔案
/etc ##大多數系統管理檔案
/home ##普通使用者的家目錄
/lib ##32位系統庫檔案存放位置
/lib64 ##64位系統庫檔案存放位置
/media ##系統臨時裝置挂載點
/mnt ##系統臨時裝置挂載點
/run ##系統臨時裝置挂載點
/opt ##第三方軟體安裝位置
/proc ##系統資訊
/root ##超級使用者家目錄
/srv,/var ##系統資料
/sys ##系統管理,主要是關于核心的
/tmp ##系統臨時檔案存放位置
/usr ##系統使用者相關資訊資料及使用者自定義軟體存放位置
##end##
########################
#### 二.檔案的尋址 ######
絕對路徑
檔案在系統的真實位置,檔案名字以“/”開頭
相對路徑
檔案相對與目前所在位置的一個名字的簡寫,這個名字不會以/開頭,而且名字會自動添加pwd顯示的值
[root@localhost Desktop]# pwd /root/Desktop |
以“/”開頭的為絕對路徑;否則是相對路徑
#######################
#### 三.檔案的管理 #####
##### 1.touch 建立檔案或修改檔案時間戳 ####
touch:檔案的時間戳管理工具
touch [OPTION...] FILE…
stat file:顯示檔案的時間戳
[root@localhost Desktop]# stat file File: `file' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: 802h/2050d Inode: 655461 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2017-09-27 19:20:18.303028677 -0700 Modify: 2017-09-27 19:20:17.279028473 -0700 Change: 2017-09-27 19:20:17.279028473 -0700 |
三個時間戳:
accesstime:通路時間,簡寫為atime,讀取檔案内容
modifytime:修改時間,mtime, 改變檔案内容(資料)
changetime:改變時間,ctime, 中繼資料發生改變
touch file ##建立檔案
-a:only atime
-m:only mtime
-c: 如果檔案不存在,則不予建立
[root@localhost Desktop]# touch -a file Access: 2017-09-27 19:21:00.384028955 -0700 Change: 2017-09-27 19:20:59.369028217 -0700 [root@localhost Desktop]# touch -m file Access: 2017-09-27 19:21:09.274028703 -0700 Modify: 2017-09-27 19:21:08.261028482 -0700 Change: 2017-09-27 19:21:08.261028482 -0700 |
##### 2.mkdir 建立目錄 ####
mkdir【OPTION】 /path/to/somewhere
mkdir directory ##建立目錄
-p ##存在不報錯,且可自動建立所需的各目錄;
-v: ##顯示詳細資訊
-mMOOE:建立目錄時直接指定權限;
[root@localhost Desktop]# mkdir -vp westos/hello1/hello2 mkdir: created directory `westos/hello1' mkdir: created directory `westos/hello1/hello2' |
#### 3.rm 删除目錄或檔案 ####
-f ##強行删除不提示
-r ##遞歸删除目錄
[root@localhost Desktop]# rm westos rm: cannot remove `westos': Is a directory [root@localhost Desktop]# rm -fr westos |
#### 4.cat|head|tail 檢視檔案内容 ####
cat|head|tail ##檔案内容檢視指令
cat
Usage: cat [OPTION]... [FILE]...
-A, --show-all equivalent to -vET
-b, --number-nonblank number nonempty output lines ##不給空行編号
-e equivalent to -vE
-E, --show-ends display $ at end of each line
-n, --number number all output lines ##給空行編号
-s, --squeeze-blank suppress repeated empty output lines
-t equivalent to -vT
-T, --show-tabs display TAB characters as ^I
-u (ignored)
-v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
--help display this help and exit
--version output version information and exit
[root@localhost Desktop]# cat -A a sfjsfksdfjls$ dfdsg$ dgdgcx gdffkjk$ hello world$ !!!!! kdsfkjf$ [root@localhost Desktop]# cat a sfjsfksdfjls dfdsg dgdgcx gdffkjk hello world !!!!! kdsfkjf [root@localhost Desktop]# cat -b a 1sfjsfksdfjls 2dfdsg 3dgdgcx gdffkjk 4hello world 5!!!!! kdsfkjf 6sss |
head
Usage: head [OPTION]... [FILE]...
-n, --lines=[-]K print the first K lines instead of the first 10; #預設前十行
[root@localhost Desktop]# head -n2 a |
tail
Usage: tail [OPTION]... [FILE]...
-n, --lines=K output the last K lines, instead of the last 10;#預設後十行
or use -n +K to output lines starting with the Kth
[root@localhost Desktop]# tail -n2 a sss |
#### 5.vim 文本方式編輯檔案 ####
vim filename 進入到指令模式
指令模式不能編輯檔案,如果要編輯檔案要進入插入模式
按"i"進入插入模式
如果完成編輯,按'esc'推出插入模式,輸入':wq'儲存退出
vim filename 如果檔案名字不存在,會自動建立
vim 沒有操作對象直接打開,編輯檔案後要 :wq filename
注意:當文内容被錯誤更改,不想儲存用 " :q! " 這表示強制退出不儲存
######## 6.cd 切換工作目錄 ############
cd directory ##切換工作目錄到指定目錄
cd - ##切換工作目錄到之前所在目錄
cd ~ ##切換到自己的家目錄
cd ~usernmae ##切換到指定使用者家目錄
cd .. ##進入到目前目錄的上級目錄
[root@localhost Desktop]# cd /tmp [root@localhost tmp]# cd - [root@localhost Desktop]# cd ~ [root@localhost ~]# cd .. [root@localhost /]# |
######## 7.ls 列出目錄或檔案資訊 ######
ls ##如果後面沒有目标那麼預設目标為目前目錄
[root@localhost Desktop]# ls file file~ westos |
ls direcory|filename ##列出檔案或目錄内容
[root@localhost Desktop]# ls file file |
ls -d direcotry ##列出目錄本身
[root@localhost Desktop]# ls -d . |
ls -l filename|dorectory ##列出檔案或目錄裡面内容的屬性
[root@localhost Desktop]# ls -l total 4 -rw-r--r--. 1 root root 0 Sep 27 19:21 file -rw-r--r--. 1 root root 0 Sep 27 19:07 file~ drwxr-xr-x. 3 root root 4096 Sep 27 19:25 westos |
ls -ld directory ##列出目錄本身屬性
[root@localhost Desktop]# ls -ld drwxr-xr-x. 3 root root 4096 Sep 27 19:25 . |
ls -a ##顯示目錄中的所有内容,包括以"."開頭的隐藏檔案
[root@localhost Desktop]# ls -a . .. file file~ westos .wtt.sh.swp |
ls -R ##遞歸顯示目錄中的内容
[root@localhost Desktop]# ls -R .: ./westos: hello1 ./westos/hello1: hello2 ./westos/hello1/hello2: |
#### 8.cp 檔案複制 ####
cp [OPTION]... [-T] SOURCE DEST
cp[OPTION]... SOURCE... DIRECTORY
cp[OPTION]... -t DIRECTORY SOURCE...
cp file file1 file2 ...directory ###把file file1 file2 複制到 directory中
[root@localhost Desktop]# cp file westos file hello1 |
cp file test ###建立test檔案模闆為file
cp -r directorydirecotry1 ###複制目錄
[root@localhost Desktop]# cp -r westos hello1 hello1 westos ./hello1: ./hello1/hello1: ./hello1/hello1/hello2: |
cp SRC DEST
如果目标不存在:建立DEST,并将SRC中内容填充至DEST中;
如果目标存在:
如果DEST是檔案:将SRC中的内容覆寫至DEST中;此時建議為cp指令使用-i選項;
如果DEST是目錄:在DEST下建立與源檔案同名的檔案,并将SRC中内容填充至新檔案中;
cpSRC... DEST
DEST必須存在,且為目錄,其他情形均會出錯;
cpSRC...DEST
SRC是目錄:此時使用選項:-r
如果DEST不存在:則建立指定目錄,複制SRC目錄中所有檔案至DEST中;
常用選項
-i:互動式
-r,-R遞歸複制目錄及内部的所有内容;
-a:歸檔,相當于-dR --presev=all
-v:顯示複制過程
#### 9.mv 移動或重命名 ####
mv[OPTION]... [-T] SOURCE DEST
mv[OPTION]... SOURCE... DIRECTORY
mv[OPTION]... -t DIRECTORY SOURCE...
相同磁盤的mv是重命名,不同磁盤的mv是複制删除過程
mv file file1 direcotry ##移動file file1到directory中
mv 存在檔案 不存在檔案 ##重命名檔案
mv westos/linux . ##把westos中的linux移動到目前目錄 .代表目前目錄
######################
##### 四.正規表達式 ####
*###比對0到任意字元
? ###比對單個字元
[[:alpha:]] ###比對單個字母
[[:lower:]] ###比對單個小寫字母
[[:upper:]] ###比對單個大寫字母
[[:digit:]] ###比對單個數字
[[:alnum:]] ###比對單個數字或字母
[[:punct:]] ###比對單個符号
[[:space:]] ###比對單個空格
~ ###目前使用者家目錄
~username ###指定的使用者家目錄
~+ ###目前目錄
~- ###目前目錄之前所在目錄
. ###目前目錄
.. ###目前目錄的上一級