day18 - 玩轉Linux操做系統

玩轉Linux操做系統

操做系統發展史

只有硬件沒有軟件的計算機系統被稱之爲「裸機」,咱們很難用「裸機」來完成計算機平常的工做(如存儲和運算),因此必須用特定的軟件來控制硬件的工做。最靠近計算機硬件的軟件是系統軟件,其中最爲重要的就是「操做系統」。「操做系統」是控制和管理整個計算機系統的硬件和軟件資源,合理的分配資源和調配任務,爲系統用戶和其餘軟件提供接口和環境的程序的集合。javascript

沒有操做系統(手工操做)

在計算機誕生之初沒有操做系統的年代,人們先把程序紙帶(或卡片)裝上計算機,而後啓動輸入機把程序和送入計算機,接着經過控制檯開關啓動程序運行。當程序執行完畢,打印機輸出計算的結果,用戶卸下並取走紙帶(或卡片)。第二個用戶上機,重複一樣的步驟。在整個過程當中用戶獨佔機器,CPU等待手工操做,資源利用率極低。下圖是IBM生產的書寫Fortran程序的80欄打孔卡,固然這個已是比較先進的打孔卡了。html

批處理系統

首先啓動計算機上的一個監督程序,在監督程序的控制下,計算機可以自動的、成批的處理一個或多個用戶的做業。完成一批做業後,監督程度又從輸入機讀取做業存入磁帶機。按照上面的步驟重複處理任務。監督程序不停的處理各個做業,實現了做業的自動轉接,減小了做業的創建時間和手工操做時間,提升了計算機資源的利用率。 批處理系統又能夠分爲單道批處理系統、多道批處理系統、聯機批處理系統、脫機批處理系統。html5

分時系統和實時系統

分時系統是把處理器的運行時間分紅很短的時間片,按時間片輪流把處理機分配給各聯機做業使用。 若某個做業在分配給它的時間片內不能完成其計算,則該做業暫時中斷,把處理機讓給另外一做業使用,等待下一輪調度時再繼續其運行。因爲計算機速度很快,做業運行輪轉得很快,給每一個用戶的感受是他獨佔了一臺計算機。而每一個用戶能夠經過本身的終端向系統發出各類操做控制命令,在充分的人機交互狀況下,完成做業的運行。爲了解決分時系統不能及時響應用戶指令的狀況,又出現了可以在在嚴格的時間範圍內完成事件處理,及時響應隨機外部事件的實時系統。java

通用操做系統

  1. 1960s:IBM的System/360系列的機器有了統一的操做系統OS/360。python

  2. 1965年:AT&T的貝爾實驗室加入GE和MIT的合做計劃開始開發MULTICS。mysql

  3. 1969年:Ken Tompson爲了玩「Space Travel」遊戲用匯編語言在PDP-7上開發了Unics。linux

  4. 1970年~1971年:Ken Tompson和Dennis Ritchie用B語言在PDP-11上重寫了Unics,並在Brian Kernighan的建議下將其改名爲Unix。ios

  5. 1972年~1973年:Dennis Ritchie發明了C語言來取代可移植性較差的B語言,並開啓了用C語言重寫Unix的工做。nginx

  6. 1974年:Unix推出了里程碑意義的第5版,幾乎徹底用C語言來實現。git

  7. 1979年:從Unix第7版開始,AT&T發佈新的使用條款,將Unix私有化。

  8. 1987年:Andrew S. Tanenbaum教授爲了能在課堂上教授學生操做系統運做的細節,決定在不使用任何AT&T的源代碼前提下,自行開發與Unix兼容的操做系統,以免版權上的爭議並將其命名爲Minix。

  9. 1991年:Linus Torvalds就讀於芬蘭赫爾辛基大學期間,嘗試在Minix上作一些開發工做,但由於Minix只是做爲教學用途的操做系統,功能並不強大,爲了方便在學校的主機的新聞組和郵件系統中讀寫和下載文件,Linus編寫了磁盤驅動程序和文件系統,這些成爲了Linux系統內核的雛形。

下圖是Unix操做系統家族的圖譜。

Linux概述

Linux是一個通用操做系統。一個操做系統要負責任務調度、內存分配、處理外圍設備I/O等操做。操做系統一般由內核(運行其餘程序,管理像磁盤、打印機等硬件設備的核心程序)和系統程序(設備驅動、底層庫、shell、服務程序等)兩部分組成。

Linux內核是芬蘭人Linus Torvalds開發的,於1991年9月發佈。而Linux操做系統做爲Internet時代的產物,它是由全世界許多開發者共同合做開發的,是一個自由的操做系統(注意自由和免費並非同一個概念,想了解兩者的差異能夠點擊這裏)。

Linux系統優勢

  1. 通用操做系統,不跟特定的硬件綁定。
  2. 用C語言編寫,有可移植性,有內核編程接口。
  3. 支持多用戶和多任務,支持安全的分層文件系統。
  4. 大量的實用程序,完善的網絡功能以及強大的支持文檔。
  5. 可靠的安全性和良好的穩定性,對開發者更友好。

Linux系統發行版本

  1. Redhat
  2. Ubuntu
  3. CentOS
  4. Fedora
  5. Debian
  6. openSUSE

基礎命令

Linux系統的命令一般都是以下所示的格式:

