前面的章節裡對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::查看壓縮包中又哪些檔案