Linux常用命令總結

  1. 觀察linux系統(tǒng)上虛擬內(nèi)存的當前狀態(tài)

    [root@localhost ~]# cat/proc/meminfo
    MemTotal:        1010536 kB
    MemFree:          178716 kB
    MemAvailable:     249504 kB
    Buffers:               0 kB
    Cached:           100180 kB
    SwapCached:        53608 kB
    Active:           206116 kB
    Inactive:         260760 kB
    Active(anon):     171404 kB
    Inactive(anon):   214548 kB
    Active(file):      34712 kB
    Inactive(file):    46212 kB
    Unevictable:           0 kB
    Mlocked:               0 kB
    SwapTotal:       2097148 kB
    SwapFree:        1767952 kB
    Dirty:                72 kB
    Writeback:             0 kB
    AnonPages:        330732 kB
    Mapped:            30380 kB
    Shmem:             19256 kB
    Slab:             223204 kB
    SReclaimable:     142948 kB
    SUnreclaim:        80256 kB
    KernelStack:        7776 kB
    PageTables:        10864 kB
    NFS_Unstable:          0 kB
    Bounce:                0 kB
    WritebackTmp:          0 kB
    CommitLimit:     2602416 kB
    Committed_AS:    1452468 kB
    VmallocTotal:   34359738367 kB
    VmallocUsed:       59056 kB
    VmallocChunk:   34359621948 kB
    HardwareCorrupted:     0 kB
    AnonHugePages:      4096 kB
    HugePages_Total:       0
    HugePages_Free:        0
    HugePages_Rsvd:        0
    HugePages_Surp:        0
    Hugepagesize:       2048 kB
    DirectMap4k:      178112 kB
    DirectMap2M:      870400 kB
    
    
    
  2. 查看系統(tǒng)當前共享內(nèi)存頁面

    [root@localhost ~]# ipcs -m 
    
    ------------共享內(nèi)存段--------------  
    鍵       shmid|      擁有者  權限     字節(jié)     nattch     狀態(tài)      
    0x0112e73f 0          root       600        1000       7                       
    0x0112e742 32769      root       600        1200712    7
    
  3. ls查看文件更多信息

    [root@localhost ~]# ls -l
    總用量 16
    -rw-------.  1 root root 1219 8月   2 08:56 anaconda-ks.cfg
    -rw-r--r--.  1 root root 6140 11月 12 2015 mysql-community-release-el7-5.noarch.rpm
    drwxr-xr-x.  2 root root   21 10月 27 13:07 python3.0
    drwxr-xr-x.  5 root root   64 11月  1 10:23 service
    drwxr-xr-x. 10 root root 4096 10月 19 17:07 web
    
    
  4. 創(chuàng)建文件touch

     [root@localhost ~]# touch test1
     [root@localhost ~]# ls -il test1
     105094843 -rw-r--r--. 1 root  root 0 11月  9 15:53 test1
    

    touch命令創(chuàng)建了你指定的新文件法焰,并將你的用戶名作為文件的屬主鸦难。

  5. 復制文件cp sourece destination

    [root@localhost ~]# cp test1 test2
    [root@localhost ~]# ls -il
    total 0
    105094843 -rw-r--r--.  1 root root    0 11月  9 15:53 test1
    105094844 -rw-r--r--.  1 root root    0 11月  9 16:02 test2
    

    如果目標文件test2存在,那么將覆蓋文件杂曲,如果新文件中和源文件同名难菌,需要用絕對路徑來表示渐夸。

  6. 重名文件

    [root@localhost ~]# mv test1 test3
    [root@localhost ~]# ls -il test*
    105094844 -rw-r--r--. 1 root root 0 11月  9 16:02 test2
    105094843 -rw-r--r--. 1 root root 0 11月  9 15:53 test3
    
  7. 刪除文件

    [root@localhost ~]# rm test2
    rm:是否刪除普通空文件 "test2"嗓蘑?y
    

    注意,提示是否刪除文件虫溜,bash shell中沒有回收站或者垃圾箱,所以一旦刪除颂郎,就無法找回了吼渡。

  8. 創(chuàng)建目錄

    [root@localhost ~]# mkdir dir1
    37353231 drwxr-xr-x.  2 root root    6 11月  9 16:17 dir1
    
    
  9. 刪除目錄

    [root@localhost ~]# rmdir dir1
    

    這個命令刪空文件好用。如果需要刪除則是rm -r dir乓序;刪庫到跑路推薦用rm -rf file。

  10. 查看系統(tǒng)磁盤占用

    [root@localhost ~]# df -h
    文件系統(tǒng)        容量  已用  可用 已用% 掛載點
    /dev/sda2        30G  5.4G   25G   18% /
    devtmpfs        486M     0  486M    0% /dev
    tmpfs           494M   20K  494M    1% /dev/shm
    tmpfs           494M   50M  444M   11% /run
    tmpfs           494M     0  494M    0% /sys/fs/cgroup
    /dev/sda5        95G   33M   95G    1% /home
    /dev/sda1       497M  102M  396M   21% /boot
    
  11. 搜索數(shù)據(jù)

    [root@localhost ~]# grep a test3
    a
    apple
    

    加入函數(shù)可以grep -n a test3

  12. 打包和壓縮文件

    bunzip2 file1.bz2 解壓一個叫做 'file1.bz2'的文件 
    bzip2 file1 壓縮一個叫做 'file1' 的文件 
    gunzip file1.gz 解壓一個叫做 'file1.gz'的文件 
    gzip file1 壓縮一個叫做 'file1'的文件 
    gzip -9 file1 最大程度壓縮 
    rar a file1.rar test_file 創(chuàng)建一個叫做 'file1.rar' 的包 
    rar a file1.rar file1 file2 dir1 同時壓縮 'file1', 'file2' 以及目錄 'dir1' 
    rar x file1.rar 解壓rar包 
    unrar x file1.rar 解壓rar包 
    tar -cvf archive.tar file1 創(chuàng)建一個非壓縮的 tarball 
    tar -cvf archive.tar file1 file2 dir1 創(chuàng)建一個包含了 'file1', 'file2' 以及 'dir1'的檔案文件 
    tar -tf archive.tar 顯示一個包中的內(nèi)容 
    tar -xvf archive.tar 釋放一個包 
    tar -xvf archive.tar -C /tmp 將壓縮包釋放到 /tmp目錄下 
    tar -cvfj archive.tar.bz2 dir1 創(chuàng)建一個bzip2格式的壓縮包 
    tar -xvfj archive.tar.bz2 解壓一個bzip2格式的壓縮包 
    tar -cvfz archive.tar.gz dir1 創(chuàng)建一個gzip格式的壓縮包 
    tar -xvfz archive.tar.gz 解壓一個gzip格式的壓縮包 
    zip file1.zip file1 創(chuàng)建一個zip格式的壓縮包 
    zip -r file1.zip file1 file2 dir1 將幾個文件和目錄同時壓縮成一個zip格式的壓縮包 
    unzip file1.zip 解壓一個zip格式壓縮包 
    
  13. 文件的權限 - 使用 "+" 設置權限坎背,使用 "-" 用于取消

    ls -lh 顯示權限 
    ls /tmp | pr -T5 -W$COLUMNS 將終端劃分成5欄顯示 
    chmod ugo+rwx directory1 設置目錄的所有人(u)替劈、群組(g)以及其他人(o)以讀(r )、寫(w)和執(zhí)行(x)的權限 
    chmod go-rwx directory1 刪除群組(g)與其他人(o)對目錄的讀寫執(zhí)行權限 
    chown user1 file1 改變一個文件的所有人屬性 
    chown -R user1 directory1 改變一個目錄的所有人屬性并同時改變改目錄下所有文件的屬性 
    chgrp group1 file1 改變文件的群組 
    chown user1:group1 file1 改變一個文件的所有人和群組屬性 
    find / -perm -u+s 羅列一個系統(tǒng)中所有使用了SUID控制的文件 
    chmod u+s /bin/file1 設置一個二進制文件的 SUID 位 - 運行該文件的用戶也被賦予和所有者同樣的權限 
    chmod u-s /bin/file1 禁用一個二進制文件的 SUID位 
    chmod g+s /home/public 設置一個目錄的SGID 位 - 類似SUID 得滤,不過這是針對目錄的 
    chmod g-s /home/public 禁用一個目錄的 SGID 位 
    chmod o+t /home/public 設置一個文件的 STIKY 位 - 只允許合法所有人刪除文件 
    chmod o-t /home/public 禁用一個目錄的 STIKY 位 
    
  14. 文本處理

    cat file1 file2 ... | command <> file1_in.txt_or_file1_out.txt general syntax for text manipulation using PIPE, STDIN and STDOUT 
    cat file1 | command( sed, grep, awk, grep, etc...) > result.txt 合并一個文件的詳細說明文本陨献,并將簡介寫入一個新文件中 
    cat file1 | command( sed, grep, awk, grep, etc...) >> result.txt 合并一個文件的詳細說明文本,并將簡介寫入一個已有的文件中 
    grep Aug /var/log/messages 在文件 '/var/log/messages'中查找關鍵詞"Aug" 
    grep ^Aug /var/log/messages 在文件 '/var/log/messages'中查找以"Aug"開始的詞匯 
    grep [0-9] /var/log/messages 選擇 '/var/log/messages' 文件中所有包含數(shù)字的行 
    grep Aug -R /var/log/* 在目錄 '/var/log' 及隨后的目錄中搜索字符串"Aug" 
    sed 's/stringa1/stringa2/g' example.txt 將example.txt文件中的 "string1" 替換成 "string2" 
    sed '/^$/d' example.txt 從example.txt文件中刪除所有空白行 
    sed '/ *#/d; /^$/d' example.txt 從example.txt文件中刪除所有注釋和空白行 
    echo 'esempio' | tr '[:lower:]' '[:upper:]' 合并上下單元格內(nèi)容 
    sed -e '1d' result.txt 從文件example.txt 中排除第一行 
    sed -n '/stringa1/p' 查看只包含詞匯 "string1"的行 
    sed -e 's/ *$//' example.txt 刪除每一行最后的空白字符 
    sed -e 's/stringa1//g' example.txt 從文檔中只刪除詞匯 "string1" 并保留剩余全部 
    sed -n '1,5p;5q' example.txt 查看從第一行到第5行內(nèi)容 
    sed -n '5p;5q' example.txt 查看第5行 
    sed -e 's/00*/0/g' example.txt 用單個零替換多個零 
    cat -n file1 標示文件的行數(shù) 
    cat example.txt | awk 'NR%2==1' 刪除example.txt文件中的所有偶數(shù)行 
    echo a b c | awk '{print $1}' 查看一行第一欄 
    echo a b c | awk '{print $1,$3}' 查看一行的第一和第三欄 
    paste file1 file2 合并兩個文件或兩欄的內(nèi)容 
    paste -d '+' file1 file2 合并兩個文件或兩欄的內(nèi)容懂更,中間用"+"區(qū)分 
    sort file1 file2 排序兩個文件的內(nèi)容 
    sort file1 file2 | uniq 取出兩個文件的并集(重復的行只保留一份) 
    sort file1 file2 | uniq -u 刪除交集眨业,留下其他的行 
    sort file1 file2 | uniq -d 取出兩個文件的交集(只留下同時存在于兩個文件中的文件) 
    comm -1 file1 file2 比較兩個文件的內(nèi)容只刪除 'file1' 所包含的內(nèi)容 
    comm -2 file1 file2 比較兩個文件的內(nèi)容只刪除 'file2' 所包含的內(nèi)容 
    comm -3 file1 file2 比較兩個文件的內(nèi)容只刪除兩個文件共有的部分 
    
  15. 網(wǎng)絡

    ifconfig eth0 顯示一個以太網(wǎng)卡的配置 
    ifup eth0 啟用一個 'eth0' 網(wǎng)絡設備 
    ifdown eth0 禁用一個 'eth0' 網(wǎng)絡設備 
    ifconfig eth0 192.168.1.1 netmask 255.255.255.0 控制IP地址 
    ifconfig eth0 promisc 設置 'eth0' 成混雜模式以嗅探數(shù)據(jù)包 (sniffing) 
    dhclient eth0 以dhcp模式啟用 'eth0' 
    route -n show routing table 
    route add -net 0/0 gw IP_Gateway configura default gateway 
    route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1 configure static route to reach network '192.168.0.0/16' 
    route del 0/0 gw IP_gateway remove static route 
    echo "1" > /proc/sys/net/ipv4/ip_forward activate ip routing 
    hostname show hostname of system 
    host www.example.com lookup hostname to resolve name to ip address and viceversa(1) 
    nslookup www.example.com lookup hostname to resolve name to ip address and viceversa(2) 
    ip link show show link status of all interfaces 
    mii-tool eth0 show link status of 'eth0' 
    ethtool eth0 show statistics of network card 'eth0' 
    netstat -tup show all active network connections and their PID 
    netstat -tupl show all network services listening on the system and their PID 
    tcpdump tcp port 80 show all HTTP traffic 
    iwlist scan show wireless networks 
    iwconfig eth1 show configuration of a wireless network card 
    hostname show hostname 
    host www.example.com lookup hostname to resolve name to ip address and viceversa 
    nslookup www.example.com lookup hostname to resolve name to ip address and viceversa 
    whois www.example.com lookup on Whois database 
    
