linux 知識點補充

1 mkdir -p參數

-p 參數用於建立多級目錄是時。 好比咱們要建立 a 目錄和a目錄下的b目錄:html

mkdir -p a/b

還能夠在多個文件夾下建立,好比在A,B,C 三個目錄下穿件test 目錄:linux

mdkir -p {a,b,c}/test

建立a目錄並在在 a 目錄下建立 b,c 兩個目錄:正則表達式

mkdir -p a/{b,c}

2 tar 參數 原文檔 http://tech.mclarian.com/a/137#viewSource

  1. -c :創建一個壓縮文件的參數指令(create 的意思)。
  2. -x :解開一個壓縮文件的參數指令。
  3. -t :查看 tarfile 裏面的文件。特別注意,在參數的下達中,c/x/t 僅能存在一個,不可同時存在, 由於不可能同時壓縮與解壓縮。
  4. -z :使用gzip進行壓縮打包文檔。
  5. -j :使用bzip2進行壓縮打包文檔。
  6. -v :壓縮的過程當中顯示文件。這個經常使用,但不建議用在背景執行過程。
  7. -f :使用檔名。請留意,在 f 以後要當即接檔名,不要再加參數。例如使用「tar -zcvfP tfile sfile」就是錯誤的寫法,要寫成「tar -zcvPf tfile sfile」纔對。(關於這點我保留意見,由於平時我解壓,都是-xvfz….沒見有神馬不對的….也許是改進了?)
  8. -p :使用原文件的原來屬性(屬性不會依據使用者而變)。
  9. -P :可使用絕對路徑來壓縮。
  10. -N() :比後面接的日期(yyyy/mm/dd)還要新的纔會被打包進新建的文件中。
  11. –exclude FILE:在壓縮的過程當中,不要將 FILE 打包。

