前面的章節(jié)里對linux的文件的權(quán)限做了簡單的解釋。現(xiàn)在來看看常見的命令,從簡單的開始:
1 、切換目錄
cd
到/tmp 目錄:cd /tmp
到上層目錄:cd ..
2 、查看當(dāng)前目錄
pwd
3、 創(chuàng)建一個(gè)新的文件夾:
mkdir
創(chuàng)建一層目錄:

創(chuàng)建多層目錄:

4 、刪除目錄:
rmdir [-p] 如果需要層級刪除目錄,就需要帶上p(只能刪除空目錄)
5、查詢環(huán)境變量
echo $PATH 或者$PATH
6、切換用戶:
su 用戶名
7、移動文件

仔細(xì)閱讀上面的命令,你會發(fā)現(xiàn)mv還可以對文件進(jìn)行從命名,上面的命令將hellot.txt從a中移動到了b中,并改名為hello1.txt
8、查看文件與目錄
ls
ls -a 目錄名稱:列出目錄中所有的文件
ls -al 目錄名:列出長字符串,包含文件的一些詳細(xì)信息
如果沒有給定目錄名,那么就是當(dāng)前目錄
9、文件的復(fù)制:
cp [-adfilprsu] 源文件 目標(biāo)文件 //將源文件拷貝到目標(biāo)文件
cp src1,src2,... des //將多個(gè)源文件拷貝到目的文件夾
cp這個(gè)命令非常重要,不同的身份執(zhí)行對命令產(chǎn)生不同的效果,尤其是-a,-p參數(shù),對不同的身份來說,區(qū)別非常大。
例1:
使用root執(zhí)行:

如果我們要將文件的所有的屬性復(fù)制過來,則要加上參數(shù)-a
復(fù)制一個(gè)目錄到另外一個(gè)目錄 cp -r /src /desc
10 、移除文件或目錄
rm [-fir] 文件或目錄
-f 強(qiáng)制的意思,忽略不存在的文件,不會出現(xiàn)警告信息
-i互動模式:刪除前,會詢問是否刪除
-r :遞歸刪除
這里不再演示,記得之前的rmdir嗎,只能刪除空目錄,所以刪除非空目錄只能使用rm -r
11、文件類容查詢
cat
-b:列出行號
-n:列出行號,包括空白行

cat 是一次性將數(shù)據(jù)顯示到屏幕上,如果想一頁一頁的看怎么辦?
使用more命令
more在運(yùn)行的過程中,你有幾個(gè)按鍵可以按:
空格鍵:代表向下翻一頁
Enter:代表向下滾動一行
q:離開more
b:往回翻頁
12 、創(chuàng)建文件
touch
touch a.txt 就會在當(dāng)前目錄下創(chuàng)建a.txt
13、查找文件的命令
whereis ,find
whereis [-bmsu] 文件或目錄名
-b:二進(jìn)制文件
-m:只找在說明文件manual路徑下的問津
-s:只找source源文件
-u:查找不在上述三個(gè)選項(xiàng)中的其他特殊文件
whereis ifconfig
下面看看find命令
find [path] [option] [actioin]
查找/home下面屬于gavin的文件
find /home -user gavin
查找系統(tǒng)中不屬于任何人的文件
find / -nouser
查找文件名為passwd的這個(gè)文件
find / -name passwd
查找文件類型為socket的文件
find / -type s
14、磁盤和目錄的容量
df:列出文件系統(tǒng)的整體磁盤使用量
du:評估文件系統(tǒng)的磁盤使用量
15 創(chuàng)建鏈接文件
ln [-sf] 源文件 目標(biāo)文件
-s :創(chuàng)建軟連接,如果不加則是硬連接
-f:如果目標(biāo)文件存在,則刪除后再建
[root@localhost test2]# echo 'good'>a.txt
[root@localhost test2]# ls
a.txt
[root@localhost test2]# ln -s a.txt b
[root@localhost test2]# ls
a.txt b
[root@localhost test2]# ll
total 12
-rw-r--r-- 1 root root 5 Aug 8 01:09 a.txt
lrwxrwxrwx 1 root root 5 Aug 8 01:09 b -> a.txt
[root@localhost test2]# echo 'hello'>>b
[root@localhost test2]# cat b
good
hello
[root@localhost test2]# cat a.txt
good
hello
[root@localhost test2]# ln a.txt c
[root@localhost test2]# ll
total 20
-rw-r--r-- 2 root root 11 Aug 8 01:09 a.txt
lrwxrwxrwx 1 root root 5 Aug 8 01:09 b -> a.txt
-rw-r--r-- 2 root root 11 Aug 8 01:09 c
[root@localhost test2]# echo 'bad'>>c
[root@localhost test2]# cat c
good
hello
bad
[root@localhost test2]# cat a.txt
good
hello
bad
[root@localhost test2]# cat b
good
hello
bad
[root@localhost test2]# rm a.txt
rm: remove regular file `a.txt'? y
[root@localhost test2]# cat b
cat: b: No such file or directory
[root@localhost test2]# cat c
good
hello
bad
[root@localhost test2]#
運(yùn)行上面的命令行,相信你對ln的使用會非常清楚的。
15、掛載CD

16、文件壓縮
tar
-c:創(chuàng)建一個(gè)壓縮文件
-v:顯示壓縮過程
-f:給出壓縮文件名
-x:解壓文件
-t::查看壓縮包中又哪些文件