最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市沮协,隨后出現(xiàn)的幾起案子龄捡,更是在濱河造成了極大的恐慌,老刑警劉巖慷暂,帶你破解...
    沈念sama閱讀 221,430評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件聘殖,死亡現(xiàn)場離奇詭異,居然都是意外死亡行瑞,警方通過查閱死者的電腦和手機奸腺,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,406評論 3 398
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來血久,“玉大人突照,你說我怎么就攤上這事⊙跬拢” “怎么了讹蘑?”我有些...
    開封第一講書人閱讀 167,834評論 0 360
  • 文/不壞的土叔 我叫張陵,是天一觀的道長副砍。 經(jīng)常有香客問我衔肢,道長,這世上最難降的妖魔是什么豁翎? 我笑而不...
    開封第一講書人閱讀 59,543評論 1 296
  • 正文 為了忘掉前任角骤,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘邦尊。我一直安慰自己背桐,他們只是感情好,可當我...
    茶點故事閱讀 68,547評論 6 397
  • 文/花漫 我一把揭開白布蝉揍。 她就那樣靜靜地躺著链峭,像睡著了一般。 火紅的嫁衣襯著肌膚如雪又沾。 梳的紋絲不亂的頭發(fā)上弊仪,一...
    開封第一講書人閱讀 52,196評論 1 308
  • 那天,我揣著相機與錄音杖刷,去河邊找鬼励饵。 笑死,一個胖子當著我的面吹牛滑燃,可吹牛的內(nèi)容都是我干的役听。 我是一名探鬼主播,決...
    沈念sama閱讀 40,776評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼表窘,長吁一口氣:“原來是場噩夢啊……” “哼典予!你這毒婦竟也來了?” 一聲冷哼從身側響起乐严,我...
    開封第一講書人閱讀 39,671評論 0 276
  • 序言:老撾萬榮一對情侶失蹤瘤袖,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后麦备,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體孽椰,經(jīng)...
    沈念sama閱讀 46,221評論 1 320
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,303評論 3 340
  • 正文 我和宋清朗相戀三年凛篙,在試婚紗的時候發(fā)現(xiàn)自己被綠了黍匾。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,444評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡呛梆,死狀恐怖锐涯,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情填物,我是刑警寧澤纹腌,帶...
    沈念sama閱讀 36,134評論 5 350
  • 正文 年R本政府宣布,位于F島的核電站滞磺,受9級特大地震影響升薯,放射性物質發(fā)生泄漏。R本人自食惡果不足惜击困,卻給世界環(huán)境...
    茶點故事閱讀 41,810評論 3 333
  • 文/蒙蒙 一涎劈、第九天 我趴在偏房一處隱蔽的房頂上張望广凸。 院中可真熱鬧,春花似錦蛛枚、人聲如沸谅海。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,285評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽扭吁。三九已至,卻和暖如春盲镶,著一層夾襖步出監(jiān)牢的瞬間侥袜,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,399評論 1 272
  • 我被黑心中介騙來泰國打工徒河, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留系馆,地道東北人。 一個月前我還...
    沈念sama閱讀 48,837評論 3 376
  • 正文 我出身青樓顽照,卻偏偏與公主長得像,于是被迫代替她去往敵國和親闽寡。 傳聞我的和親對象是個殘疾皇子代兵,可洞房花燭夜當晚...
    茶點故事閱讀 45,455評論 2 359

推薦閱讀更多精彩內(nèi)容

  • 系統(tǒng) arch 顯示機器的處理器架構(1) uname -m 顯示機器的處理器架構(2) uname -r 顯示正...
    莎楽哥哥鴨閱讀 764評論 1 51
  • 最近都在和Linux打交道,這方面基礎比較薄弱的我只好買了本鳥哥的書看看爷狈,感覺還不錯植影。我覺得Linux相比wind...
    blvftigd閱讀 782評論 0 0
  • centos7 常用命令管理centos服務器的時候常會對文件進行一些常規(guī)操作,除了ftp之外了解在ssh下必要的...
    小線亮亮閱讀 1,198評論 0 2
  • 系統(tǒng)信息 arch 顯示機器的處理器架構(1) uname -m 顯示機器的處理器架構(2) uname -r 顯...
    muyang_js的簡書閱讀 405評論 0 2
  • 一朵花 你說是詩 我說是畫 于是—— 一朵花 你入詩 我作畫 所以—— 一朵花 花是詩 花是畫 所以—— 一朵花 ...
    葉知春_eb10閱讀 213評論 0 0