命令名稱 [命名參數] [命令對象]
  1. 獲取登陸信息 - w / who / last。

    [root@izwz97tbgo9lkabnat2lo8z ~]# w 23:31:16 up 12:16, 2 users, load average: 0.00, 0.01, 0.05 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root pts/0 182.139.66.250 23:03 4.00s 0.02s 0.00s w jackfrue pts/1 182.139.66.250 23:26 3:56 0.00s 0.00s -bash [root@izwz97tbgo9lkabnat2lo8z ~]# who root pts/0 2018-04-12 23:03 (182.139.66.250) jackfrued pts/1 2018-04-12 23:26 (182.139.66.250) [root@izwz97tbgo9lkabnat2lo8z ~]# who am i root pts/0 2018-04-12 23:03 (182.139.66.250)
  2. 查看本身使用的Shell - ps。

    Shell也被稱爲「殼」,它是用戶與內核交流的翻譯官,簡單的說就是人與計算機交互的接口。目前不少Linux系統默認的Shell都是bash(Bourne Again SHell),由於它可使用Tab鍵進行命令補全、能夠保存歷史命令、能夠方便的配置環境變量以及執行批處理操做等。

    [root@izwz97tbgo9lkabnat2lo8z ~]# ps PID TTY TIME CMD 3531 pts/0 00:00:00 bash 3553 pts/0 00:00:00 ps
  3. 查看命令的說明 - whatis。

    [root@izwz97tbgo9lkabnat2lo8z ~]# whatis ps ps (1) - report a snapshot of the current processes. [root@izwz97tbgo9lkabnat2lo8z ~]# whatis python python (1) - an interpreted, interactive, object-oriented programming language
  4. 查看命令的位置 - which / whereis。

    [root@izwz97tbgo9lkabnat2lo8z ~]# whereis ps ps: /usr/bin/ps /usr/share/man/man1/ps.1.gz [root@izwz97tbgo9lkabnat2lo8z ~]# whereis python python: /usr/bin/python /usr/bin/python2.7 /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /usr/share/man/man1/python.1.gz [root@izwz97tbgo9lkabnat2lo8z ~]# which ps /usr/bin/ps [root@izwz97tbgo9lkabnat2lo8z ~]# which python /usr/bin/python
  5. 查看幫助文檔 - man / info / apropos。

    [root@izwz97tbgo9lkabnat2lo8z ~]# ps --help Usage: ps [options] Try 'ps --help <simple|list|output|threads|misc|all>' or 'ps --help <s|l|o|t|m|a>' for additional help text. For more details see ps(1). [root@izwz97tbgo9lkabnat2lo8z ~]# man ps PS(1) User Commands PS(1) NAME ps - report a snapshot of the current processes. SYNOPSIS ps [options] DESCRIPTION ... [root@izwz97tbgo9lkabnat2lo8z ~]# info ps ...
  6. 切換用戶 - su。

    [root@izwz97tbgo9lkabnat2lo8z ~]# su hellokitty [hellokitty@izwz97tbgo9lkabnat2lo8z root]$
  7. 以管理員身份執行命令 - sudo。

    [jackfrued@izwz97tbgo9lkabnat2lo8z ~]$ ls /root
    ls: cannot open directory /root: Permission denied
    [jackfrued@izwz97tbgo9lkabnat2lo8z ~]$ sudo ls /root [sudo] password for jackfrued: calendar.py code error.txt hehe hello.c index.html myconf result.txt

    說明:若是但願用戶可以以管理員身份執行命令,用戶必須被添加到sudoers名單中,該文件在 /etc目錄下。

  8. 登入登出相關 - logout / exit / adduser / userdel / passwd / ssh。

    [root@izwz97tbgo9lkabnat2lo8z ~]# adduser hellokitty [root@izwz97tbgo9lkabnat2lo8z ~]# passwd hellokitty Changing password for user jackfrued. New password: Retype new password: passwd: all authentication tokens updated successfully. [root@izwz97tbgo9lkabnat2lo8z ~]# ssh hellokitty@1.2.3.4 hellokitty@1.2.3.4's password: Last login: Thu Apr 12 23:05:32 2018 from 10.12.14.16 [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ logout Connection to 1.2.3.4 closed. [root@izwz97tbgo9lkabnat2lo8z ~]#
  9. 查看系統和主機名 - uname / hostname。

    [root@izwz97tbgo9lkabnat2lo8z ~]# uname Linux [root@izwz97tbgo9lkabnat2lo8z ~]# hostname izwz97tbgo9lkabnat2lo8z [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat /etc/centos-release CentOS Linux release 7.4.1708 (Core) 
  10. 重啓和關機 - reboot / init 6 / shutdown / init 0。

  11. 查看歷史命令 - history。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# history ... 452 ls 453 cd Python-3.6.5/ 454 clear 455 history [root@iZwz97tbgo9lkabnat2lo8Z ~]# !454

    說明:查看到歷史命令以後,能夠用!歷史命令編號來從新執行該命令;經過history -c能夠清除歷史命令。

實用程序