問題: 1 tar: Removing leading `/’ from member names」的錯誤shell

|    其緣由是tar默認爲相對路徑,使用絕對路徑的話就回報這個錯,可使 用-P參數(注意大寫)解決這個問題vim

[root@iZryxshkbkz2x2Z a]# tar -jPcf shell.tar /root/shell

3 grep命令

3-1 定義

定義: 在文件中搜素符合條件的字符串,若是須要匹配,使用正則表達式進行匹配。服務器

[root@iZryxshkbkz2x2Z ~]#  grep savepath ./backups.sh 
    savepath=/root/tar/$(date +%F_%H%M)
    if [ ! -d  $savepath ]
      mkdir -p $savepath
    tar -jPcf $savepath/96.tar /www/wwwroot/default/96weixin.ewm

3-2 grep 中的 :

grep -E 'bin|sacepath' ./backups.sh  # 重點必定要加E參數。將範本樣式爲延伸的普通表示法來使用,意味着使用能使用擴展正則表達式

3-3 grep 中的

     grep pattern1 files | grep pattern2 //顯示既匹配 pattern1 又匹配 pattern2 的行。ssh

[root@iZryxshkbkz2x2Z ~]# grep 'mkdir' backups.sh | grep 'savepath'
    mkdir -p $savepath

4 find 命令

4-1 定義

[root@iZryxshkbkz2x2Z find]# ls
    testABC.txt  testA.txt  testB.txt  test.txt
    [root@iZryxshkbkz2x2Z find]# find . -name test
    [root@iZryxshkbkz2x2Z find]# find . -name test.txt  # 因此find徹底匹配
    ./test.txt

4-2 使用 通配符

    ***** :tcp

[root@iZryxshkbkz2x2Z find]# ls
    test  testA  testABC
    [root@iZryxshkbkz2x2Z find]# find ./ -name 'test*'
    ./testABC
    ./test
    ./testA

    ? :工具

[root@iZryxshkbkz2x2Z find]# ls
    test  testA  testABC
    [root@iZryxshkbkz2x2Z find]# find . -name 'test?'
    ./testA

    [] :this

find . -name 'test[AB]' 碰到tes後跟 A 或 B 就返回,注意只返回一個

[root@iZryxshkbkz2x2Z find]# ls
    test  testA  testABC  testBc
    [root@iZryxshkbkz2x2Z find]# find . -name 'test[AB]'
    ./testA

4-3 find命令按照時間查找

[root@iZryxshkbkz2x2Z ~]# find ./  -mtime 2
    ./shell/if.sh
    ./shell/a.txt
    ./shell/for.sh
    ./shell/while.sh
    ./shell/.until.swp

4-4 find 按照文件大小查找

[root@iZryxshkbkz2x2Z ~]# find . -size +20k -a -size -10M; # 注意,k小寫,M大寫。
    ./.acme.sh/acme.sh

5 查看系統內存

5-1 free -m

https://blog.csdn.net/makang456/article/details/78694120

[root@iZryxshkbkz2x2Z default]# free -m
                 total       used       free     shared    buffers     cached
    Mem:           996        883        112        103         62        456
    -/+ buffers/cache:        365        630
    Swap:         1024         57        967

總內存: total 996M

系統使用內存: userd - free - buffers - cached (-buffer/cached)

系統剩餘內存: free + buffers + cached (+buffer/cached)

5-2 proc/meminfo

[root@iZryxshkbkz2x2Z ~]# cat /proc//meminfo 
    MemTotal:        1019988 kB
    MemFree:          347060 kB
    Buffers:           24876 kB
    Cached:           305160 kB
    SwapCached:         8828 kB
    Active:           242408 kB
    Inactive:         356236 kB
    Active(anon):     158404 kB
    Inactive(anon):   216016 kB
    Active(file):      84004 kB
    Inactive(file):   140220 kB
    Unevictable:           0 kB
    Mlocked:               0 kB

6 獲取系統信息

  6-1 獲取系統: uname -o
[root@iZryxshkbkz2x2Z ~]# uname -o
        GNU/Linux
  6-2 獲取系統版本: cat /etc/issue
[root@iZryxshkbkz2x2Z ~]# cat /etc/issue
    CentOS release 6.10 (Final)
    Kernel \r on an \m
  6-3 獲取系統操做位數: uname - m
[root@iZryxshkbkz2x2Z ~]# uname -m
x86_64
  6-4 獲取系統發行版本
[root@iZryxshkbkz2x2Z ~]# uname -r
    2.6.32-696.10.1.el6.x86_64
  6-5 可以使用 uname -a 獲取以上信息
[root@iZryxshkbkz2x2Z ~]# uname -a
    Linux iZryxshkbkz2x2Z 2.6.32-696.10.1.el6.x86_64 #1 SMP Tue Aug 22 18:51:35 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
  6-6 獲取主機名 hostname
[root@iZryxshkbkz2x2Z ~]# hostname
    iZryxshkbkz2x2Z
  6-7 獲取公網ip hostname -I
[root@iZryxshkbkz2x2Z ~]# hostname -I
    172.17.0.1
  6-8 獲取內網 ip
  6-9 獲取DNS ca /etc/resolv.conf
[root@iZryxshkbkz2x2Z ~]#  cat /etc/resolv.conf
    nameserver 100.100.2.136
    nameserver 100.100.2.138
    options timeout:2 attempts:3 rotate single-request-reopen
  6-10 獲取當前正在登錄的用戶 who
[root@iZryxshkbkz2x2Z ~]# who
    root     pts/5        2018-08-16 08:13 (222.173.241.202)

未完待續。。。

7 linux 查看文件或文件夾大小 du

  7-1 -s : 僅顯示總計,只列出最後加總的值
[root@iZryxshkbkz2x2Z ~]# du -s
    51000   .
  7-2 -h : 以M 統計
[root@iZryxshkbkz2x2Z ~]# du -sh
    50M .
  7-3 -a : 遞歸顯示全部文件大小
[root@iZryxshkbkz2x2Z ~]# du -ah
    4.0K    ./b.docx
    4.0K    ./backups.sh
    4.0K    ./.ssh/known_hosts
    4.0K    ./.ssh/id_rsa
    4.0K    ./.ssh/id_rsa.pub
    4.0K    ./.ssh/authorized_keys
    20K ./.ssh
    4.0K    ./firewall.sh
    20K ./.cache/pip/http/b/b/8/7/6/bb876b2e6a22c2739002e9ef3388ae978b7a6192a19fe67d8b0030f2
    24K ./.cache/pip/http/b/b/8/7/6
    28K ./.cache/pip/http/b/b/8/7
    32K ./.cache/pip/http/b/b/8
    36K ./.cache/pip/http/b/b
    40K ./.cache/pip/http/b
    4.0K    ./.cache/pip/http/f/e/d/0/e/fed0ed508030b766d5b0c2792132c8bf197804464765b46b361f93a4
    8.0K    ./.cache/pip/http/f/e/d/0/e
    12K ./.cache/pip/http/f/e/d/0
  7-4 --max-depth=1 : 顯示一級目錄大小,重點: 不顯示文件,只顯示目錄
[root@iZryxshkbkz2x2Z ~]# du -h --max-depth=1  # 重點
    20K ./.ssh
    80K ./.cache
    4.0K    ./.gconf
    46M ./tar
    8.0K    ./.pip
    12K ./a
    1.7M    ./.openoffice
    4.0K    ./find
    600K    ./html
    56K ./.subversion
    184K    ./.acme.sh
    124K    ./shell
    1.8M    ./.config
    8.0K    ./.pki
    50M .
  7-5 顯示單個文件大小
[root@iZryxshkbkz2x2Z ~]# du  -h test.txt
    4.0K    test.txt

8 ipatables 添加端口

  1. vim /etc/sysconfig/iptables

  2. -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT # 添加3306 端口

  3. service iptables restart # 重啓iptables

9 linux 關機與重啓

1 shutdow

f

如當即重啓:

shutdown -r now

在5:30 重啓服務器:

[root@iZryxshkbkz2x2Z ~]# shutdown -r 05:30

    Broadcast message from root@iZryxshkbkz2x2Z
        (/dev/pts/5) at 11:12 ...

    The system is going down for reboot in 1098 minutes!

取消上一個關機命令:

[root@iZryxshkbkz2x2Z ~]# shutdown -c
shutdown: Shutdown cancelled
[1]+  Done                    shutdown -r 05:30
[root@iZryxshkbkz2x2Z ~]# shutdown -c
shutdown: Cannot find pid of running shutdown

2 其餘關機命令

# halt

# poweroff

# init 0

# reboot

# init 6

並不建議使用以上命令,建議使用shutdown。

3 關於linux init

init命令是Linux下的進程初始化工具,init進程是全部Linux進程的父進程,它的進程號爲1。init命令是Linux操做系統中不可缺乏的程序之一,init進程是Linux內核引導運行的,是系統中的第一個進程

能夠在 在/etc/inittab中查看 # 0 - halt (Do NOT set initdefault to this) # 1 - Single user mode # 2 - Multiuser, without NFS (The same as 3, if you do not have networking) # 3 - Full multiuser mode # 4 - unused # 5 - X11 # 6 - reboot (Do NOT set initdefault to this) # id:3:initdefault: 中文: #0 停機(千萬不能把initdefault 設置爲0) #1 單用戶模式 #2 多用戶,沒有 NFS(和級別3類似,會中止部分服務) #3 徹底多用戶模式 #4 沒有用到 #5 x11(Xwindow) #6 從新啓動(千萬不要把initdefault 設置爲6)

怎麼排查linux 宕機緣由?

未完待續 。。。

相關文章
相關標籤/搜索