天天看點

Linux基礎指令--常用指令工具

1 cd 切換工作目錄

[root@localhost ~]# cd /usr/local/    #切換到目錄/usr/local下

[root@localhost local]# cd ..       #切換到上一級目錄

[root@localhost usr]# cd -        #傳回到/usr/local下

/usr/local                

2 touch 建立或修改檔案

[root@localhost ~]# touch test.txt

在目前目錄下,若果不存在test.txt,就直接建立;若果存在,則是更新檔案時間

3 mkdir 建立目錄

[root@localhost ~]# mkdir game        #建立目錄game

[root@localhost ~]# mkdir -p /home/test/game  #建立多級目錄

[root@localhost ~]# mkdir test gamek hello   #建立多個目錄

4 pwd 顯示目前路徑

[root@localhost test]# pwd

/home/test                   #傳回目前工作目錄

5 ls 顯示目錄和檔案資訊

[root@localhost game]# ls            #顯示目前目錄和檔案的名稱

[root@localhost game]# ls -a           #顯示包含的隐藏檔案

[root@localhost game]# ls -l           #顯示檔案和目錄的詳細資訊

[root@localhost game]# ls -lh          #顯示容量資訊

[root@localhost game]# ls -ld /home        #檢視目前home目錄自身的詳細資訊

[root@localhost game]# ls -lt          #檢視有時間排序的詳細資訊

[root@localhost game]# ls -lu           #顯示最後到訪時間

[root@localhost game]# ls -lc           #顯示屬性變更的時間

6 mv 移動或者重命名目錄和檔案

[root@localhost ~]# mv test.txt text.py     #将text.py 改名為text.py

[root@localhost ~]# mv text.py /home/      #将text.py移動至/home下

7 cp 複制檔案和目錄

[root@localhost ~]# cp /etc/passwd /home/    #複制passwd到/home下

[root@localhost ~]# cp /etc/passwd /home/pass   #複制passwd到/home下改名為pass

[root@localhost ~]# cp -r /home/logs /tmp/    #複制子檔案和目錄到/tmp/下

8 rm 删除

[root@localhost ~]# rm test        #删除test

[root@localhost ~]# rm -rf test      #徹底删除且不提示

9 du 顯示檔案和目錄的容量

[root@localhost ~]# du -sh /home     #檢視/home所占用的空間

10 df 所有檔案系統的使用情況

[root@localhost ~]# df -a        #檢視分區及使用情況

[root@localhost ~]# df -i        #檢視分區iNode使用情況

[root@localhost ~]# df -h        #帶機關顯示使用情況

11 cat 檢視檔案内容

[root@localhost ~]# cat -b /home/passwd  #顯示行号,空白行不顯示

[root@localhost ~]# cat -n /home/passwd  #顯示行号,包括空白行 

12 more 分頁檢視 

[root@localhost ~]# more /tmp.log      #分頁檢視,空格看下一頁,q退出

13 less 分頁檢視

[root@localhost ~]# less /tmp.log     #分頁檢視,空格看下頁,方向鍵可翻頁,q退出

14 head 檢視檔案頭部,預設顯示前10行

[root@localhost ~]# head -c 10k /tmp.log    #檢視前10k的内容

[root@localhost ~]# head -20 /tmp.log      #檢視前20行内容

15 tail 檢視檔案尾部 預設最後10行

[root@localhost ~]# tail -c 10k /tmp.log     #檢視尾部10k的内容

[root@localhost ~]# tail -20 /tmp.log       #檢視後20行

[root@localhost ~]# tail -f /tmp.log       #動态檢視

16 wc 統計行資訊

[root@localhost ~]# wc -c /tmp.log        #統計位元組數

[root@localhost ~]# wc -l /tmp.log        #統計行數

[root@localhost ~]# wc -w /tmp.log        #統計單詞數

17 uptime 檢視目前時間 系統運作時長 目前使用者 平均負載

[root@localhost ~]# uptime

04:03:58 up 10 days, 13:19, 1 user, load average: 0.54, 0.40, 0.20

目前時間 04:03:58

系統已運作的時間 10 days, 13:19

目前線上使用者 1 user

平均負載:0.54, 0.40, 0.20,最近1分鐘、5分鐘、15分鐘系統的負載

18 free 檢視系統記憶體及交換分區資訊

free -b|-k|-m (容量機關)

[root@localhost ~]# free

total used free shared buffers cached  

Mem: 3266180 3250004 16176 0 110652 2668236  

-/+ buffers/cache: 471116 2795064  

Swap: 2048276 80160 1968116 

本文轉自super李導51CTO部落格,原文連結: http://blog.51cto.com/superleedo/1886113,如需轉載請自行聯系原作者

繼續閱讀