文件和文件夾操做

  1. 建立/刪除目錄 - mkdir / rmdir。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# mkdir abc [root@iZwz97tbgo9lkabnat2lo8Z ~]# mkdir -p xyz/abc [root@iZwz97tbgo9lkabnat2lo8Z ~]# rmdir abc
  2. 建立/刪除文件 - touch / rm。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# touch readme.txt [root@iZwz97tbgo9lkabnat2lo8Z ~]# touch error.txt [root@iZwz97tbgo9lkabnat2lo8Z ~]# rm error.txt rm: remove regular empty file ‘error.txt’? y [root@iZwz97tbgo9lkabnat2lo8Z ~]# rm -rf xyz
    • touch命令用於建立空白文件或修改文件時間。在Linux系統中一個文件有三種時間:
      • 更改內容的時間 - mtime。
      • 更改權限的時間 - ctime。
      • 最後訪問時間 - atime。
    • rm的幾個重要參數:
      • -i:交互式刪除,每一個刪除項都會進行詢問。
      • -r:刪除目錄並遞歸的刪除目錄中的文件和目錄。
      • -f:強制刪除,忽略不存在的文件,沒有任何提示。
  3. 切換和查看當前工做目錄 - cd / pwd。

    說明:cd命令後面能夠跟相對路徑(以當前路徑做爲參照)或絕對路徑(以/開頭)來切換到指定的目錄,也能夠用cd ..來返回上一級目錄。

  4. 查看目錄內容 - ls。

    • -l:以長格式查看文件和目錄。
    • -a:顯示以點開頭的文件和目錄(隱藏文件)。
    • -R:遇到目錄要進行遞歸展開(繼續列出目錄下面的文件和目錄)。
    • -d:只列出目錄,不列出其餘內容。
    • -S/-t:按大小/時間排序。
  5. 查看文件內容 - cat / head / tail / more / less。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# wget http://www.sohu.com/ -O sohu.html --2018-06-20 18:42:34-- http://www.sohu.com/ Resolving www.sohu.com (www.sohu.com)... 14.18.240.6 Connecting to www.sohu.com (www.sohu.com)|14.18.240.6|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 212527 (208K) [text/html] Saving to: ‘sohu.html’ 100%[==================================================>] 212,527 --.-K/s in 0.03s 2018-06-20 18:42:34 (7.48 MB/s) - ‘sohu.html’ saved [212527/212527] [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat sohu.html ... [root@iZwz97tbgo9lkabnat2lo8Z ~]# head -10 sohu.html <!DOCTYPE html> <html> <head> <title>搜狐</title> <meta name="Keywords" content="搜狐,門戶網站,新媒體,網絡媒體,新聞,財經,體育,娛樂,時尚,汽車,房產,科技,圖片,論壇,微博,博客,視頻,電影,電視劇"/> <meta name="Description" content="搜狐網爲用戶提供24小時不間斷的最新資訊,及搜索、郵件等網絡服務。內容包括全球熱點事件、突發新聞、時事評論、熱播影視劇、體育賽事、行業動態、生活服務信息,以及論壇、博客、微博、個人搜狐等互動空間。" /> <meta name="shenma-site-verification" content="1237e4d02a3d8d73e96cbd97b699e9c3_1504254750"> <meta charset="utf-8"/> <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"/> [root@iZwz97tbgo9lkabnat2lo8Z ~]# tail -2 sohu.html </body> </html> [root@iZwz97tbgo9lkabnat2lo8Z ~]# less sohu.html ... [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat -n sohu.html | more ...
  6. 拷貝/移動文件 - cp / mv。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# mkdir backup [root@iZwz97tbgo9lkabnat2lo8Z ~]# cp sohu.html backup/ [root@iZwz97tbgo9lkabnat2lo8Z ~]# cd backup [root@iZwz97tbgo9lkabnat2lo8Z backup]# ls sohu.html [root@iZwz97tbgo9lkabnat2lo8Z backup]# mv sohu.html sohu_index.html [root@iZwz97tbgo9lkabnat2lo8Z backup]# ls sohu_index.html
  7. 查找文件和查找內容 - find / grep。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# find / -name "*.html" /root/sohu.html /root/backup/sohu_index.html [root@izwz97tbgo9lkabnat2lo8z ~]# find . -atime 7 -type f -print [root@izwz97tbgo9lkabnat2lo8z ~]# find . -type f -size +2k [root@izwz97tbgo9lkabnat2lo8z ~]# find . -type f -name "*.swp" -delete [root@iZwz97tbgo9lkabnat2lo8Z ~]# grep "<script>" sohu.html -n 20:<script> [root@iZwz97tbgo9lkabnat2lo8Z ~]# grep -E \<\/?script.*\> sohu.html -n 20:<script> 22:</script> 24:<script src="//statics.itc.cn/web/v3/static/js/es5-shim-08e41cfc3e.min.js"></script> 25:<script src="//statics.itc.cn/web/v3/static/js/es5-sham-1d5fa1124b.min.js"></script> 26:<script src="//statics.itc.cn/web/v3/static/js/html5shiv-21fc8c2ba6.js"></script> 29:<script type="text/javascript"> 52:</script> ...

    說明:grep在搜索字符串時可使用正則表達式,若是須要使用正則表達式能夠用grep -E或者直接使用egrep

  8. 連接 - ln。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l sohu.html -rw-r--r-- 1 root root 212131 Jun 20 19:15 sohu.html [root@iZwz97tbgo9lkabnat2lo8Z ~]# ln /root/sohu.html /root/backup/sohu_backup [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l sohu.html -rw-r--r-- 2 root root 212131 Jun 20 19:15 sohu.html [root@iZwz97tbgo9lkabnat2lo8Z ~]# ln /root/sohu.html /root/backup/sohu_backup2 [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l sohu.html -rw-r--r-- 3 root root 212131 Jun 20 19:15 sohu.html [root@iZwz97tbgo9lkabnat2lo8Z ~]# ln -s /etc/centos-release sysinfo [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l sysinfo lrwxrwxrwx 1 root root 19 Jun 20 19:21 sysinfo -> /etc/centos-release [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat sysinfo CentOS Linux release 7.4.1708 (Core) [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat /etc/centos-release CentOS Linux release 7.4.1708 (Core)

    說明:連接能夠分爲硬連接和軟連接(符號連接)。硬連接能夠認爲是一個指向文件數據的指針,就像Python中對象的引用計數,每添加一個硬連接,文件的對應連接數就增長1,只有當文件的連接數爲0時,文件所對應的存儲空間纔有可能被其餘文件覆蓋。咱們日常刪除文件時其實並無刪除硬盤上的數據,咱們刪除的只是一個指針,或者說是數據的一條使用記錄,因此相似於「文件粉碎機」之類的軟件在「粉碎」文件時除了刪除文件指針,還會在文件對應的存儲區域填入數據來保證文件沒法再恢復。軟連接相似於Windows系統下的快捷方式,當軟連接連接的文件被刪除時,軟連接也就失效了。

  9. 壓縮/解壓縮和歸檔/解歸檔 - gzip / gunzip / xz / tar。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# wget http://download.redis.io/releases/redis-4.0.10.tar.gz --2018-06-20 19:29:59-- http://download.redis.io/releases/redis-4.0.10.tar.gz Resolving download.redis.io (download.redis.io)... 109.74.203.151 Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 1738465 (1.7M) [application/x-gzip] Saving to: ‘redis-4.0.10.tar.gz’ 100%[==================================================>] 1,738,465 70.1KB/s in 74s 2018-06-20 19:31:14 (22.9 KB/s) - ‘redis-4.0.10.tar.gz’ saved [1738465/1738465] [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls redis* redis-4.0.10.tar.gz [root@iZwz97tbgo9lkabnat2lo8Z ~]# gunzip redis-4.0.10.tar.gz [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls redis* redis-4.0.10.tar [root@iZwz97tbgo9lkabnat2lo8Z ~]# tar -xvf redis-4.0.10.tar redis-4.0.10/ redis-4.0.10/.gitignore redis-4.0.10/00-RELEASENOTES redis-4.0.10/BUGS redis-4.0.10/CONTRIBUTING redis-4.0.10/COPYING redis-4.0.10/INSTALL redis-4.0.10/MANIFESTO redis-4.0.10/Makefile redis-4.0.10/README.md redis-4.0.10/deps/ redis-4.0.10/deps/Makefile redis-4.0.10/deps/README.md ... [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls redis* redis-4.0.10.tar redis-4.0.10: 00-RELEASENOTES COPYING Makefile redis.conf runtest-sentinel tests BUGS deps MANIFESTO runtest sentinel.conf utils CONTRIBUTING INSTALL README.md runtest-cluster src
  10. 其餘工具 - sort / uniq / diff / tr / cut / paste / file / wc。

