前面的章節里對linux的文件的權限做了簡單的解釋。現在來看看常見的命令,從簡單的開始:
1 、切換目錄
cd
到/tmp 目錄:cd /tmp
到上層目錄:cd ..
2 、查看當前目錄
pwd
3、 創建一個新的文件夾:
mkdir
創建一層目錄:

創建多層目錄:

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

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

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

cat 是一次性將數據顯示到屏幕上,如果想一頁一頁的看怎么辦?
使用more命令
more在運行的過程中,你有幾個按鍵可以按:
空格鍵:代表向下翻一頁
Enter:代表向下滾動一行
q:離開more
b:往回翻頁
12 、創建文件
touch
touch a.txt 就會在當前目錄下創建a.txt
13、查找文件的命令
whereis ,find
whereis [-bmsu] 文件或目錄名
-b:二進制文件
-m:只找在說明文件manual路徑下的問津
-s:只找source源文件
-u:查找不在上述三個選項中的其他特殊文件
whereis ifconfig
下面看看find命令
find [path] [option] [actioin]
查找/home下面屬于gavin的文件
find /home -user gavin
查找系統中不屬于任何人的文件
find / -nouser
查找文件名為passwd的這個文件
find / -name passwd
查找文件類型為socket的文件
find / -type s
14、磁盤和目錄的容量
df:列出文件系統的整體磁盤使用量
du:評估文件系統的磁盤使用量
15 創建鏈接文件
ln [-sf] 源文件 目標文件
-s :創建軟連接,如果不加則是硬連接
-f:如果目標文件存在,則刪除后再建
[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]#
運行上面的命令行,相信你對ln的使用會非常清楚的。
15、掛載CD

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