[root@iZwz97tbgo9lkabnat2lo8Z ~]# cat foo.txt grape apple pitaya [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat bar.txt 100 200 300 400 [root@iZwz97tbgo9lkabnat2lo8Z ~]# paste foo.txt bar.txt grape 100 apple 200 pitaya 300 400 [root@iZwz97tbgo9lkabnat2lo8Z ~]# paste foo.txt bar.txt > hello.txt [root@iZwz97tbgo9lkabnat2lo8Z ~]# cut -b 4-8 hello.txt pe 10 le 20 aya 3 0 [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat hello.txt | tr '\t' ',' grape,100 apple,200 pitaya,300 ,400 [root@iZwz97tbgo9lkabnat2lo8Z ~]# wget https://www.baidu.com/img/bd_logo1.png --2018-06-20 18:46:53-- https://www.baidu.com/img/bd_logo1.png Resolving www.baidu.com (www.baidu.com)... 220.181.111.188, 220.181.112.244 Connecting to www.baidu.com (www.baidu.com)|220.181.111.188|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 7877 (7.7K) [image/png] Saving to: ‘bd_logo1.png’ 100%[==================================================>] 7,877 --.-K/s in 0s 2018-06-20 18:46:53 (118 MB/s) - ‘bd_logo1.png’ saved [7877/7877][root@iZwz97tbgo9lkabnat2lo8Z ~]# file bd_logo1.png bd_logo1.png: PNG image data, 540 x 258, 8-bit colormap, non-interlaced [root@iZwz97tbgo9lkabnat2lo8Z ~]# wc sohu.html 2979 6355 212527 sohu.html [root@iZwz97tbgo9lkabnat2lo8Z ~]# wc -l sohu.html 2979 sohu.html

管道和重定向

  1. 管道的使用 - |。

    例子:查找當前目錄下文件個數。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# find ./ | wc -l 6152

    例子:列出當前路徑下的文件和文件夾,給每一項加一個編號。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls | cat -n 1 dump.rdb 2 mongodb-3.6.5 3 Python-3.6.5 4 redis-3.2.11 5 redis.conf

    例子:查找record.log中包含AAA,但不包含BBB的記錄的總數

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat record.log | grep AAA | grep -v BBB | wc -l
  2. 輸出重定向和錯誤重定向 - > / >> / 2>。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat readme.txt banana apple grape apple grape watermelon pear pitaya [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat readme.txt | sort | uniq > result.txt [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat result.txt apple banana grape pear pitaya watermelon
  3. 輸入重定向 - <。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# echo 'hello, world!' > hello.txt [root@iZwz97tbgo9lkabnat2lo8Z ~]# wall < hello.txt [root@iZwz97tbgo9lkabnat2lo8Z ~]# Broadcast message from root@iZwz97tbgo9lkabnat2lo8Z (Wed Jun 20 19:43:05 2018): hello, world! [root@iZwz97tbgo9lkabnat2lo8Z ~]# echo 'I will show you some code.' >> hello.txt [root@iZwz97tbgo9lkabnat2lo8Z ~]# wall < hello.txt [root@iZwz97tbgo9lkabnat2lo8Z ~]# Broadcast message from root@iZwz97tbgo9lkabnat2lo8Z (Wed Jun 20 19:43:55 2018): hello, world! I will show you some code.

別名

  1. alias

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# alias ll='ls -l' [root@iZwz97tbgo9lkabnat2lo8Z ~]# alias frm='rm -rf' [root@iZwz97tbgo9lkabnat2lo8Z ~]# ll ... drwxr-xr-x 2 root root 4096 Jun 20 12:52 abc ... [root@iZwz97tbgo9lkabnat2lo8Z ~]# frm abc
  2. unalias

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# unalias frm [root@iZwz97tbgo9lkabnat2lo8Z ~]# frm sohu.html -bash: frm: command not found

其餘程序

  1. 時間和日期 - date / cal。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# date Wed Jun 20 12:53:19 CST 2018 [root@iZwz97tbgo9lkabnat2lo8Z ~]# cal June 2018 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 [root@iZwz97tbgo9lkabnat2lo8Z ~]# cal 5 2017 May 2017 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
  2. 錄製操做腳本 - script。

  3. 給用戶發送消息 - mesg / write / wall / mail。

文件系統

文件和路徑

  1. 命名規則:文件名的最大長度與文件系統類型有關,通常狀況下,文件名不該該超過255個字符,雖然絕大多數的字符均可以用於文件名,可是最好使用英文大小寫字母、數字、下劃線、點這樣的符號。文件名中雖然可使用空格,但應該儘量避免使用空格,不然在輸入文件名時須要用將文件名放在雙引號中或者經過\對空格進行轉義。
  2. 擴展名:在Linux系統下文件的擴展名是可選的,可是使用擴展名有助於對文件內容的理解。有些應用程序要經過擴展名來識別文件,可是更多的應用程序並不依賴文件的擴展名,就像file命令在識別文件時並非依據擴展名來斷定文件的類型。
  3. 隱藏文件:以點開頭的文件在Linux系統中是隱藏文件(不可見文件)。

目錄結構

  1. /bin - 基本命令的二進制文件。
  2. /boot - 引導加載程序的靜態文件。
  3. /dev - 設備文件。
  4. /etc - 配置文件。
  5. /home - 普通用戶主目錄的父目錄。
  6. /lib - 共享庫文件。
  7. /lib64 - 共享64位庫文件。
  8. /lost+found - 存放未連接文件。
  9. /media - 自動識別設備的掛載目錄。
  10. /mnt - 臨時掛載文件系統的掛載點。
  11. /opt - 可選插件軟件包安裝位置。
  12. /proc - 內核和進程信息。
  13. /root - 超級管理員用戶主目錄。
  14. /run - 存放系統運行時須要的東西。
  15. /sbin - 超級用戶的二進制文件。
  16. /sys - 設備的僞文件系統。
  17. /tmp - 臨時文件夾。
  18. /usr - 用戶應用目錄。
  19. /var - 變量數據目錄。

訪問權限

  1. chmod - 改變文件模式比特。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l ... -rw-r--r-- 1 root root 211878 Jun 19 16:06 sohu.html ... [root@iZwz97tbgo9lkabnat2lo8Z ~]# chmod g+w,o+w sohu.html [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l ... -rw-rw-rw- 1 root root 211878 Jun 19 16:06 sohu.html ... [root@iZwz97tbgo9lkabnat2lo8Z ~]# chmod 644 sohu.html [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l ... -rw-r--r-- 1 root root 211878 Jun 19 16:06 sohu.html ...

    說明:經過上面的例子能夠看出,用chmod改變文件模式比特有兩種方式:一種是字符設定法,另外一種是數字設定法。除了chmod以外,能夠經過umask來設定哪些權限將在新文件的默認權限中被刪除。

    長格式查看目錄或文件時顯示結果及其對應權限的數值以下表所示。

  2. chown - 改變文件全部者。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l ... -rw-r--r-- 1 root root 54 Jun 20 10:06 readme.txt ... [root@iZwz97tbgo9lkabnat2lo8Z ~]# chown hellokitty readme.txt [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l ... -rw-r--r-- 1 hellokitty root 54 Jun 20 10:06 readme.txt ...

磁盤管理

  1. 列出文件系統的磁盤使用情況 - df。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/vda1 40G 5.0G 33G 14% / devtmpfs 486M 0 486M 0% /dev tmpfs 497M 0 497M 0% /dev/shm tmpfs 497M 356K 496M 1% /run tmpfs 497M 0 497M 0% /sys/fs/cgroup tmpfs 100M 0 100M 0% /run/user/0
  2. 磁盤分區表操做 - fdisk。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# fdisk -l Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000a42f4 Device Boot Start End Blocks Id System /dev/vda1 * 2048 83884031 41940992 83 Linux Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes
  3. 格式化文件系統 - mkfs。

  4. 文件系統檢查 - fsck。

  5. 掛載/卸載 - mount / umount。

編輯器 - vim

  1. 啓動vim。能夠經過vivim命令來啓動vim,啓動時能夠指定文件名來打開一個文件,若是沒有指定文件名,也能夠在保存的時候指定文件名。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# vim guess.py
  2. 命令模式、編輯模式和末行模式:啓動vim進入的是命令模式(也稱爲Normal模式),在命令模式下輸入英文字母i會進入編輯模式(Insert模式),屏幕下方出現-- INSERT --提示;在編輯模式下按下Esc會回到命令模式,此時若是輸入英文:會進入末行模式,在末行模式下輸入q!能夠在不保存當前工做的狀況下強行退出vim;在命令模式下輸入v會進入可視模式(Visual模式),能夠用光標選擇一個區域再完成對應的操做。

  3. 保存和退出vim:在命令模式下輸入: 進入末行模式,輸入wq能夠實現保存退出;若是想放棄編輯的內容輸入q!強行退出,這一點剛纔已經提到過了;在命令模式下也能夠直接輸入ZZ實現保存退出。若是隻想保存文件不退出,那麼能夠在末行模式下輸入w;能夠在w後面輸入空格再指定要保存的文件名。

  4. 光標操做。

    • 在命令模式下能夠經過hjkl來控制光標向左、下、上、右的方向移動,能夠在字母前輸入數字來表示移動的距離,例如:10h表示向左移動10個字符。
    • 在命令模式下能夠經過Ctrl+yCtrl+e來實現向上、向下滾動一行文本的操做,能夠經過Ctrl+fCtrl+b來實現向前和向後翻頁的操做。
    • 在命令模式下能夠經過輸入英文字母G將光標移到文件的末尾,能夠經過gg將光標移到文件的開始,也能夠經過在G前輸入數字來將光標移動到指定的行。
  5. 文本操做。

    • 刪除:在命令模式下能夠用dd來刪除整行;能夠在dd前加數字來指定刪除的行數;能夠用d$來實現刪除從光標處刪到行尾的操做,也能夠經過d0來實現從光標處刪到行首的操做;若是想刪除一個單詞,可使用dw;若是要刪除全文,能夠在輸入:%d(其中:用來從命令模式進入末行模式)。
    • 複製和粘貼:在命令模式下能夠用yy來複制整行;能夠在yy前加數字來指定複製的行數;能夠經過p將複製的內容粘貼到光標所在的地方。
    • 撤銷和恢復:在命令模式下輸入u能夠撤銷以前的操做;經過Ctrl+r能夠恢復被撤銷的操做。
    • 對內容進行排序:在命令模式下輸入%!sort
  6. 查找和替換。

    • 查找操做須要輸入/進入末行模式並提供正則表達式來匹配與之對應的內容,例如:/doc.*\.,輸入n來向前搜索,也能夠輸入N來向後搜索。
    • 替換操做須要輸入:進入末行模式並指定搜索的範圍、正則表達式以及替換後的內容和匹配選項,例如::1,$s/doc.*/hello/gice,其中:
      • g - global:全局匹配。
      • i - ignore case:忽略大小寫匹配。
      • c - confirm:替換時須要確認。
      • e - error:忽略錯誤。
  7. 參數設定:在輸入:進入末行模式後能夠對vim進行設定。

    • 設置Tab鍵的空格數:set ts=4

    • 設置顯示/不顯示行號:set nu / set nonu

    • 設置啓用/關閉高亮語法:syntax on / syntax off

    • 設置顯示標尺(光標所在的行和列): set ruler

    • 設置啓用/關閉搜索結果高亮:set hls / set nohls

      說明:若是但願上面的這些設定在每次啓動vim時都能生效,須要將這些設定寫到用戶主目錄下的.vimrc文件中。

  8. 高級技巧

    • 比較多個文件。

      [root@iZwz97tbgo9lkabnat2lo8Z ~]# vim -d foo.txt bar.txt

    • 打開多個文件。

      [root@iZwz97tbgo9lkabnat2lo8Z ~]# vim foo.txt bar.txt hello.txt

      啓動vim後只有一個窗口顯示的是foo.txt,能夠在末行模式中輸入ls查看到打開的三個文件,也能夠在末行模式中輸入b <num>來顯示另外一個文件,例如能夠用:b 2將bar.txt顯示出來,能夠用:b 3將hello.txt顯示出來。

    • 拆分和切換窗口。

      能夠在末行模式中輸入spvs來實現對窗口的水平或垂直拆分,這樣咱們就能夠同時打開多個編輯窗口,經過按兩次Ctrl+w就能夠實現編輯窗口的切換,在一個窗口中執行退出操做只會關閉對應的窗口,其餘的窗口繼續保留。

    • 映射快捷鍵:在vim下能夠將一些經常使用操做映射爲快捷鍵來提高工做效率。

      • 例子1:在命令模式下輸入F4執行從第一行開始刪除10000行代碼的操做。

        :map <F4> gg10000dd

        例子2:在編輯模式下輸入__main直接補全爲if __name__ == '__main__':

        :inoremap __main if __name__ == '__main__':

      說明:上面例子2的inoremap中的i表示映射的鍵在編輯模式使用, nore表示不要遞歸,這一點很是重要,不然若是鍵對應的內容中又出現鍵自己,就會引起遞歸(至關於進入了死循環)。若是但願映射的快捷鍵每次啓動vim時都能生效,須要將映射寫到用戶主目錄下的.vimrc文件中。

    • 錄製宏。

      • 在命令模式下輸入qa開始錄製宏(其中a是寄存器的名字,也能夠是其餘英文字母或0-9的數字)。

      • 執行你的操做(光標操做、編輯操做等),這些操做都會被錄製下來。

      • 若是錄製的操做已經完成了,按q結束錄製。

      • 經過@aa是剛纔使用的寄存器的名字)播放宏,若是要屢次執行宏能夠在前面加數字,例如100@a表示將宏播放100次。

      • 能夠試一試下面的例子來體驗錄製宏的操做,該例子來源於Harttle Land網站,該網站上提供了不少關於vim的使用技巧,有興趣的能夠去了解一下。

軟件安裝和配置

使用包管理工具

  1. yum - Yellowdog Updater Modified。
    • yum search:搜索軟件包,例如yum search nginx
    • yum list installed:列出已經安裝的軟件包,例如yum list installed | grep zlib
    • yum install:安裝軟件包,例如yum install nginx
    • yum remove:刪除軟件包,例如yum remove nginx
    • yum update:更新軟件包,例如yum update能夠更新全部軟件包,而yum update tar只會更新tar。
    • yum check-update:檢查有哪些能夠更新的軟件包。
    • yum info:顯示軟件包的相關信息,例如yum info nginx
  2. rpm - Redhat Package Manager。
    • 安裝軟件包:rpm -ivh <packagename>.rpm
    • 移除軟件包:rpm -e <packagename>
    • 查詢軟件包:rpm -qa,例如能夠用rpm -qa | grep mysql來檢查是否安裝了MySQL相關的軟件包。

下面以Nginx爲例,演示如何使用yum安裝軟件。

[root@iZwz97tbgo9lkabnat2lo8Z ~]# yum -y install nginx ... Installed: nginx.x86_64 1:1.12.2-2.el7 Dependency Installed: nginx-all-modules.noarch 1:1.12.2-2.el7 nginx-mod-http-geoip.x86_64 1:1.12.2-2.el7 nginx-mod-http-image-filter.x86_64 1:1.12.2-2.el7 nginx-mod-http-perl.x86_64 1:1.12.2-2.el7 nginx-mod-http-xslt-filter.x86_64 1:1.12.2-2.el7 nginx-mod-mail.x86_64 1:1.12.2-2.el7 nginx-mod-stream.x86_64 1:1.12.2-2.el7 Complete! [root@iZwz97tbgo9lkabnat2lo8Z ~]# yum info nginx Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Installed Packages Name : nginx Arch : x86_64 Epoch : 1 Version : 1.12.2 Release : 2.el7 Size : 1.5 M Repo : installed From repo : epel Summary : A high performance web server and reverse proxy server URL : http://nginx.org/ License : BSD Description : Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and : IMAP protocols, with a strong focus on high concurrency, performance and low : memory usage. [root@iZwz97tbgo9lkabnat2lo8Z ~]# nginx -v nginx version: nginx/1.12.2

移除Nginx。

[root@iZwz97tbgo9lkabnat2lo8Z ~]# nginx -s stop [root@iZwz97tbgo9lkabnat2lo8Z ~]# yum -y remove nginx

下面以MySQL爲例,演示如何使用rpm安裝軟件。要安裝MySQL須要先到MySQL官方網站下載對應的RPM文件,固然要選擇和你使用的Linux系統對應的版本。MySQL如今是Oracle公司旗下的產品,在MySQL被收購後,MySQL的做者從新制做了一個MySQL的分支MariaDB,能夠經過yum進行安裝。若是要安裝MySQL須要先經過yum刪除mariadb-libs這個可能會跟MySQL底層庫衝突的庫,而後還須要安裝一個名爲libaio的依賴庫。

[root@iZwz97tbgo9lkabnat2lo8Z mysql]# ls mysql-community-client-5.7.22-1.el7.x86_64.rpm mysql-community-common-5.7.22-1.el7.x86_64.rpm mysql-community-libs-5.7.22-1.el7.x86_64.rpm mysql-community-server-5.7.22-1.el7.x86_64.rpm [root@iZwz97tbgo9lkabnat2lo8Z mysql]# yum -y remove mariadb-libs [root@iZwz97tbgo9lkabnat2lo8Z mysql]# yum -y install libaio [root@iZwz97tbgo9lkabnat2lo8Z mysql]# ls | xargs rpm -ivh warning: mysql-community-client-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] ...

說明:因爲MySQL和MariaDB的底層依賴庫是有衝突的,因此上面咱們首先用yum移除了名爲mariadb-libs的依賴庫並安裝了名爲libaio的依賴庫。因爲咱們將安裝MySQL所需的rpm文件放在一個獨立的目錄中,因此能夠經過ls命令查看到安裝文件並用xargsls的輸出做爲參數交給rpm -ivh來進行安裝。關於MySQL和MariaDB之間的關係,能夠閱讀維基百科上關於MariaDB的介紹。

移除安裝的MySQL。

[root@iZwz97tbgo9lkabnat2lo8Z ~]# rpm -qa | grep mysql | xargs rpm -e

下載解壓配置環境變量

下面以安裝MongoDB爲例,演示這類軟件應該如何安裝。

[root@iZwz97tbgo9lkabnat2lo8Z ~]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.6.5.tgz --2018-06-21 18:32:53-- https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.6.5.tgz Resolving fastdl.mongodb.org (fastdl.mongodb.org)... 52.85.83.16, 52.85.83.228, 52.85.83.186, ... Connecting to fastdl.mongodb.org (fastdl.mongodb.org)|52.85.83.16|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 100564462 (96M) [application/x-gzip] Saving to: ‘mongodb-linux-x86_64-rhel70-3.6.5.tgz’ 100%[==================================================>] 100,564,462 630KB/s in 2m 9s 2018-06-21 18:35:04 (760 KB/s) - ‘mongodb-linux-x86_64-rhel70-3.6.5.tgz’ saved [100564462/100564462] [root@iZwz97tbgo9lkabnat2lo8Z ~]# gunzip mongodb-linux-x86_64-rhel70-3.6.5.tgz [root@iZwz97tbgo9lkabnat2lo8Z ~]# tar -xvf mongodb-linux-x86_64-rhel70-3.6.5.tar mongodb-linux-x86_64-rhel70-3.6.5/README mongodb-linux-x86_64-rhel70-3.6.5/THIRD-PARTY-NOTICES mongodb-linux-x86_64-rhel70-3.6.5/MPL-2 mongodb-linux-x86_64-rhel70-3.6.5/GNU-AGPL-3.0 mongodb-linux-x86_64-rhel70-3.6.5/bin/mongodump mongodb-linux-x86_64-rhel70-3.6.5/bin/mongorestore mongodb-linux-x86_64-rhel70-3.6.5/bin/mongoexport mongodb-linux-x86_64-rhel70-3.6.5/bin/mongoimport mongodb-linux-x86_64-rhel70-3.6.5/bin/mongostat mongodb-linux-x86_64-rhel70-3.6.5/bin/mongotop mongodb-linux-x86_64-rhel70-3.6.5/bin/bsondump mongodb-linux-x86_64-rhel70-3.6.5/bin/mongofiles mongodb-linux-x86_64-rhel70-3.6.5/bin/mongoreplay mongodb-linux-x86_64-rhel70-3.6.5/bin/mongoperf mongodb-linux-x86_64-rhel70-3.6.5/bin/mongod mongodb-linux-x86_64-rhel70-3.6.5/bin/mongos mongodb-linux-x86_64-rhel70-3.6.5/bin/mongo mongodb-linux-x86_64-rhel70-3.6.5/bin/install_compass [root@iZwz97tbgo9lkabnat2lo8Z ~]# vim .bash_profile ... PATH=$PATH:$HOME/bin:$HOME/mongodb-linux-x86_64-rhel70-3.6.5/bin export PATH ... [root@iZwz97tbgo9lkabnat2lo8Z ~]# source .bash_profile [root@iZwz97tbgo9lkabnat2lo8Z ~]# mongod --version db version v3.6.5 git version: a20ecd3e3a174162052ff99913bc2ca9a839d618 OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013 allocator: tcmalloc modules: none build environment: distmod: rhel70 distarch: x86_64 target_arch: x86_64 [root@iZwz97tbgo9lkabnat2lo8Z ~]# mongo --version MongoDB shell version v3.6.5 git version: a20ecd3e3a174162052ff99913bc2ca9a839d618 OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013 allocator: tcmalloc modules: none build environment: distmod: rhel70 distarch: x86_64 target_arch: x86_64

說明:固然也能夠經過yum來安裝MongoDB,具體能夠參照官方網站上給出的說明。

源代碼構建安裝

  1. 安裝Python 3.6。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# yum install gcc [root@iZwz97tbgo9lkabnat2lo8Z ~]# wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz [root@iZwz97tbgo9lkabnat2lo8Z ~]# gunzip Python-3.6.5.tgz [root@iZwz97tbgo9lkabnat2lo8Z ~]# tar -xvf Python-3.6.5.tar [root@iZwz97tbgo9lkabnat2lo8Z ~]# cd Python-3.6.5 [root@iZwz97tbgo9lkabnat2lo8Z ~]# ./configure --prefix=/usr/local/python36 --enable-optimizations [root@iZwz97tbgo9lkabnat2lo8Z ~]# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel [root@iZwz97tbgo9lkabnat2lo8Z ~]# make && make install ... 配置環境變量 ... [root@iZwz97tbgo9lkabnat2lo8Z ~]# ln -s /usr/local/python36/bin/python3.6 /usr/bin/python3 [root@iZwz97tbgo9lkabnat2lo8Z ~]# python3 --version Python 3.6.5 [root@iZwz97tbgo9lkabnat2lo8Z ~]# python3 -m pip install -U pip [root@iZwz97tbgo9lkabnat2lo8Z ~]# pip3 --version
  2. 安裝Redis-3.2.12。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# wget http://download.redis.io/releases/redis-3.2.12.tar.gz [root@iZwz97tbgo9lkabnat2lo8Z ~]# gunzip redis-3.2.12.tar.gz [root@iZwz97tbgo9lkabnat2lo8Z ~]# tar -xvf redis-3.2.12.tar [root@iZwz97tbgo9lkabnat2lo8Z ~]# cd redis-3.2.12 [root@iZwz97tbgo9lkabnat2lo8Z ~]# make && make install [root@iZwz97tbgo9lkabnat2lo8Z ~]# redis-server --version Redis server v=3.2.12 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=5bc5cd3c03d6ceb6 [root@iZwz97tbgo9lkabnat2lo8Z ~]# redis-cli --version redis-cli 3.2.12

配置服務

  1. 啓動服務。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# systemctl start firewalld
  2. 終止服務。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# systemctl stop firewalld
  3. 重啓服務。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# systemctl restart firewalld
  4. 查看服務。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# systemctl status firewalld
  5. 設置是否開機自啓。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# systemctl enable firewalld Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to /usr/lib/systemd/system/firewalld.service. Created symlink from /etc/systemd/system/multi-user.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service. [root@iZwz97tbgo9lkabnat2lo8Z ~]# systemctl disable firewalld Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

計劃任務

  1. crontab命令。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# crontab -e * * * * * echo "hello, world!" >> /root/hello.txt 59 23 * * * rm -f /root/*.log

    說明:輸入crontab -e命令會打開vim來編輯Cron表達式並指定觸發的任務,上面咱們定製了兩個計劃任務,一個是每分鐘向/root目錄下的hello.txt中追加輸出hello, world!;另外一個是天天23時59分執行刪除/root目錄下以log爲後綴名的文件。若是不知道Cron表達式如何書寫,能夠參照/etc/crontab文件中的提示(下面會講到)或者用谷歌或百度搜索一下,也可使用Cron表達式在線生成器來生成Cron表達式。

  2. crontab相關文件。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# cd /etc [root@iZwz97tbgo9lkabnat2lo8Z etc]# ls -l | grep cron -rw-------. 1 root root 541 Aug 3 2017 anacrontab drwxr-xr-x. 2 root root 4096 Mar 27 11:56 cron.d drwxr-xr-x. 2 root root 4096 Mar 27 11:51 cron.daily -rw-------. 1 root root 0 Aug 3 2017 cron.deny drwxr-xr-x. 2 root root 4096 Mar 27 11:50 cron.hourly drwxr-xr-x. 2 root root 4096 Jun 10 2014 cron.monthly -rw-r--r-- 1 root root 493 Jun 23 15:09 crontab drwxr-xr-x. 2 root root 4096 Jun 10 2014 cron.weekly [root@iZwz97tbgo9lkabnat2lo8Z etc]# vim crontab 1 SHELL=/bin/bash 2 PATH=/sbin:/bin:/usr/sbin:/usr/bin 3 MAILTO=root 4 5 # For details see man 4 crontabs 6 7 # Example of job definition: 8 # .---------------- minute (0 - 59) 9 # | .------------- hour (0 - 23) 10 # | | .---------- day of month (1 - 31) 11 # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... 12 # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat 13 # | | | | | 14 # * * * * * user-name command to be executed

    經過修改/etc目錄下的crontab文件也可以定製計劃任務。

網絡訪問和管理

  1. 安全遠程鏈接 - ssh。

  2. 經過網絡獲取資源 - wget。

    • -b 後臺下載模式
    • -O 下載到指定的目錄
    • -r 遞歸下載
  3. 顯示/操做網絡配置(舊) - ifconfig。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# ifconfig eth0 eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.18.61.250 netmask 255.255.240.0 broadcast 172.18.63.255 ether 00:16:3e:02:b6:46 txqueuelen 1000 (Ethernet) RX packets 1067841 bytes 1296732947 (1.2 GiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 409912 bytes 43569163 (41.5 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 
  4. 顯示/操做網絡配置(新) - ip。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# ip address 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:16:3e:02:b6:46 brd ff:ff:ff:ff:ff:ff inet 172.18.61.250/20 brd 172.18.63.255 scope global eth0 valid_lft forever preferred_lft forever
  5. 網絡可達性檢查 - ping。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# ping www.baidu.com -c 3 PING www.a.shifen.com (220.181.111.188) 56(84) bytes of data. 64 bytes from 220.181.111.188 (220.181.111.188): icmp_seq=1 ttl=51 time=36.3 ms 64 bytes from 220.181.111.188 (220.181.111.188): icmp_seq=2 ttl=51 time=36.4 ms 64 bytes from 220.181.111.188 (220.181.111.188): icmp_seq=3 ttl=51 time=36.4 ms --- www.a.shifen.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms rtt min/avg/max/mdev = 36.392/36.406/36.427/0.156 ms
  6. 查看網絡服務和端口 - netstat。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# netstat -nap | grep nginx
  7. 安全文件拷貝 - scp。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# scp root@1.2.3.4:/root/guido.jpg hellokitty@4.3.2.1:/home/hellokitty/pic.jpg
  8. 安全文件傳輸 - sftp。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# sftp root@120.77.222.217 root@120.77.222.217's password: Connected to 120.77.222.217. sftp>
    • help:顯示幫助信息。

    • ls/lls:顯示遠端/本地目錄列表。

    • cd/lcd:切換遠端/本地路徑。

    • mkdir/lmkdir:建立遠端/本地目錄。

    • pwd/lpwd:顯示遠端/本地當前工做目錄。

    • get:下載文件。

    • put:上傳文件。

    • rm:刪除遠端文件。

    • bye/exit/quit:退出sftp。

進程管理

  1. ps - 查詢進程。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# ps -ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 Jun23 ? 00:00:05 /usr/lib/systemd/systemd --switched-root --system --deserialize 21 root 2 0 0 Jun23 ? 00:00:00 [kthreadd] ... [root@iZwz97tbgo9lkabnat2lo8Z ~]# ps -ef | grep mysqld root 4943 4581 0 22:45 pts/0 00:00:00 grep --color=auto mysqld mysql 25257 1 0 Jun25 ? 00:00:39 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
  2. kill - 終止進程。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# kill 1234 [root@iZwz97tbgo9lkabnat2lo8Z ~]# kill -9 1234

    例子:用一條命令強制終止正在運行的Redis進程。

    ps -ef | grep redis | grep -v grep | awk '{print $2}' | xargs kill
  3. 將進程置於後臺運行。

    • Ctrl+Z
    • &
    [root@iZwz97tbgo9lkabnat2lo8Z ~]# mongod & [root@iZwz97tbgo9lkabnat2lo8Z ~]# redis-server ... ^Z [4]+ Stopped redis-server
  4. jobs - 查詢後臺進程。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# jobs [2] Running mongod & [3]- Stopped cat [4]+ Stopped redis-server
  5. bg - 讓進程在後臺繼續運行。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# bg %4 [4]+ redis-server & [root@iZwz97tbgo9lkabnat2lo8Z ~]# jobs [2] Running mongod & [3]+ Stopped cat [4]- Running redis-server &
  6. fg - 將後臺進程置於前臺。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# fg %4 redis-server ^C5554:signal-handler (1530025281) Received SIGINT scheduling shutdown... 5554:M 26 Jun 23:01:21.413 # User requested shutdown... 5554:M 26 Jun 23:01:21.413 * Saving the final RDB snapshot before exiting. 5554:M 26 Jun 23:01:21.415 * DB saved on disk 5554:M 26 Jun 23:01:21.415 # Redis is now ready to exit, bye bye...

    說明:置於前臺的進程可使用Ctrl+C來終止它。

  7. top - 進程監控。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# top top - 23:04:23 up 3 days, 14:10, 1 user, load average: 0.00, 0.01, 0.05 Tasks: 65 total, 1 running, 64 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.3 us, 0.3 sy, 0.0 ni, 99.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 1016168 total, 191060 free, 324700 used, 500408 buff/cache KiB Swap: 0 total, 0 free, 0 used. 530944 avail Mem ...

系統性能

  1. 查看系統活動信息 - sar。

  2. 查看內存使用狀況 - free。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# free total used free shared buff/cache available Mem: 1016168 323924 190452 356 501792 531800 Swap: 0 0 0
  3. 查看進程使用內存情況 - pmap。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# ps PID TTY TIME CMD 4581 pts/0 00:00:00 bash 5664 pts/0 00:00:00 ps [root@iZwz97tbgo9lkabnat2lo8Z ~]# pmap 4581 4581: -bash 0000000000400000 884K r-x-- bash 00000000006dc000 4K r---- bash 00000000006dd000 36K rw--- bash 00000000006e6000 24K rw--- [ anon ] 0000000001de0000 400K rw--- [ anon ] 00007f82fe805000 48K r-x-- libnss_files-2.17.so 00007f82fe811000 2044K ----- libnss_files-2.17.so ...
  4. 報告設備CPU和I/O統計信息 - iostat。

    [root@iZwz97tbgo9lkabnat2lo8Z ~]# iostat Linux 3.10.0-693.11.1.el7.x86_64 (iZwz97tbgo9lkabnat2lo8Z) 06/26/2018 _x86_64_ (1 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 0.79 0.00 0.20 0.04 0.00 98.97 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn vda 0.85 6.78 21.32 2106565 6623024 vdb 0.00 0.01 0.00 2088 0
相關文章
相關標籤/搜索