最全的linux基礎命令


 

第1章 linux命令

1.1 線上查詢及幫助命令

  1. help命令***

    help前面接你要查詢的命令:例如ls

    [root@server02 ~]# ls --help

    用法:ls [選項]... [文件]...

    列出 FILE 的信息(默認為當前目錄)

    如果不指定-cftuvSUX --sort 選項,則根據字母大小排序。

       

    長選項必須使用的參數對於短選項時也是必需使用的。

    -a, --all 不隱藏任何以開始的項目

    -A, --almost-all 列出除.. 以外的任何項目

    --author -l 同時使用時列出每個文件的作者

    -b, --escape 以八進制溢出序列表示不可打印的字符

    --block-size=大小 塊以指定大小的字節為單位

    -B, --ignore-backups 不列出任何以"~"字符結束的項目

    -c 配合-lt:根據ctime 排序並顯示ctime(文件

    狀態最后更改的時間)

    配合-l:顯示ctime 但根據名稱排序 其他情況:按ctime 排序

    -C 每欄由上至下列出項目

    --color[=WHEN] 控制是否使用色彩分辨文件。WHEN 可以是

    "never"(默認)"always""auto"其中之一

    -d, --directory 當遇到目錄時列出目錄本身而非目錄內的文件

    -D, --dired 產生適合Emacs dired 模式使用的結果

    -f 不進行排序,-aU 選項生效,-lst 選項失效

    -F, --classify 加上文件類型的指示符號(*/=@| 其中一個)

    --format=關鍵字 交錯-x,逗號分隔-m,水平-x,長-l

    單欄-1,詳細-l,垂直-C

    --full-time -l --time-style=full-iso

    -g 類似-l,但不列出所有者

    --group-directories-first

    在文件前分組目錄。此選項可與--sort 一起使用,

    但是一旦使用--sort=none (-U)將禁用分組

    -G, --no-group 以一個長列表的形式,不輸出組名

    -h, --human-readable -l 一起,以易於閱讀的格式輸出文件大小

    (例如 1K 234M 2G)

    --si 同上面類似,但是使用1000 為基底而非1024

    -H, --dereference-command-line

    跟隨命令行列出的符號鏈接

    --dereference-command-line-symlink-to-dir

    跟隨命令行列出的目錄的符號鏈接

    --hide=PATTERN 隱藏符合PATTERN 模式的項目

    (-a  -A 將覆蓋此選項)

    --indicator-style=方式 指定在每個項目名稱后加上指示符號方式:

    none (默認)classify (-F)file-type (-p)

    -i, --inode 顯示每個文件的inode 

    -I, --ignore=PATTERN 不顯示任何符合指定shell PATTERN 的項目

    -k --block-size=1K

    -l 使用較長格式列出信息

    -L, --dereference 當顯示符號鏈接的文件信息時,顯示符號鏈接所指示

    的對象而並非符號鏈接本身的信息

    -m 所有項目以逗號分隔,並填滿整行行寬

    -n, --numeric-uid-gid 類似 -l,但列出UID GID 

    -N, --literal 輸出未經處理的項目名稱 (如不特別處理控制字符)

    -o 類似 -l,但不列出有關組的信息

    -p, --indicator-style=slash 對目錄加上表示符號"/"

    -q, --hide-control-chars "?"字符代替無法打印的字符

    --show-control-chars 直接顯示無法打印的字符 (這是默認方式,除非調用

    的程序名稱是"ls"而且是在終端輸出結果)

    -Q, --quote-name 將條目名稱括上雙引號

    --quoting-style=方式 使用指定的quoting 方式顯示條目的名稱:

    literallocaleshellshell-alwayscescape

    -r, --reverse 排序時保留順序

    -R, --recursive 遞歸顯示子目錄

    -s, --size 以塊數形式顯示每個文件分配的尺寸

    -S 根據文件大小排序

    --sort=WORD 以下是可選用的WORD 和它們代表的相應選項:

    extension -X status -c

    none -U time -t

    size -S atime -u

    time -t access -u

    version -v use -u

    --time=WORD -l 同時使用時顯示WORD 所代表的時間而非修改時

    間:atimeaccessusectime status;加上

    --sort=time 選項時會以指定時間作為排序關鍵字

    --time-style=STYLE -l 同時使用時根據STYLE 代表的格式顯示時間:

    full-isoisolocaleposix-iso+FORMAT

    FORMAT 即是"date"所用的時間格式;如果FORMAT

    FORMAT1<換行>FORMAT2FORMAT1 適用於較舊

    的文件而FORMAT2 適用於較新的文件;如果STYLE

    "posix-"開頭,則STYLE 僅在POSIX 語系之外

    生效。

    -t 根據修改時間排序

    -T, --tabsize=寬度 指定制表符(Tab)的寬度,而非個字符

    -t 按修改時間排序

    -T, --tabsize=COLS 指定制表符(Tab)的寬度,而非8個字符

    -u -lt 一起使用:按照訪問時間排序並顯示

    -l一起使用:顯示訪問時間並按文件名排序

    其他:按照訪問時間排序

    -U 不進行排序;按照目錄順序列出項目

    -v 在文本中進行數字(版本)的自然排序

    -w, --width=COLS assume screen width instead of current value

    -x list entries by lines instead of by columns

    -X sort alphabetically by entry extension

    -1 list one file per line

       

    SELinux options:

       

    --lcontext Display security context. Enable -l. Lines

    will probably be too wide for most displays.

    -Z, --context Display security context so it fits on most

    displays. Displays only mode, user, group,

    security context and file name.

    --scontext Display only security context and file name.

    --help 顯示此幫助信息並退出

    --version 顯示版本信息並退出

       

    SIZE 可以是一個可選的整數,后面跟着以下單位中的一個:

    KB 1000K 1024MB 1000*1000M 1024*1024,還有 GTPEZY

       

    使用色彩來區分文件類型的功能已被禁用,默認設置和 --color=never 同時禁用了它。

    使用 --color=auto 選項,ls 只在標准輸出被連至終端時才生成顏色代碼。

    LS_COLORS 環境變量可改變此設置,可使用 dircolors 命令來設置。

       

       

    退出狀態:

    正常

    一般問題 (例如:無法訪問子文件夾)

    嚴重問題 (例如:無法使用命令行參數)

       

    請向bug-coreutils@gnu.org 報告ls 的錯誤

    GNU coreutils 項目主頁:<http://www.gnu.org/software/coreutils/>

    GNU 軟件一般性幫助:<http://www.gnu.org/gethelp/>

    請向<http://translationproject.org/team/zh_CN.html> 報告ls 的翻譯錯誤

    要獲取完整文檔,請運行:info coreutils 'ls invocation'

  2. man命令****

    man后面加你要查詢的命令:例如ls

    [root@server02 ~]# man ls

    LS(1) LS(1)

       

    NAME

    ls, dir, vdir - 列目錄內容

       

    提要

    ls [選項] [文件名...]

       

    POSIX 標准選項: [-CFRacdilqrtu1]

       

    GNU 選項 (短格式):

    [-1abcdfgiklmnopqrstuxABCDFGLNQRSUX] [-w cols] [-T cols] [-I pattern] [--full-time] [--format={long,verbose,commas,across,vertical,single-col-

    umn}] [--sort={none,time,size,extension}] [--time={atime,access,use,ctime,status}] [--color[={none,auto,always}]] [--help] [--version] [--]

       

    描述( DESCRIPTION 

    程序ls先列出非目錄的文件項,然后是每一個目錄中的"可顯示"文件。如果沒有選項之外的參數【譯注:即文件名部分為空】出現,缺省為 "." (當前目錄)。 

    項" -d "使得目錄與非目錄項同樣對待。除非" -a " 選項出現,文件名以"."開始的文件不屬"可顯示"文件。

       

    以當前目錄為准,每一組文件(包括非目錄文件項,以及每一內含文件的目錄)分別按文件名比較順序排序。如果" -l "選項存在,每組文件前顯示一摘要行給出

    該組文件長度之和(以 512 字節為單位)。

       

    輸出是到標准輸出( stdout )。除非以" -C "選項要求按多列輸出,輸出將是一行一個。然而,輸出到終端時,單列輸出或多列輸出是不確定的。可以分別  

    項" -1 " 或" -C "來強制按單列或多列輸出。

       

    -C 多列輸出,縱向排序。

       

    -F 每個目錄名加" / "后綴,每個 FIFO 名加" | "后綴,每個可運行名加" * "后綴。

       

    -R 遞歸列出遇到的子目錄。

       

    -a 列出所有文件,包括以 "." 開頭的隱含文件。

       

    -c 使用"狀態改變時間"代替"文件修改時間"為依據來排序(使用" -t "選項時)或列出(使用" -l "選項時)。

       

    -d 將目錄名象其它文件一樣列出,而不是列出它們的內容。

       

    -i 輸出文件前先輸出文件系列號(即 i 節點號: i-node number)。 -l 列出(以單列格式)文件模式( file mode ),文件的鏈接數,所有者名,組名,文

    件大小(以字節為單位),時間信息,及文件名。缺省時,時間信息顯示最近修改時間;可以以選項" -c "和" -u "選擇顯示其它兩種時間信息。對於設 

    文件,原先顯示文件大小的區域通常顯示的是主要和次要的號(majorand minor device numbers)。

       

    -q 將文件名中的非打印字符輸出為問號。(對於到終端的輸出這是缺省的。)

  3. 文件和目錄操作命令

    1.2.1 ls****

    ls:查看列表信息

    [root@server02 ~]# ls

    10MinuteAtHomeHIITABChallenge.MP4 config.db.p install.log.syslog sdsdsdsd.ts

    10MinuteAtHomeHIITABChallenge.ts config.db.t jar.tar t.txt

    123.sh dd libevent-2.0.21-stable.tar.gz video.ts

    1.sh get_dir.c live.mpg work

    aa h5_record.mp4 manpages-zh-1.5.1 wtxt.txt

    a_en h5_record.ts manpages-zh-1.5.1.tar.gz 公共的

    anaconda-ks.cfg index.html Net.class 模板

    bb index.html.1 orderId-generater-0.0.1-SNAPSHOT 視頻

    btv.ts index.html.2 orderId-generater-0.0.1-SNAPSHOT-bin.zip 圖片

    catalina.out index.html.3 rev.txt 文檔

    cctv5_6m.ts index.html.4 rpmbuild 下載

    common_zh index.html.5 sad.ts 音樂

    config.db install.log sdsd.cap 桌面

       

    ls -l:相當於ll,用來顯示目標詳細信息

    [root@server02 ~]# ls -l

    -rw-r--r-- 1 root root 203642732 6 15 2018 10MinuteAtHomeHIITABChallenge.MP4

    -rw-r--r-- 1 root root 223125544 6 15 2018 10MinuteAtHomeHIITABChallenge.ts

    -rw-r--r-- 1 root root 410 7 2 2018 123.sh

    -rw-r--r-- 1 root root 388 7 2 2018 1.sh

    drwxr-xr-x 2 root root 4096 6 30 2018 aa

    -rw-r--r-- 1 root root 0 10 27 2017 a_en

    -rw-------. 1 root root 2625 6 26 2017 anaconda-ks.cfg

    drwxr-xr-x 2 root root 4096 7 12 2018 bb

    -rw-r--r-- 1 root root 40628868 12 18 16:17 btv.ts

    -rw-r--r-- 1 root root 0 10 27 2017 catalina.out

    -rw-r--r-- 1 root root 92783264 5 8 2018 cctv5_6m.ts

    -rw-r--r-- 1 root root 0 10 27 2017 common_zh

    -rw-r--r-- 1 root root 33432 8 13 2018 config.db

    -rw-r--r-- 1 root root 13776 8 13 2018 config.db.p

    -rw-r--r-- 1 root root 16 10 22 09:06 config.db.t

    ls -al:顯示隱藏文件(.為隱藏文件)

    [root@server02 ~]# ls -al

    總用量 726320

    dr-xr-x---. 40 root root 4096 2 19 09:52 .

    dr-xr-xr-x. 34 root root 4096 2 18 09:08 ..

    -rw-r--r-- 1 root root 203642732 6 15 2018 10MinuteAtHomeHIITABChallenge.MP4

    -rw-r--r-- 1 root root 223125544 6 15 2018 10MinuteAtHomeHIITABChallenge.ts

    -rw-r--r-- 1 root root 410 7 2 2018 123.sh

    -rw-r--r-- 1 root root 388 7 2 2018 1.sh

    drwxr-xr-x 2 root root 4096 6 30 2018 aa

    drwxr-xr-x 3 root root 4096 10 28 2017 .abrt

    -rw-r--r-- 1 root root 0 10 27 2017 a_en

    -rw-------. 1 root root 2625 6 26 2017 anaconda-ks.cfg

    -rw------- 1 root root 24834 2 19 20:26 .bash_history

    -rw-r--r--. 1 root root 18 5 20 2009 .bash_logout

    -rw-r--r-- 1 root root 318 2 7 2018 .bash_profile

    -rw-r--r-- 1 root root 255 7 17 2018 .bashrc

    drwxr-xr-x 2 root root 4096 7 12 2018 bb

    -rw-r--r-- 1 root root 40628868 12 18 16:17 btv.ts

    drwxr-xr-x 3 root root 4096 9 21 2017 .cache

    -rw-r--r-- 1 root root 0 10 27 2017 catalina.out

    -rw-r--r-- 1 root root 92783264 5 8 2018 cctv5_6m.ts

    -rw-r--r-- 1 root root 0 10 27 2017 common_zh

    drwxr-xr-x 5 root root 4096 9 21 2017 .config

    -rw-r--r-- 1 root root 33432 8 13 2018 config.db

    ls -ltr:按修改時間逆向排序文件和文件夾詳細信息(-t:時間 -r:逆向)

    [root@server02 ~]# ls -ltr

    總用量 725540

    -rw-r--r-- 1 root root 850772 12 22 2015 libevent-2.0.21-stable.tar.gz

    -rw-r--r--. 1 root root 12619 6 26 2017 install.log.syslog

    -rw-r--r--. 1 root root 67834 6 26 2017 install.log

    -rw-------. 1 root root 2625 6 26 2017 anaconda-ks.cfg

    drwxr-xr-x 2 root root 4096 9 21 2017 桌面

    drwxr-xr-x 2 root root 4096 9 21 2017 下載

    drwxr-xr-x 2 root root 4096 9 21 2017 模板

    drwxr-xr-x 2 root root 4096 9 21 2017 音樂

    drwxr-xr-x 2 root root 4096 9 21 2017 文檔

    drwxr-xr-x 2 root root 4096 9 21 2017 圖片

    drwxr-xr-x 2 root root 4096 9 21 2017 視頻

    drwxr-xr-x 2 root root 4096 9 21 2017 公共的

    -rw-r--r-- 1 root root 0 10 27 2017 a_en

    -rw-r--r-- 1 root root 0 10 27 2017 wtxt.txt

    -rw-r--r-- 1 root root 0 10 27 2017 rev.txt

    -rw-r--r-- 1 root root 0 10 27 2017 common_zh

    -rw-r--r-- 1 root root 0 10 27 2017 t.txt

    -rw-r--r-- 1 root root 0 10 27 2017 catalina.out

    -rw-r--r-- 1 root root 5019412 12 9 2017 video.ts

    -rw-r--r-- 1 root root 9562886 2 26 2018 orderId-generater-0.0.1-SNAPSHOT-bin.zip

    drwxr-xr-x 3 root root 4096 2 26 2018 orderId-generater-0.0.1-SNAPSHOT

    -rw-r--r-- 1 root root 54794240 3 16 2018 jar.tar

    -rw-r--r-- 1 root root 1808 4 25 2018 Net.class

    -rw-r--r-- 1 tcpdump tcpdump 7646334 4 26 2018 sdsd.cap

    -rw-r--r-- 1 root root 13803460 5 3 2018 h5_record.mp4

    -rw-r--r-- 1 root root 15654384 5 4 2018 h5_record.ts

    -rw-r--r-- 1 root root 92783264 5 8 2018 cctv5_6m.ts

    -rw-r--r-- 1 root root 1494036 5 10 2018 sdsdsdsd.ts

    ls -d:列出指定目錄是否存在

    [root@oldboyedu ~]# ls -d /oldboy/oldboy01/ --- 列出指定目錄是否存在

    /oldboy/oldboy01/

    ls -1h:以人類可讀的方式寫出來

    [root@oldboy6666 ~]# ls -lh

    total 12K

    -rw-r--r--. 1 root root 7 Sep 10 16:45 1.txt

    -rw-------. 1 root root 1.5K Aug 30 12:16 anaconda-ks.cfg

    drwxr-xr-x. 2 root root 6 Sep 9 11:23 oldboy01

    -rw-r--r--. 1 root root 986 Sep 2 14:36 passwd

    [root@oldboy6666 ~]#

    ls -hlSr:根據文件的大小逆向排序(-S:文件大小)

    [root@oldboy6666 ~] # ls -hlSr /etc

    -rw-r--r--. 1 root root 2.0K Apr 11 2018 mail.rc

    -rw-r--r--. 1 root root 2.0K Oct 31 2018 virc

    -rw-r--r--. 1 root root 2.0K Jun 28 21:59 vimrc

    -rw-r--r--. 1 root root 2.0K Oct 30 2018 login.defs

    -rw-r--r--. 1 root root 2.0K Sep 12 15:03 profile

    -rw-r--r--. 1 root root 2.4K Oct 13 2013 libuser.conf

    -rw-r--r--. 1 root root 2.8K Oct 31 2018 bashrc

    -rw-r-----. 1 root root 3.2K Oct 30 2018 sudo-ldap.conf

    -rw-r--r--. 1 root root 3.2K Oct 30 2018 rsyslog.conf

    drwxr-xr-x. 6 root root 4.0K Sep 12 11:51 sysconfig

    drwxr-xr-x. 6 root root 4.0K Sep 18 10:58 security

    drwxr-xr-x. 2 root root 4.0K Sep 11 17:11 profile.d

    drwxr-xr-x. 2 root root 4.0K Aug 30 12:15 pam.d

    -r--r-----. 1 root root 4.3K Oct 30 2018 sudoers

    -rw-r--r--. 1 root root 4.4K May 16 05:01 wgetrc

    -rw-r--r--. 1 root root 4.6K Oct 30 2018 DIR_COLORS.lightbgcolor

    -rw-r--r--. 1 root root 5.0K Oct 30 2018 DIR_COLORS

    -rw-r--r--. 1 root root 5.1K Nov 5 2018 makedumpfile.conf.sample

    -rw-r--r--. 1 root root 5.1K Oct 31 2018 man_db.conf

    -rw-r--r--. 1 root root 5.6K Oct 30 2018 DIR_COLORS.256color

    -rw-r--r--. 1 root root 6.4K Oct 31 2018 protocols

    -rw-------. 1 tss tss 6.9K Aug 4 2017 tcsd.conf

    -rw-r--r--. 1 root root 7.1K Aug 30 12:12 kdump.conf

    -rw-r--r--. 1 root root 12K Aug 30 12:29 aliases.db

    -rw-r--r--. 1 root root 29K Sep 6 11:26 ld.so.cache

    -rw-r--r--. 1 root root 51K May 15 2013 mime.types

    -rw-r--r--. 1 root root 655K Jun 7 2013 services

    ls -lF:查找出來的目錄后面會加/

    [root@oldboy6666 ~] # ls -lF /etc

    total 1164

    drwxr-xr-x. 3 root root 101 Aug 30 12:12 abrt/

    -rw-r--r--. 1 root root 18 Sep 12 17:04 adjtime

    -rw-r--r--. 1 root root 1518 Jun 7 2013 aliases

    -rw-r--r--. 1 root root 12288 Aug 30 12:29 aliases.db

    drwxr-xr-x. 2 root root 236 Aug 30 12:13 alternatives/

    -rw-------. 1 root root 541 Apr 11 2018 anacrontab

    -rw-r--r--. 1 root root 55 Oct 30 2018 asound.conf

    drwxr-x---. 3 root root 43 Aug 30 12:13 audisp/

    drwxr-x---. 3 root root 83 Aug 30 12:29 audit/

    drwxr-xr-x. 2 root root 79 Sep 11 12:29 bash_completion.d/

    -rw-r--r--. 1 root root 2853 Oct 31 2018 bashrc

    drwxr-xr-x. 2 root root 6 Oct 31 2018 binfmt.d/

    -rw-r--r--. 1 root root 38 Nov 23 2018 centos-release

    -rw-r--r--. 1 root root 51 Nov 23 2018 centos-release-upstream

    drwxr-xr-x. 2 root root 6 Aug 4 2017 chkconfig.d/

    1.2.2 cd****

    cd/cd ~:切換到家目錄

    [root@server02 ~]# cd /opt

    [root@server02 opt]# ls

    121.cap download.cap lost+found starts tomcat_gz tomcat_nw

    30.cap hdtest.txt ntfs-3g_ntfsprogs-2011.4.12 testdisk tomcat_hn tomcat.tar.gz

    apache-jmeter-2.13 hs platform-tools-latest-linux testdisk.c tomcat_hrjq tomcat_th

    apache-jmeter-2.13.zip ifcfg-em1.bak res test.sh tomcat_ht tomcat_vod

    catalina.out ifcfg-em2.bak restart_app.sh tomcat tomcat_jd tomcat_whjj

    cfg kkstatr.sh rh tomcat_93792 tomcat_jinding viewstatus.sh

    download01.cap lo_config.sh shutdown_app.sh tomcat.bak tomcat_jy work

    download02.cap log smart tomcat_gpzx tomcat_kk

    download03.cap log0001.out start_app.sh tomcat_gx tomcat_license

    [root@server02 opt]# cd tomcat

    [root@server02 tomcat]# ls

    bin conf lib log NOTICE RUNNING.txt temp work

    cfg hs_err_pid32351.log LICENSE logs RELEASE-NOTES shared webapps

    cd ..:切換到上級目錄

    [root@server02 ~]#(1) cd /opt

    [root@server02 opt]# ls

    121.cap download.cap lost+found starts tomcat_gz tomcat_nw

    30.cap hdtest.txt ntfs-3g_ntfsprogs-2011.4.12 testdisk tomcat_hn tomcat.tar.gz

    apache-jmeter-2.13 hs platform-tools-latest-linux testdisk.c tomcat_hrjq tomcat_th

    apache-jmeter-2.13.zip ifcfg-em1.bak res test.sh tomcat_ht tomcat_vod

    catalina.out ifcfg-em2.bak restart_app.sh tomcat tomcat_jd tomcat_whjj

    cfg kkstatr.sh rh tomcat_93792 tomcat_jinding viewstatus.sh

    download01.cap lo_config.sh shutdown_app.sh tomcat.bak tomcat_jy work

    download02.cap log smart tomcat_gpzx tomcat_kk

    download03.cap log0001.out start_app.sh tomcat_gx tomcat_license

    [root@server02 opt]# (2)cd tomcat

    [root@server02 tomcat]# ls

    bin conf lib log NOTICE RUNNING.txt temp work

    cfg hs_err_pid32351.log LICENSE logs RELEASE-NOTES shared webapps

    [root@server02 tomcat]# (3)cd ..

    [root@server02 opt]# ls

    121.cap download.cap lost+found starts tomcat_gz tomcat_nw

    30.cap hdtest.txt ntfs-3g_ntfsprogs-2011.4.12 testdisk tomcat_hn tomcat.tar.gz

    apache-jmeter-2.13 hs platform-tools-latest-linux testdisk.c tomcat_hrjq tomcat_th

    apache-jmeter-2.13.zip ifcfg-em1.bak res test.sh tomcat_ht tomcat_vod

    catalina.out ifcfg-em2.bak restart_app.sh tomcat tomcat_jd tomcat_whjj

    cfg kkstatr.sh rh tomcat_93792 tomcat_jinding viewstatus.sh

    download01.cap lo_config.sh shutdown_app.sh tomcat.bak tomcat_jy work

    download02.cap log smart tomcat_gpzx tomcat_kk

    download03.cap log0001.out start_app.sh tomcat_gx tomcat_license

    [root@server02 opt]#

    cd - 切換到上一次所在的目錄

    [root@server02 tomcat]# (1)cd /opt/tomcat

    [root@server02 tomcat]# ls

    bin conf lib log NOTICE RUNNING.txt temp work

    cfg hs_err_pid32351.log LICENSE logs RELEASE-NOTES shared webapps

    [root@server02 tomcat]# (2)cd lib/

    [root@server02 lib]# ls

    annotations-api.jar catalina-tribes.jar jasper.jar tomcat-api.jar tomcat-i18n-fr.jar websocket-api.jar

    catalina-ant.jar ecj-4.3.1.jar jsp-api.jar tomcat-coyote.jar tomcat-i18n-ja.jar

    catalina-ha.jar el-api.jar servlet-api.jar tomcat-dbcp.jar tomcat-jdbc.jar

    catalina.jar jasper-el.jar tomcat7-websocket.jar tomcat-i18n-es.jar tomcat-util.jar

    [root@server02 lib]# cd /res/

    [root@server02 res]# ls

    93792 gpzx hrjq jd jy kk nw nw_mdml readme testso upload whjj

    backup gz ht jg jynew lost+found nw.bak nws smart th vod

    [root@server02 res]# (3)cd -

    /opt/tomcat/lib

    1.2.3 cp****

    cp:拷貝命令 cp 源目標 目的目標

    [root@server02 ll]# mkdir bb

    [root@server02 ll]# mkdir aa

    mkdir: 無法創建目錄"aa": 文件已存在

    [root@server02 ll]# mkdir aa

    mkdir: 無法創建目錄"aa": 文件已存在

    [root@server02 ll]# ls

    aa bb

    [root@server02 ll]# cp aa bb/

    cp: 略過目錄"aa"

    [root@server02 ll]# touch txt.txt

    [root@server02 ll]# cp txt.txt bb/

    [root@server02 ll]# cd bb

    [root@server02 bb]# ls

    txt.txt

    [root@server02 bb]#

    cp -r:遞歸處理

    [root@server02 ll]# mkdir bb

    [root@server02 ll]# mkdir aa

    mkdir: 無法創建目錄"aa": 文件已存在

    [root@server02 ll]# mkdir aa

    mkdir: 無法創建目錄"aa": 文件已存在

    [root@server02 ll]# ls

    aa bb

    [root@server02 ll]# cp aa bb/

    cp: 略過目錄"aa"

    [root@server02 ll]# touch txt.txt

    [root@server02 ll]# cp txt.txt bb/

    [root@server02 ll]# cd bb

    [root@server02 bb]# ls

    txt.txt

    [root@server02 bb]#

    cp -rf:強制覆蓋(\cp -r)|(/usr/bin/cp )

    [root@server02 ll]# ls

    '1.ttx 2.txt aa bb txt.txt

    [root@server02 ll]# 'cd bb

    > ls

    > ^C

    [root@server02 ll]# ls

    1.ttx 2.txt aa bb txt.txt

    [root@server02 ll]# cp -rf txt.txt ../

    [root@server02 ll]#

    1.2.5 mkdir****

    mkdir:創建目錄,但是只能創建一級目錄

    [root@server02 cdn]#

    [root@server02 cdn]# cd /opt/ll/

    [root@server02 ll]# ls

    1.ttx 2.txt aa bb ll.TXT txt.txt

    [root@server02 ll]# mkdir xx

    [root@server02 ll]#(1) ls

    1.ttx 2.txt aa bb ll.TXT txt.txt xx

    [root@server02 ll]# mkdir xx/aa/bb

    mkdir: 無法創建目錄"xx/aa/bb": 沒有那個文件或目錄

    mkdir -p:創建多級目錄和創建存在目錄的時候會忽略錯誤信息

    [root@server02 ll]# mkdir -p xx/AA/BB

    [root@server02 ll]# ls

    1.ttx 2.txt aa bb ll.TXT txt.txt xx

    [root@server02 ll]# cd xx

    [root@server02 xx]# ls

    AA

    [root@server02 xx]# cd AA

    [root@server02 AA]# ls

    BB

    [root@server02 AA]# cd BB

    [root@server02 BB]# ls

    [root@server02 BB]#

    mkdir -m:創建目錄的時候可以修改目錄權限

    [root@oldboy6666 ~] # mkdir aa

    [root@oldboy6666 ~] # ll -d aa

    drwxr-xr-x 2 root root 6 Sep 18 16:33 aa

    [root@oldboy6666 ~] # mkdir bb -m 777

    [root@oldboy6666 ~] # ll -d bb

    drwxrwxrwx 2 root root 6 Sep 18 16:34 bb

    [root@oldboy6666 ~] #

    mkdir -v:創建目錄的時候會顯示詳細信息

    [root@oldboy6666 ~] # mkdir cc -v

    mkdir: created directory 'cc'

    [root@oldboy6666 ~] #

    1.2.6 mv****

    mv 源文件目錄 目標文件目錄

    [root@server02 xx]# cd AA

    [root@server02 AA]# ls

    BB

    [root@server02 AA]# cd BB

    [root@server02 BB]# ls

    [root@server02 BB]# cd ..

    [root@server02 AA]# ls

    BB

    [root@server02 AA]# mv BB ../../

    [root@server02 AA]# ls

    [root@server02 AA]# cd ../..

    [root@server02 ll]# ls

    ttx 2.txt aa bb BB ll.TXT txt.txt xx

    mv 源文件 重命名后的文件

    [root@server02 ll]# ls

    1.ttx 2.txt aa bb BB ll.TXT txt.txt xx

    [root@server02 ll]# mv BB BBB

    [root@server02 ll]# ls

    1.ttx 2.txt aa bb BBB ll.TXT txt.txt xx

    [root@server02 ll]#

    1.2.7 pwd****

    pwd:查看文件所在的當前目錄

    [root@server02 ll]# pwd

    /opt/ll

    1.2.8 rename*******

    rename 修改的名字 要修改成什么名字 修改的文件有哪些

    [root@oldboyedu oldboy02] # rename txt log *.txt rename txt log *.txt

    You have new mail in /var/spool/mail/root

    [root@oldboyedu oldboy02] # ls

    001 008.log 015.log 022.log 029.log 036.log 043.log 050.log 057.log 064.log 071.log 078.log 085.log 092.log 099.log

    002.log 009.log 016.log 023.log 030.log 037.log 044.log 051.log 058.log 065.log 072.log 079.log 086.log 093.log 100.log

    003.log 010.log 017.log 024.log 031.log 038.log 045.log 052.log 059.log 066.log 073.log 080.log 087.log 094.log

    004.log 011.log 018.log 025.log 032.log 039.log 046.log 053.log 060.log 067.log 074.log 081.log 088.log 095.log

    005.log 012.log 019.log 026.log 033.log 040.log 047.log 054.log 061.log 068.log 075.log 082.log 089.log 096.log

    006.log 013.log 020.log 027.log 034.log 041.log 048.log 055.log 062.log 069.log 076.log 083.log 090.log 097.log

    007.log 014.log 021.log 028.log 035.log 042.log 049.log 056.log 063.log 070.log 077.log 084.log 091.log 098.log

    [root@oldboyedu oldboy02] #

    1.2.8.1 mv和rename的區別

    [root@oldboyedu oldboy02] #

    [root@oldboyedu oldboy02] # ls

    001 008.txt 015.txt 022.txt 029.txt 036.txt 043.txt 050.txt 057.txt 064.txt 071.txt 078.txt 085.txt 092.txt 099.txt

    002.txt 009.txt 016.txt 023.txt 030.txt 037.txt 044.txt 051.txt 058.txt 065.txt 072.txt 079.txt 086.txt 093.txt 100.txt

    003.txt 010.txt 017.txt 024.txt 031.txt 038.txt 045.txt 052.txt 059.txt 066.txt 073.txt 080.txt 087.txt 094.txt

    004.txt 011.txt 018.txt 025.txt 032.txt 039.txt 046.txt 053.txt 060.txt 067.txt 074.txt 081.txt 088.txt 095.txt

    005.txt 012.txt 019.txt 026.txt 033.txt 040.txt 047.txt 054.txt 061.txt 068.txt 075.txt 082.txt 089.txt 096.txt

    006.txt 013.txt 020.txt 027.txt 034.txt 041.txt 048.txt 055.txt 062.txt 069.txt 076.txt 083.txt 090.txt 097.txt

    007.txt 014.txt 021.txt 028.txt 035.txt 042.txt 049.txt 056.txt 063.txt 070.txt 077.txt 084.txt 091.txt 098.txt

    [root@oldboyedu oldboy02] # mv *.txt *.log 通過修改發現mv只能單個修改

    mv: target '*.log' is not a directory

    [root@oldboyedu oldboy02] #

    [root@oldboyedu oldboy02] #

    [root@oldboyedu oldboy02] # rename txt log *.txt 使用rename修改將txt的名字修改成log名字,並且是全部后綴為*.txt的文件

    You have new mail in /var/spool/mail/root

    [root@oldboyedu oldboy02] # ls

    001 008.log 015.log 022.log 029.log 036.log 043.log 050.log 057.log 064.log 071.log 078.log 085.log 092.log 099.log

    002.log 009.log 016.log 023.log 030.log 037.log 044.log 051.log 058.log 065.log 072.log 079.log 086.log 093.log 100.log

    003.log 010.log 017.log 024.log 031.log 038.log 045.log 052.log 059.log 066.log 073.log 080.log 087.log 094.log

    004.log 011.log 018.log 025.log 032.log 039.log 046.log 053.log 060.log 067.log 074.log 081.log 088.log 095.log

    005.log 012.log 019.log 026.log 033.log 040.log 047.log 054.log 061.log 068.log 075.log 082.log 089.log 096.log

    006.log 013.log 020.log 027.log 034.log 041.log 048.log 055.log 062.log 069.log 076.log 083.log 090.log 097.log

    007.log 014.log 021.log 028.log 035.log 042.log 049.log 056.log 063.log 070.log 077.log 084.log 091.log 098.log

    [root@oldboyedu oldboy02] #

    1.2.9 rm****

    rm:刪除文件,但是會有交互過程

    [root@server02 ll]# rm 1.ttx

    rm:是否刪除普通空文件 "1.ttx"y

    [root@server02 ll]# ls

    2.xls aa bb BBB bb.xls cc.xls dd.xls ll.TXT xls.txt xx

    [root@server02 ll]#

    rm -r:刪除文件和目錄,有交互過程

    [root@server02 ll]# rm -r aa 2.xls

    rm:是否刪除目錄 "aa"y

    rm:是否刪除普通空文件 "2.xls"y

    [root@server02 ll]#

    rm -rf:強制刪除文件和目錄,沒有交互過程(一般不建議使用)

    [root@server02 ll]# rm -rf cc.xls bb

    [root@server02 ll]#

    1.2.10 rmdir****

    rmdir:刪除空目錄

    [root@server02 ll]# rmdir BBB

    [root@server02 ll]# rmdir xx

    rmdir: 刪除 "xx" 失敗目錄非空

    [root@server02 ll]#

    1.2.11 touch***

    touch:創建文件/修改文件的時間戳

    [root@server02 ll]# touch cc.txt

    [root@server02 ll]# ll

    總用量 12

    drwxr-xr-x 2 root root 4096 2 27 16:16 bb.xls

    -rw-r--r-- 1 root root 0 2 27 17:09 cc.txt

    drwxr-xr-x 2 root root 4096 2 27 16:16 dd.xls

    -rw-r--r-- 1 root root 0 2 23 11:39 ll.TXT

    -rw-r--r-- 1 root root 0 2 23 11:08 xls.txt

    drwxr-xr-x 3 root root 4096 2 27 15:57 xx

    [root@server02 ll]#

    1.2.12 tree****

    tree:顯示目錄結構

    [root@server02 ll]# tree /opt/ll

    /opt/ll

    ├── bb.xls

    ├── cc.txt

    ├── dd.xls

    ├── ll.TXT

    ├── xls.txt

    └── xx

    └── AA

       

    4 directories, 3 files

    [root@server02 ll]#

    tree -L num:只顯示num行目錄

    [root@server02 ll]# tree -L 1 /opt/ll

    /opt/ll

    ├── bb.xls

    ├── dd.xls

    └── xx

       

    3 directories

    1.2.13 basename

    basename:即basename的作用是從文件名中去除目錄和后綴

    [root@server02 ll]# ls

    bb.xls cc.txt dd.xls ll.TXT xls.txt xx

    [root@server02 ll]# touch aa.txt

    [root@server02 ll]# touch aa.txt .

    [root@server02 ll]# touch aa.txt txt

    [root@server02 ll]# touch aa.txt .txt

    [root@server02 ll]# ls

    aa.txt bb.xls cc.txt dd.xls ll.TXT txt xls.txt xx

    [root@server02 ll]# basename /opt/ll/aa

    aa

    [root@server02 ll]# basename /opt/ll/aa.txt

    aa.txt

    [root@server02 ll]# basename /opt/ll/aa.txt .

    aa.txt

    [root@server02 ll]# basename /opt/ll/aa.txt txt

    aa.

    [root@server02 ll]# basename /opt/ll/aa.txt .txt

    aaq

    [root@server02 ll]#

    1.2.14 dirname

    dirname:令讀取指定路徑名刪除最后一個/及其后面的字符,保留其他部分

    [root@server02 ~]# dirname cd /opt

    dirname: 額外的操作數 "/opt"

    請嘗試執行"dirname --help"來獲取更多信息。

    [root@server02 ~]# dirname cd/opt

    cd

    [root@server02 ~]# dirname cd

    .

    [root@server02 ~]#

    [root@server02 ~]#

    [root@server02 ~]# dirname

    dirname: 缺少操作數

    請嘗試執行"dirname --help"來獲取更多信息。

    [root@server02 ~]# dirname cd

    .

    [root@server02 ~]# dirname /cd

    /

    1.2.15 chattr********

    chattr +(-)i:設定文件不能被刪除、改名、設定鏈接關系,同時不能寫入或新增內容

    [root@server02 ll]# chattr +i

    aa.txt aa.txt~ bb.xls/ cc.txt dd.xls/ ll.TXT txt .txt xls.txt xx/

    [root@server02 ll]# chattr +i cc.txt

    [root@server02 ll]# rm -rf cc.txt

    rm: 無法刪除"cc.txt": 不允許的操作

    [root@server02 ll]# ln cc.txt /cc.txt

    ln: 創建硬鏈接"/cc.txt" => "cc.txt": 無效的跨設備連接

    [root@server02 ll]# ln cc.txt ff.txt

    ln: 創建硬鏈接"ff.txt" => "cc.txt": 不允許的操作

    [root@server02 ll]#

    chattr +(-):a即append,設定該參數后,只能向文件中添加數據,而不能刪除

    [root@server02 ll]# chattr +a dd.xls

    [root@server02 ll]# ls

    aa.txt aa.txt~ bb.xls cc.txt dd.xls ll.TXT txt xls.txt xx

    [root@server02 ll]# rm -rf dd.xls

    rm: 無法刪除"dd.xls": 不允許的操作

    [root@server02 ll]# chattr +a ll.TXT

    [root@server02 ll]# ls

    aa.txt aa.txt~ bb.xls cc.txt dd.xls ll.TXT txt xls.txt xx

    [root@server02 ll]# rm -rf ll.TXT

    rm: 無法刪除"ll.TXT": 不允許的操作

    [root@server02 ll]# vim ll.TXT

       

    ~

    "ll.TXT" 0L, 0C 0,0-1 全部

    qqqqqqqqq

       

    "ll.TXT"

    "ll.TXT" E212: 無法打開並寫入文件

    "ll.TXT"

    "ll.TXT" E212: 無法打開並寫入文件

    請按 ENTER 或其它命令繼續

    1.2.16 lsattr******

    lsattr:查看文件是否加鎖了

    [root@server02 ll]# aa.txt aa.txt~ bb.xls cc.txt dd.xls ll.TXT txt xls.txt xx

    -bash: aa.txt: command not found

    [root@server02 ll]# ls

    aa.txt aa.txt~ bb.xls cc.txt dd.xls ll.TXT ll.TXT~ ll.TXz~ txt xls.txt xx

    [root@server02 ll]# lsattr aa.txt

    ----ia-------e- aa.txt

    1.2.17 file****

    file:file命令用來識別文件類型,也可用來辨別一些文件的編碼格式。它是通過查看文件的頭部信息來獲取文件類型

    file -b:不顯示文件名稱

    [root@nfs ~]# file linuxtest.txt

    linuxtest.txt: Bourne-Again shell script text executable

    [root@nfs ~]# file -b linuxtest.txt

    Bourne-Again shell script text executable

    [root@nfs ~]#

    file -c:詳細顯示指令執行過程

    [root@nfs ~]# file -c linuxtest.txt

    cont offset type opcode mask value desc

    [root@nfs ~]#

    file -L:查看軟連接

    [root@nfs etc]# touch aa.txt

    [root@nfs etc]# ln -s aa.txt /etc/sysconfig/network-scripts/bb.txt

    [root@nfs etc]# cd /etc/sysconfig/network-scripts/bb.txt

    -bash: cd: /etc/sysconfig/network-scripts/bb.txt: 沒有那個文件或目錄

    [root@nfs etc]# cd /etc/sysconfig/network-scripts/

    [root@nfs network-scripts]# ll bb.txt

    lrwxrwxrwx. 1 root root 6 4 12 21:45 bb.txt -> aa.txt

    [root@nfs network-scripts]# file -L bb.txt

    bb.txt: cannot open `bb.txt' (No such file or directory)

    [root@nfs network-scripts]#

    file -f:查看文件中的文件類型

    [root@nfs ~]# file -f linuxtest.txt

    #!/bin/bash: cannot open `#!/bin/bash' (No such file or directory)

    echo "aa": cannot open `echo "aa"' (No such file or directory)

    file -z:查看壓縮包里面的文件類型

    [root@nfs network-scripts]# tar -Pzcvf bb.tar.gz bb.txt

    bb.txt

    [root@nfs network-scripts]# ls

    bb.tar.gz ifcfg-eth1 ifdown-bnep ifdown-ipv6 ifdown-ppp ifdown-tunnel ifup-bnep ifup-ipv6 ifup-plusb ifup-routes ifup-wireless network-functions

    bb.txt ifcfg-lo ifdown-eth ifdown-isdn ifdown-routes ifup ifup-eth ifup-isdn ifup-post ifup-sit init.ipv6-global network-functions-ipv6

    ifcfg-eth0 ifdown ifdown-ippp ifdown-post ifdown-sit ifup-aliases ifup-ippp ifup-plip ifup-ppp ifup-tunnel net.hotplug

    [root@nfs network-scripts]# file -z bb.tar.gz

    bb.tar.gz: POSIX tar archive (GNU) (gzip compressed data, from Unix, last modified: Fri Apr 12 21:46:53 2019)

    1.2.18 md5sum

    md5sum:目標文件傳輸完成后和源文件進行對比

    1.獲取包,確保包正確無誤

       獲取包后,驗證包的MD5值:md5sum rc*.tar.gz

    2. 解壓縮到指定目錄

        確保對應的目錄存在

        tar -zxvf  rc1.tar.gz -C ./test_rc1

         tar -zxvf  rc2.tar.gz -C ./test_rc2

    3. 遞歸生成各文件的的MD5

        find ./test_rc1 -type f -print0| xargs -0 md5sum >> rc1_md5.txt

        find ./test_rc2 -type f -print0| xargs -0 md5sum >> rc2_md5.txt

    4. 比較兩文件的MD5

        diff -c rc1_md5.txt  rc2_md5.txt

         或者用UltraCompare Professional比對結果

    1.3 查看文件及內容處理命令

    1.3.1 cat***

    cat -n:查看文件並且給每行編號

    [root@nfs2 ~]# cat -n /etc/liangyuxing.txt

    1 root:x:0:0:root:/root:/bin/bash

    2 bin:x:1:1:bin:/bin:/sbin/nologin

    3 daemon:x:2:2:daemon:/sbin:/sbin/nologin

    4 adm:x:3:4:adm:/var/adm:/sbin/nologin

    5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

    6 sync:x:5:0:sync:/sbin:/bin/sync

    7 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

    8 halt:x:7:0:halt:/sbin:/sbin/halt

    9 mail:x:8:12:mail:/var/spool/mail:/sbin/nologin

    10 uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin

    11 operator:x:11:0:operator:/root:/sbin/nologin

    12

    13

    14 games:x:12:100:games:/usr/games:/sbin/nologin

    15 gopher:x:13:30:gopher:/var/gopher:/sbin/nologin

    16 ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin

    17 nobody:x:99:99:Nobody:/:/sbin/nologin

    18 vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin

    19

    20

    21 saslauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin

    22 postfix:x:89:89::/var/spool/postfix:/sbin/nologin

    23 sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin

    24 rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin

    25 rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin

    26 nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin

    cat -b:查看文件並且給每行編號,如果是空行,不給編號

    [root@nfs2 ~]# cat -b /etc/liangyuxing.txt

    1 root:x:0:0:root:/root:/bin/bash

    2 bin:x:1:1:bin:/bin:/sbin/nologin

    3 daemon:x:2:2:daemon:/sbin:/sbin/nologin

    4 adm:x:3:4:adm:/var/adm:/sbin/nologin

    5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

    6 sync:x:5:0:sync:/sbin:/bin/sync

    7 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

    8 halt:x:7:0:halt:/sbin:/sbin/halt

    9 mail:x:8:12:mail:/var/spool/mail:/sbin/nologin

    10 uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin

    11 operator:x:11:0:operator:/root:/sbin/nologin

       

       

    12 games:x:12:100:games:/usr/games:/sbin/nologin

    13 gopher:x:13:30:gopher:/var/gopher:/sbin/nologin

    14 ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin

    15 nobody:x:99:99:Nobody:/:/sbin/nologin

    16 vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin

       

       

    17 saslauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin

    18 postfix:x:89:89::/var/spool/postfix:/sbin/nologin

    19 sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin

    20 rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin

    21 rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin

    22 nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin

    cat -A:顯示所有(會將文件內容默認的$符號顯示出來)

    [root@oldboy6666 oldboy] # cat -A oldboy.txt

    oldboy$

    oldgirl$

    oldbaby$

    olddog$

    [root@oldboy6666 oldboy] #

    1.3.2 tac*******

    tac和cat功能一樣,只是tac是從后往前

    [root@nfs2 ~]# tac /etc/liangyuxing.txt

    nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin

    rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin

    rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin

    sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin

    postfix:x:89:89::/var/spool/postfix:/sbin/nologin

    saslauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin

       

       

    vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin

    nobody:x:99:99:Nobody:/:/sbin/nologin

    ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin

    gopher:x:13:30:gopher:/var/gopher:/sbin/nologin

    games:x:12:100:games:/usr/games:/sbin/nologin

       

       

    operator:x:11:0:operator:/root:/sbin/nologin

    uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin

    mail:x:8:12:mail:/var/spool/mail:/sbin/nologin

    halt:x:7:0:halt:/sbin:/sbin/halt

    shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

    sync:x:5:0:sync:/sbin:/bin/sync

    lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

    adm:x:3:4:adm:/var/adm:/sbin/nologin

    daemon:x:2:2:daemon:/sbin:/sbin/nologin

    bin:x:1:1:bin:/bin:/sbin/nologin

    root:x:0:0:root:/root:/bin/bash

    1.3.3 more****

    more:查看文檔

  • 回車鍵 換行
  • ctrl +F(空格鍵) 向下滾頁
  • ctrl +B 向上滾頁
  • q 退出

       

    [root@nfs2 ~]# more /etc/init.d/nfs

    #!/bin/sh

    #

    # nfs This shell script takes care of starting and stopping

    # the NFS services.

    #

    # chkconfig: - 30 60

    # description: NFS is a popular protocol for file sharing across networks.

    # This service provides NFS server functionality, which is \

    # configured via the /etc/exports file.

    # probe: true

    # config: /etc/sysconfig/nfs

       

    ### BEGIN INIT INFO

    # Provides: nfs

    # Required-Start: $local_fs $network $syslog $rpcbind

    # Required-Stop: $local_fs $network $syslog $rpcbind

    # Default-Stop: 0 1 6

    # Short-Description: Start up the NFS server sevice

    # Description: NFS is a popular protocol for file sharing across networks \

    # This service provides NFS server functionality, \

    # which is configured via the /etc/exports file.

    ### END INIT INFO

       

       

    # Source function library.

    . /etc/rc.d/init.d/functions

       

    # Source networking configuration.

    [ -f /etc/sysconfig/network ] && . /etc/sysconfig/network

       

    # Check for and source configuration file otherwise set defaults

    [ -f /etc/sysconfig/nfs ] && . /etc/sysconfig/nfs

       

    # Remote quota server

    [ -z "$RQUOTAD" ] && RQUOTAD=`type -path rpc.rquotad`

       

    RETVAL=0

    uid=`id | cut -d\( -f1 | cut -d= -f2`

       

    # See how we were called.

    case "$1" in

    start)

       

    # Check that networking is up.

    [ "${NETWORKING}" != "yes" ] && exit 6

    --More--(19%)

    擴展:空格鍵:切換頁

    回車鍵:換行

    q:退出more

    b:向上翻頁

    1.3.4 less****

    less:查看文檔

  • 回車鍵 換行
  • ctrl +F(空格鍵) 向下滾頁
  • ctrl +B 向上滾頁
  • q 退出
  • 方向上鍵 向上切換一行
  • 方向下鍵 向下切換一行
  • /文件內容 向下搜索內容
  • ?文件內容 向上搜索內容

    #!/bin/sh

    #

    # nfs This shell script takes care of starting and stopping

    # the NFS services.

    #

    # chkconfig: - 30 60

    # description: NFS is a popular protocol for file sharing across networks.

    # This service provides NFS server functionality, which is \

    # configured via the /etc/exports file.

    # probe: true

    # config: /etc/sysconfig/nfs

       

    ### BEGIN INIT INFO

    # Provides: nfs

    # Required-Start: $local_fs $network $syslog $rpcbind

    # Required-Stop: $local_fs $network $syslog $rpcbind

    # Default-Stop: 0 1 6

    # Short-Description: Start up the NFS server sevice

    # Description: NFS is a popular protocol for file sharing across networks \

    # This service provides NFS server functionality, \

    # which is configured via the /etc/exports file.

    ### END INIT INFO

       

       

    # Source function library.

    . /etc/rc.d/init.d/functions

       

    # Source networking configuration.

    [ -f /etc/sysconfig/network ] && . /etc/sysconfig/network

       

    # Check for and source configuration file otherwise set defaults

    [ -f /etc/sysconfig/nfs ] && . /etc/sysconfig/nfs

       

    # Remote quota server

    [ -z "$RQUOTAD" ] && RQUOTAD=`type -path rpc.rquotad`

       

    RETVAL=0

    uid=`id | cut -d\( -f1 | cut -d= -f2`

       

    # See how we were called.

    case "$1" in

    start)

       

    # Check that networking is up.

    [ "${NETWORKING}" != "yes" ] && exit 6

    :

    擴展:空格鍵(pagedown):向下切換頁

    回車鍵:換行

    q:退出

    ctrl +b(pageup):向上翻頁

       

    • 1.3.5 head***

    head -n 10:為查看文件的前10行(不加-n,默認也是10行)

    [root@nfs2 ~]# head -n 10 /etc/init.d/nfs

    #!/bin/sh

    #

    # nfs This shell script takes care of starting and stopping

    # the NFS services.

    #

    # chkconfig: - 30 60

    # description: NFS is a popular protocol for file sharing across networks.

    # This service provides NFS server functionality, which is \

    # configured via the /etc/exports file.

    # probe: true

    [root@nfs2 ~]#

    head -c 10:為查看文件的前10個字符

    [root@nfs2 ~]# head -c 10 /etc/init.d/nfs

    #!/bin/sh

    [root@nfs2 ~]#

    1.3.6 tail****

    tail:命令輸出文件的最后10行

    [root@nfs2 ~]# head -c 10 /etc/init.d/nfs

    #!/bin/sh

    [root@nfs2 ~]# tail /etc/init.d/nfs

    RETVAL=$?

    }

    ;;

    *)

    echo $"Usage: nfs {start|stop|status|restart|reload|force-reload|condrestart|try-restart|condstop}"

    RETVAL=2

    ;;

    esac

       

    exit $RETVAL

    tail -c 100:顯示文件的最后100個字符

    [root@nfs2 ~]# tail -c 100 /etc/init.d/nfs

    tus|restart|reload|force-reload|condrestart|try-restart|condstop}"

    RETVAL=2

    ;;

    esac

       

    exit $RETVAL

    [root@nfs2 ~]#

    tail -20f:追蹤日志文件的最后20行,如果一旦追蹤的文件被刪除,就算還原也不會繼續追蹤

    添加的記錄

    [root@oldboy6666 ~]#

    [root@oldboy6666 ~]# echo "123456" >> 1.txt

    [root@oldboy6666 ~]# echo "123456" >> 1.txt

    [root@oldboy6666 ~]# rm -rf 1.txt

    [root@oldboy6666 ~]# echo "123456" >> 1.txt

    [root@oldboy6666 ~]#

    追蹤的日志記錄

    [root@oldboy6666 ~]# tail -20f 1.txt

    #alias cman='man -M /usr//share/man/zh_CN'

    #alias cman='man -M /usr//share/man/zh_CN'

    #alias cman='man -M /usr//share/man/zh_CN'

    #alias cman='man -M /usr//share/man/zh_CN'

    #alias cman='man -M /usr//share/man/zh_CN'

    #alias cman='man -M /usr//share/man/zh_CN'

    #alias cman='man -M /usr//share/man/zh_CN'

    #alias cman='man -M /usr//share/man/zh_CN'

    #alias cman='man -M /usr//share/man/zh_CN'

    #alias cman='man -M /usr//share/man/zh_CN'

    #alias cman='man -M /usr//share/man/zh_CN'

    #alias cman='man -M /usr//share/man/zh_CN'

    #alias cman='man -M /usr//share/man/zh_CN'

    #alias cman='man -M /usr//share/man/zh_CN'

    #alias cman='man -M /usr//share/man/zh_CN'

    #alias cman='man -M /usr//share/man/zh_CN'

    #alias cman='man -M /usr//share/man/zh_CN'

    #alias cman='man -M /usr//share/man/zh_CN'

    #alias cman='man -M /usr//share/man/zh_CN'

    #alias cman='man -M /usr//share/man/zh_CN'

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

    123456

    123456

    tail -f -n 20:顯示文件的最后20行

    [root@nfs2 ~]# tail -f -n 20 /etc/init.d/nfs | cat -n

    1 [ -f /var/lock/subsys/nfs ] && {

    2 $0 stop

    3 $0 start

    4 RETVAL=$?

    5 }

    6 ;;

    7 condstop)

    8 [ -x /usr/sbin/rpc.svcgssd ] && /sbin/service rpcsvcgssd condstop

    9 [ -f /var/lock/subsys/nfs ] && {

    10 $0 stop

    11 RETVAL=$?

    12 }

    13 ;;

    14 *)

    15 echo $"Usage: nfs {start|stop|status|restart|reload|force-reload|condrestart|try-restart|condstop}"

    16 RETVAL=2

    17 ;;

    18 esac

    19

    20 exit $RETVAL

    tail -20F 查看日志文件的最后20行,並且如果文件刪除以后,會暫停追蹤,一旦文件恢復,會繼續追蹤

    測試數據

    [root@oldboy6666 ~]# echo "123456" >> 1.txt

    [root@oldboy6666 ~]# echo "123456" >> 1.txt

    [root@oldboy6666 ~]# echo "123456" >> 1.txt

    [root@oldboy6666 ~]# echo "123456" >> 1.txt

    [root@oldboy6666 ~]# rm -rf 1.txt

    [root@oldboy6666 ~]# echo "123456" >> 1.txt

    [root@oldboy6666 ~]# echo "123456" >> 1.txt

    [root@oldboy6666 ~]# echo "123456" >> 1.txt

    [root@oldboy6666 ~]#

    日志追蹤

    [root@oldboy6666 ~]# tail -F 20 1.txt

    tail: cannot open '20' for reading: No such file or directory

    ==> 1.txt <==

    1

    0

    1

    1

    0

    1

    1

    0

    1

    1

    123456

    123456

    123456

    123456

       

    tail: '1.txt' has become inaccessible: No such file or directory

    tail: '1.txt' has appeared; following end of new file

       

    ==> 1.txt <==

    123456

       

    ==> 1.txt <==

    123456

    123456

       

    1.3.7 cut

    cut -f 1-4 -d":"以:分割選擇選中的4列(-f 后面接選中的列;-d 后面接分隔符)

    [root@nfs2 ~]# cut -f 1-4 -d":" /etc/liangyuxing.txt

    root:x:0:0

    bin:x:1:1

    daemon:x:2:2

    adm:x:3:4

    lp:x:4:7

    sync:x:5:0

    shutdown:x:6:0

    halt:x:7:0

    mail:x:8:12

    uucp:x:10:14

    operator:x:11:0

       

       

    games:x:12:100

    gopher:x:13:30

    ftp:x:14:50

    nobody:x:99:99

    vcsa:x:69:69

       

       

    saslauth:x:499:76

    postfix:x:89:89

    sshd:x:74:74

    rpc:x:32:32

    rpcuser:x:29:29

    nfsnobody:x:65534:65534

    cut -c n-m:打印第n到m之間的字符

    [root@oldboyedu oldboy02] # echo $RANDOM 生成隨機數

    27077

    [root@oldboyedu oldboy02] # echo $RANDOM | md5sum 使用md5sum來進行匹配

    d8bb2da155ce92a832351329439d5a82 -

    [root@oldboyedu oldboy02] # echo $RANDOM | md5sum | cut -c 1-6 取出第16之間的字符

    ebc93b

    [root@oldboyedu oldboy02] #

    1.3.8 split

    split -b 10k +文件:以每字節10K的大小來分割文件

    [root@nfs2 data]# dd if=/dev/zero bs=100k count=1 of=file.data

    記錄了1+0 的讀入

    記錄了1+0 的寫出

    102400字節(102 kB)已復制,0.000426812 秒,240 MB/

    [root@nfs2 data]# ls

    file.data

    [root@nfs2 data]# split -b 10K file.data

    [root@nfs2 data]# ls

    file.data xaa xab xac xad xae xaf xag xah xai xaj

    [root@nfs2 data]#

    split -b 10k +文件 -d 2a:以每字節10K的大小來分割文件並且分割的文件首字符為2a開頭

  • -b:指定切割字符的大小
  • -d:指定切割字符前面以什么開頭

    [root@nfs2 data]# split -b 10K file.data -d 2a

    [root@nfs2 data]# ls

    2a00 2a01 2a02 2a03 2a04 2a05 2a06 2a07 2a08 2a09 file.data

    [root@nfs2 data]#

    1.3.9 paste

  • -d:指定合並文件之間用什么進行分割

    [root@oldboyedu oldboy02] # echo oldboy > oldboy.txt

    [root@oldboyedu oldboy02] # echo oldboy01 > oldboy01.txt

    [root@oldboyedu oldboy02] # echo oldboy02 > oldboy02.txt

    [root@oldboyedu oldboy02] # paste oldboy.txt oldboy01.txt oldboy02.txt 合並這3個文件

    oldboy    oldboy01    oldboy02

    [root@oldboyedu oldboy02] # paste -d "\n" oldboy.txt oldboy01.txt oldboy02.txt 合並這3個文件內容並且使用-d參數指定中間使用什么進行分割

    oldboy

    oldboy01

    oldboy02

    You have new mail in /var/spool/mail/root

    [root@oldboyedu oldboy02] #

    1.3.10 sort

    sort:排序命令(默認以第一列排序)

    [root@nfs2 data]# sort /etc/liangyuxing.txt

    adm:x:3:4:adm:/var/adm:/sbin/nologin

    bin:x:1:1:bin:/bin:/sbin/nologin

    daemon:x:2:2:daemon:/sbin:/sbin/nologin

    ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin

    games:x:12:100:games:/usr/games:/sbin/nologin

    gopher:x:13:30:gopher:/var/gopher:/sbin/nologin

    halt:x:7:0:halt:/sbin:/sbin/halt

    lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

    mail:x:8:12:mail:/var/spool/mail:/sbin/nologin

    nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin

    nobody:x:99:99:Nobody:/:/sbin/nologin

    operator:x:11:0:operator:/root:/sbin/nologin

    postfix:x:89:89::/var/spool/postfix:/sbin/nologin

    root:x:0:0:root:/root:/bin/bash

    rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin

    rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin

    saslauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin

    shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

    sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin

    sync:x:5:0:sync:/sbin:/bin/sync

    uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin

    vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin

    [root@nfs2 data]#

    sort -u:去除重復(相當於uniq -c)

    [root@nfs2 data]# sort -u /etc/liangyuxing.txt

       

    adm:x:3:4:adm:/var/adm:/sbin/nologin

    bin:x:1:1:bin:/bin:/sbin/nologin

    daemon:x:2:2:daemon:/sbin:/sbin/nologin

    ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin

    games:x:12:100:games:/usr/games:/sbin/nologin

    gopher:x:13:30:gopher:/var/gopher:/sbin/nologin

    halt:x:7:0:halt:/sbin:/sbin/halt

    lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

    mail:x:8:12:mail:/var/spool/mail:/sbin/nologin

    nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin

    nobody:x:99:99:Nobody:/:/sbin/nologin

    operator:x:11:0:operator:/root:/sbin/nologin

    postfix:x:89:89::/var/spool/postfix:/sbin/nologin

    root:x:0:0:root:/root:/bin/bash

    rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin

    rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin

    saslauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin

    shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

    sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin

    sync:x:5:0:sync:/sbin:/bin/sync

    uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin

    vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin

    [root@nfs2 data]#

    sort -nk 2 -t: +文件:以:為分隔符,第2列進行從小到大排序

  • -t:后面加分隔符
  • -k:以第幾列為分隔符
  • -n:從小到大開始排序(先大寫字母,在小寫字母,在數字,在特殊字符)
  • -r:反向排序

    [root@oldboyedu oldboy02] # sort -nk 2 -t: passwd_lyx.txt

    AAA:BBB

    adm:x:3:4:adm:/var/adm:/sbin/nologin

    bin:x:1:1:bin:/bin:/sbin/nologin

    daemon:x:2:2:daemon:/sbin:/sbin/nologin

    dbus:x:81:81:System message bus:/:/sbin/nologin

    ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin

    games:x:12:100:games:/usr/games:/sbin/nologin

    halt:x:7:0:halt:/sbin:/sbin/halt

    lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

    mail:x:8:12:mail:/var/spool/mail:/sbin/nologin

    nobody:x:99:99:Nobody:/:/sbin/nologin

    operator:x:11:0:operator:/root:/sbin/nologin

    root:x:0:0:root:/root:/bin/bash

    shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

    sync:x:5:0:sync:/sbin:/bin/sync

    systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin

    123:111

    ^$:9999

    [root@oldboyedu oldboy02] #

    1.3.11 uniq****

    uniq -c:統計有多少個重復的行(結合sort使用)

    [root@model test]# sort uniq.txt | uniq -c

    4 11111

    1 22222

    1 33333

    1 4444

    1 44444

    1 444444

    1 44444455555

    1 6666666

    [root@model test]#

    uniq -d:查找出帶有重復的行(結合sort使用)

    [root@model test]# cat uniq.txt

    11111

    22222

    11111

    11111

    33333

    444444

    11111

    4444

    44444

    44444455555

    6666666

       

       

    [root@model test]# sort uniq.txt | uniq -d

    11111

    [root@model test]#

    uniq -u:查找出單一的行

    [root@model test]# sort uniq.txt | uniq -u

    22222

    33333

    4444

    44444

    444444

    44444455555

    6666666

    [root@model test]#

    1.3.12 wc****

    wc名字用來計算數字,通常前面會將結果查出來后面進行計算

    wc -l:用於查看有多少行

    [root@model test]# sort uniq.txt | wc -l

    11

    [root@model test]#

    wc -c:用於查看有多少字節

    [root@model test]# sort uniq.txt | wc -c

    74

    [root@model test]#

    wc -w:用於查看多少個字

    [root@model test]# sort uniq.txt | wc -w

    11

    [root@model test]#

    1.3.13 iconv

    iconv -l:列出當前支持的字符編碼

    [root@model test]# iconv -l

    The following list contain all the coded character sets known. This does

    not necessarily mean that all combinations of these names can be used for

    the FROM and TO command line parameters. One coded character set can be

    listed with several different names (aliases).

       

    437, 500, 500V1, 850, 851, 852, 855, 856, 857, 860, 861, 862, 863, 864, 865,

    866, 866NAV, 869, 874, 904, 1026, 1046, 1047, 8859_1, 8859_2, 8859_3, 8859_4,

    8859_5, 8859_6, 8859_7, 8859_8, 8859_9, 10646-1:1993, 10646-1:1993/UCS4,

    ANSI_X3.4-1968, ANSI_X3.4-1986, ANSI_X3.4, ANSI_X3.110-1983, ANSI_X3.110,

    ARABIC, ARABIC7, ARMSCII-8, ASCII, ASMO-708, ASMO_449, BALTIC, BIG-5,

    BIG-FIVE, BIG5-HKSCS, BIG5, BIG5HKSCS, BIGFIVE, BRF, BS_4730, CA, CN-BIG5,

    CN-GB, CN, CP-AR, CP-GR, CP-HU, CP037, CP038, CP273, CP274, CP275, CP278,

    CP280, CP281, CP282, CP284, CP285, CP290, CP297, CP367, CP420, CP423, CP424,

    CP437, CP500, CP737, CP775, CP803, CP813, CP819, CP850, CP851, CP852, CP855,

    CP856, CP857, CP860, CP861, CP862, CP863, CP864, CP865, CP866, CP866NAV,

    CP868, CP869, CP870, CP871, CP874, CP875, CP880, CP891, CP901, CP902, CP903,

    CP904, CP905, CP912, CP915, CP916, CP918, CP920, CP921, CP922, CP930, CP932,

    CP933, CP935, CP936, CP937, CP939, CP949, CP950, CP1004, CP1008, CP1025,

    CP1026, CP1046, CP1047, CP1070, CP1079, CP1081, CP1084, CP1089, CP1097,

    CP1112, CP1122, CP1123, CP1124, CP1125, CP1129, CP1130, CP1132, CP1133,

    CP1137, CP1140, CP1141, CP1142, CP1143, CP1144, CP1145, CP1146, CP1147,

    CP1148, CP1149, CP1153, CP1154, CP1155, CP1156, CP1157, CP1158, CP1160,

    CP1161, CP1162, CP1163, CP1164, CP1166, CP1167, CP1250, CP1251, CP1252,

    CP1253, CP1254, CP1255, CP1256, CP1257, CP1258, CP1282, CP1361, CP1364,

    CP1371, CP1388, CP1390, CP1399, CP4517, CP4899, CP4909, CP4971, CP5347,

    CP9030, CP9066, CP9448, CP10007, CP12712, CP16804, CPIBM861, CSA7-1, CSA7-2,

    CSASCII, CSA_T500-1983, CSA_T500, CSA_Z243.4-1985-1, CSA_Z243.4-1985-2,

    CSA_Z243.419851, CSA_Z243.419852, CSDECMCS, CSEBCDICATDE, CSEBCDICATDEA,

    CSEBCDICCAFR, CSEBCDICDKNO, CSEBCDICDKNOA, CSEBCDICES, CSEBCDICESA,

    CSEBCDICESS, CSEBCDICFISE, CSEBCDICFISEA, CSEBCDICFR, CSEBCDICIT, CSEBCDICPT,

    CSEBCDICUK, CSEBCDICUS, CSEUCKR, CSEUCPKDFMTJAPANESE, CSGB2312, CSHPROMAN8,

    CSIBM037, CSIBM038, CSIBM273, CSIBM274, CSIBM275, CSIBM277, CSIBM278,

    CSIBM280, CSIBM281, CSIBM284, CSIBM285, CSIBM290, CSIBM297, CSIBM420,

    CSIBM423, CSIBM424, CSIBM500, CSIBM803, CSIBM851, CSIBM855, CSIBM856,

    CSIBM857, CSIBM860, CSIBM863, CSIBM864, CSIBM865, CSIBM866, CSIBM868,

    CSIBM869, CSIBM870, CSIBM871, CSIBM880, CSIBM891, CSIBM901, CSIBM902,

    CSIBM903, CSIBM904, CSIBM905, CSIBM918, CSIBM921, CSIBM922, CSIBM930,

    CSIBM932, CSIBM933, CSIBM935, CSIBM937, CSIBM939, CSIBM943, CSIBM1008,

    CSIBM1025, CSIBM1026, CSIBM1097, CSIBM1112, CSIBM1122, CSIBM1123, CSIBM1124,

    CSIBM1129, CSIBM1130, CSIBM1132, CSIBM1133, CSIBM1137, CSIBM1140, CSIBM1141,

    CSIBM1142, CSIBM1143, CSIBM1144, CSIBM1145, CSIBM1146, CSIBM1147, CSIBM1148,

    CSIBM1149, CSIBM1153, CSIBM1154, CSIBM1155, CSIBM1156, CSIBM1157, CSIBM1158,

    CSIBM1160, CSIBM1161, CSIBM1163, CSIBM1164, CSIBM1166, CSIBM1167, CSIBM1364,

    CSIBM1371, CSIBM1388, CSIBM1390, CSIBM1399, CSIBM4517, CSIBM4899, CSIBM4909,

    CSIBM4971, CSIBM5347, CSIBM9030, CSIBM9066, CSIBM9448, CSIBM12712,

    CSIBM16804, CSIBM11621162, CSISO4UNITEDKINGDOM, CSISO10SWEDISH,

    CSISO11SWEDISHFORNAMES, CSISO14JISC6220RO, CSISO15ITALIAN, CSISO16PORTUGESE,

    CSISO17SPANISH, CSISO18GREEK7OLD, CSISO19LATINGREEK, CSISO21GERMAN,

    CSISO25FRENCH, CSISO27LATINGREEK1, CSISO49INIS, CSISO50INIS8,

    CSISO51INISCYRILLIC, CSISO58GB1988, CSISO60DANISHNORWEGIAN,

    CSISO60NORWEGIAN1, CSISO61NORWEGIAN2, CSISO69FRENCH, CSISO84PORTUGUESE2,

    CSISO85SPANISH2, CSISO86HUNGARIAN, CSISO88GREEK7, CSISO89ASMO449, CSISO90,

    CSISO92JISC62991984B, CSISO99NAPLPS, CSISO103T618BIT, CSISO111ECMACYRILLIC,

    CSISO121CANADIAN1, CSISO122CANADIAN2, CSISO139CSN369103, CSISO141JUSIB1002,

    CSISO143IECP271, CSISO150, CSISO150GREEKCCITT, CSISO151CUBA,

    CSISO153GOST1976874, CSISO646DANISH, CSISO2022CN, CSISO2022JP, CSISO2022JP2,

    CSISO2022KR, CSISO2033, CSISO5427CYRILLIC, CSISO5427CYRILLIC1981,

    CSISO5428GREEK, CSISO10367BOX, CSISOLATIN1, CSISOLATIN2, CSISOLATIN3,

    CSISOLATIN4, CSISOLATIN5, CSISOLATIN6, CSISOLATINARABIC, CSISOLATINCYRILLIC,

    CSISOLATINGREEK, CSISOLATINHEBREW, CSKOI8R, CSKSC5636, CSMACINTOSH,

    CSNATSDANO, CSNATSSEFI, CSN_369103, CSPC8CODEPAGE437, CSPC775BALTIC,

    CSPC850MULTILINGUAL, CSPC862LATINHEBREW, CSPCP852, CSSHIFTJIS, CSUCS4,

    CSUNICODE, CSWINDOWS31J, CUBA, CWI-2, CWI, CYRILLIC, DE, DEC-MCS, DEC,

    DECMCS, DIN_66003, DK, DS2089, DS_2089, E13B, EBCDIC-AT-DE-A, EBCDIC-AT-DE,

    EBCDIC-BE, EBCDIC-BR, EBCDIC-CA-FR, EBCDIC-CP-AR1, EBCDIC-CP-AR2,

    EBCDIC-CP-BE, EBCDIC-CP-CA, EBCDIC-CP-CH, EBCDIC-CP-DK, EBCDIC-CP-ES,

    EBCDIC-CP-FI, EBCDIC-CP-FR, EBCDIC-CP-GB, EBCDIC-CP-GR, EBCDIC-CP-HE,

    EBCDIC-CP-IS, EBCDIC-CP-IT, EBCDIC-CP-NL, EBCDIC-CP-NO, EBCDIC-CP-ROECE,

    EBCDIC-CP-SE, EBCDIC-CP-TR, EBCDIC-CP-US, EBCDIC-CP-WT, EBCDIC-CP-YU,

    EBCDIC-CYRILLIC, EBCDIC-DK-NO-A, EBCDIC-DK-NO, EBCDIC-ES-A, EBCDIC-ES-S,

    EBCDIC-ES, EBCDIC-FI-SE-A, EBCDIC-FI-SE, EBCDIC-FR, EBCDIC-GREEK, EBCDIC-INT,

    EBCDIC-INT1, EBCDIC-IS-FRISS, EBCDIC-IT, EBCDIC-JP-E, EBCDIC-JP-KANA,

    EBCDIC-PT, EBCDIC-UK, EBCDIC-US, EBCDICATDE, EBCDICATDEA, EBCDICCAFR,

    EBCDICDKNO, EBCDICDKNOA, EBCDICES, EBCDICESA, EBCDICESS, EBCDICFISE,

    EBCDICFISEA, EBCDICFR, EBCDICISFRISS, EBCDICIT, EBCDICPT, EBCDICUK, EBCDICUS,

    ECMA-114, ECMA-118, ECMA-128, ECMA-CYRILLIC, ECMACYRILLIC, ELOT_928, ES, ES2,

    EUC-CN, EUC-JISX0213, EUC-JP-MS, EUC-JP, EUC-KR, EUC-TW, EUCCN, EUCJP-MS,

    EUCJP-OPEN, EUCJP-WIN, EUCJP, EUCKR, EUCTW, FI, FR, GB, GB2312, GB13000,

    GB18030, GBK, GB_1988-80, GB_198880, GEORGIAN-ACADEMY, GEORGIAN-PS,

    GOST_19768-74, GOST_19768, GOST_1976874, GREEK-CCITT, GREEK, GREEK7-OLD,

    GREEK7, GREEK7OLD, GREEK8, GREEKCCITT, HEBREW, HP-GREEK8, HP-ROMAN8,

    HP-ROMAN9, HP-THAI8, HP-TURKISH8, HPGREEK8, HPROMAN8, HPROMAN9, HPTHAI8,

    HPTURKISH8, HU, IBM-803, IBM-856, IBM-901, IBM-902, IBM-921, IBM-922,

    IBM-930, IBM-932, IBM-933, IBM-935, IBM-937, IBM-939, IBM-943, IBM-1008,

    IBM-1025, IBM-1046, IBM-1047, IBM-1097, IBM-1112, IBM-1122, IBM-1123,

    IBM-1124, IBM-1129, IBM-1130, IBM-1132, IBM-1133, IBM-1137, IBM-1140,

    IBM-1141, IBM-1142, IBM-1143, IBM-1144, IBM-1145, IBM-1146, IBM-1147,

    IBM-1148, IBM-1149, IBM-1153, IBM-1154, IBM-1155, IBM-1156, IBM-1157,

    IBM-1158, IBM-1160, IBM-1161, IBM-1162, IBM-1163, IBM-1164, IBM-1166,

    IBM-1167, IBM-1364, IBM-1371, IBM-1388, IBM-1390, IBM-1399, IBM-4517,

    IBM-4899, IBM-4909, IBM-4971, IBM-5347, IBM-9030, IBM-9066, IBM-9448,

    IBM-12712, IBM-16804, IBM037, IBM038, IBM256, IBM273, IBM274, IBM275, IBM277,

    IBM278, IBM280, IBM281, IBM284, IBM285, IBM290, IBM297, IBM367, IBM420,

    IBM423, IBM424, IBM437, IBM500, IBM775, IBM803, IBM813, IBM819, IBM848,

    IBM850, IBM851, IBM852, IBM855, IBM856, IBM857, IBM860, IBM861, IBM862,

    IBM863, IBM864, IBM865, IBM866, IBM866NAV, IBM868, IBM869, IBM870, IBM871,

    IBM874, IBM875, IBM880, IBM891, IBM901, IBM902, IBM903, IBM904, IBM905,

    IBM912, IBM915, IBM916, IBM918, IBM920, IBM921, IBM922, IBM930, IBM932,

    IBM933, IBM935, IBM937, IBM939, IBM943, IBM1004, IBM1008, IBM1025, IBM1026,

    IBM1046, IBM1047, IBM1089, IBM1097, IBM1112, IBM1122, IBM1123, IBM1124,

    IBM1129, IBM1130, IBM1132, IBM1133, IBM1137, IBM1140, IBM1141, IBM1142,

    IBM1143, IBM1144, IBM1145, IBM1146, IBM1147, IBM1148, IBM1149, IBM1153,

    IBM1154, IBM1155, IBM1156, IBM1157, IBM1158, IBM1160, IBM1161, IBM1162,

    IBM1163, IBM1164, IBM1166, IBM1167, IBM1364, IBM1371, IBM1388, IBM1390,

    IBM1399, IBM4517, IBM4899, IBM4909, IBM4971, IBM5347, IBM9030, IBM9066,

    IBM9448, IBM12712, IBM16804, IEC_P27-1, IEC_P271, INIS-8, INIS-CYRILLIC,

    INIS, INIS8, INISCYRILLIC, ISIRI-3342, ISIRI3342, ISO-2022-CN-EXT,

    ISO-2022-CN, ISO-2022-JP-2, ISO-2022-JP-3, ISO-2022-JP, ISO-2022-KR,

    ISO-8859-1, ISO-8859-2, ISO-8859-3, ISO-8859-4, ISO-8859-5, ISO-8859-6,

    ISO-8859-7, ISO-8859-8, ISO-8859-9, ISO-8859-9E, ISO-8859-10, ISO-8859-11,

    ISO-8859-13, ISO-8859-14, ISO-8859-15, ISO-8859-16, ISO-10646-UCS-2,

    ISO-10646, ISO-10646/UCS2, ISO-10646/UCS4, ISO-10646/UTF-8, ISO-10646/UTF8,

    ISO-CELTIC, ISO-IR-4, ISO-IR-6, ISO-IR-8-1, ISO-IR-9-1, ISO-IR-10, ISO-IR-11,

    ISO-IR-14, ISO-IR-15, ISO-IR-16, ISO-IR-17, ISO-IR-18, ISO-IR-19, ISO-IR-21,

    ISO-IR-25, ISO-IR-27, ISO-IR-37, ISO-IR-49, ISO-IR-50, ISO-IR-51, ISO-IR-54,

    ISO-IR-55, ISO-IR-57, ISO-IR-60, ISO-IR-61, ISO-IR-69, ISO-IR-84, ISO-IR-85,

    ISO-IR-86, ISO-IR-88, ISO-IR-89, ISO-IR-90, ISO-IR-92, ISO-IR-98, ISO-IR-99,

    ISO-IR-100, ISO-IR-101, ISO-IR-103, ISO-IR-109, ISO-IR-110, ISO-IR-111,

    ISO-IR-121, ISO-IR-122, ISO-IR-126, ISO-IR-127, ISO-IR-138, ISO-IR-139,

    ISO-IR-141, ISO-IR-143, ISO-IR-144, ISO-IR-148, ISO-IR-150, ISO-IR-151,

    ISO-IR-153, ISO-IR-155, ISO-IR-156, ISO-IR-157, ISO-IR-166, ISO-IR-179,

    ISO-IR-193, ISO-IR-197, ISO-IR-199, ISO-IR-203, ISO-IR-209, ISO-IR-226,

    ISO/TR_11548-1, ISO646-CA, ISO646-CA2, ISO646-CN, ISO646-CU, ISO646-DE,

    ISO646-DK, ISO646-ES, ISO646-ES2, ISO646-FI, ISO646-FR, ISO646-FR1,

    ISO646-GB, ISO646-HU, ISO646-IT, ISO646-JP-OCR-B, ISO646-JP, ISO646-KR,

    ISO646-NO, ISO646-NO2, ISO646-PT, ISO646-PT2, ISO646-SE, ISO646-SE2,

    ISO646-US, ISO646-YU, ISO2022CN, ISO2022CNEXT, ISO2022JP, ISO2022JP2,

    ISO2022KR, ISO6937, ISO8859-1, ISO8859-2, ISO8859-3, ISO8859-4, ISO8859-5,

    ISO8859-6, ISO8859-7, ISO8859-8, ISO8859-9, ISO8859-9E, ISO8859-10,

    ISO8859-11, ISO8859-13, ISO8859-14, ISO8859-15, ISO8859-16, ISO11548-1,

    ISO88591, ISO88592, ISO88593, ISO88594, ISO88595, ISO88596, ISO88597,

    ISO88598, ISO88599, ISO88599E, ISO885910, ISO885911, ISO885913, ISO885914,

    ISO885915, ISO885916, ISO_646.IRV:1991, ISO_2033-1983, ISO_2033,

    ISO_5427-EXT, ISO_5427, ISO_5427:1981, ISO_5427EXT, ISO_5428, ISO_5428:1980,

    ISO_6937-2, ISO_6937-2:1983, ISO_6937, ISO_6937:1992, ISO_8859-1,

    ISO_8859-1:1987, ISO_8859-2, ISO_8859-2:1987, ISO_8859-3, ISO_8859-3:1988,

    ISO_8859-4, ISO_8859-4:1988, ISO_8859-5, ISO_8859-5:1988, ISO_8859-6,

    ISO_8859-6:1987, ISO_8859-7, ISO_8859-7:1987, ISO_8859-7:2003, ISO_8859-8,

    ISO_8859-8:1988, ISO_8859-9, ISO_8859-9:1989, ISO_8859-9E, ISO_8859-10,

    ISO_8859-10:1992, ISO_8859-14, ISO_8859-14:1998, ISO_8859-15,

    ISO_8859-15:1998, ISO_8859-16, ISO_8859-16:2001, ISO_9036, ISO_10367-BOX,

    ISO_10367BOX, ISO_11548-1, ISO_69372, IT, JIS_C6220-1969-RO,

    JIS_C6229-1984-B, JIS_C62201969RO, JIS_C62291984B, JOHAB, JP-OCR-B, JP, JS,

    JUS_I.B1.002, KOI-7, KOI-8, KOI8-R, KOI8-RU, KOI8-T, KOI8-U, KOI8, KOI8R,

    KOI8U, KSC5636, L1, L2, L3, L4, L5, L6, L7, L8, L10, LATIN-9, LATIN-GREEK-1,

    LATIN-GREEK, LATIN1, LATIN2, LATIN3, LATIN4, LATIN5, LATIN6, LATIN7, LATIN8,

    LATIN9, LATIN10, LATINGREEK, LATINGREEK1, MAC-CENTRALEUROPE, MAC-CYRILLIC,

    MAC-IS, MAC-SAMI, MAC-UK, MAC, MACCYRILLIC, MACINTOSH, MACIS, MACUK,

    MACUKRAINIAN, MIK, MS-ANSI, MS-ARAB, MS-CYRL, MS-EE, MS-GREEK, MS-HEBR,

    MS-MAC-CYRILLIC, MS-TURK, MS932, MS936, MSCP949, MSCP1361, MSMACCYRILLIC,

    MSZ_7795.3, MS_KANJI, NAPLPS, NATS-DANO, NATS-SEFI, NATSDANO, NATSSEFI,

    NC_NC0010, NC_NC00-10, NC_NC00-10:81, NF_Z_62-010, NF_Z_62-010_(1973),

    NF_Z_62-010_1973, NF_Z_62010, NF_Z_62010_1973, NO, NO2, NS_4551-1, NS_4551-2,

    NS_45511, NS_45512, OS2LATIN1, OSF00010001, OSF00010002, OSF00010003,

    OSF00010004, OSF00010005, OSF00010006, OSF00010007, OSF00010008, OSF00010009,

    OSF0001000A, OSF00010020, OSF00010100, OSF00010101, OSF00010102, OSF00010104,

    OSF00010105, OSF00010106, OSF00030010, OSF0004000A, OSF0005000A, OSF05010001,

    OSF100201A4, OSF100201A8, OSF100201B5, OSF100201F4, OSF100203B5, OSF1002011C,

    OSF1002011D, OSF1002035D, OSF1002035E, OSF1002035F, OSF1002036B, OSF1002037B,

    OSF10010001, OSF10010004, OSF10010006, OSF10020025, OSF10020111, OSF10020115,

    OSF10020116, OSF10020118, OSF10020122, OSF10020129, OSF10020352, OSF10020354,

    OSF10020357, OSF10020359, OSF10020360, OSF10020364, OSF10020365, OSF10020366,

    OSF10020367, OSF10020370, OSF10020387, OSF10020388, OSF10020396, OSF10020402,

    OSF10020417, PT, PT2, PT154, R8, R9, RK1048, ROMAN8, ROMAN9, RUSCII, SE, SE2,

    SEN_850200_B, SEN_850200_C, SHIFT-JIS, SHIFT_JIS, SHIFT_JISX0213, SJIS-OPEN,

    SJIS-WIN, SJIS, SS636127, STRK1048-2002, ST_SEV_358-88, T.61-8BIT, T.61,

    T.618BIT, TCVN-5712, TCVN, TCVN5712-1, TCVN5712-1:1993, THAI8, TIS-620,

    TIS620-0, TIS620.2529-1, TIS620.2533-0, TIS620, TS-5881, TSCII, TURKISH8,

    UCS-2, UCS-2BE, UCS-2LE, UCS-4, UCS-4BE, UCS-4LE, UCS2, UCS4, UHC, UJIS, UK,

    UNICODE, UNICODEBIG, UNICODELITTLE, US-ASCII, US, UTF-7, UTF-8, UTF-16,

    UTF-16BE, UTF-16LE, UTF-32, UTF-32BE, UTF-32LE, UTF7, UTF8, UTF16, UTF16BE,

    UTF16LE, UTF32, UTF32BE, UTF32LE, VISCII, WCHAR_T, WIN-SAMI-2, WINBALTRIM,

    WINDOWS-31J, WINDOWS-874, WINDOWS-936, WINDOWS-1250, WINDOWS-1251,

    WINDOWS-1252, WINDOWS-1253, WINDOWS-1254, WINDOWS-1255, WINDOWS-1256,

    WINDOWS-1257, WINDOWS-1258, WINSAMI2, WS2, YU

    [root@model test]#

    1.3.14 dos2unix

    用於將dos文本轉換成unix

    [root@model test]# ls

    file1 lin.bat linzhou3Dbobo.bat uniq.txt

    [root@model test]# dos2unix lin.bat

    dos2unix: converting file lin.bat to UNIX format ...

    [root@model test]# cat lin.bat

    @ECHO OFF

       

    echo "V?′|-2?·?D22Ξ·¨?3°2?"

       

    echo "--------------------------------"

       

    set /p ip="Please input contorl ip: "

       

    adb kill-server

       

    adb start-server

       

    adb connect %ip%

       

    adb uninstall com.bobo.splayer

       

    adb install C:\Users\Administrator\Desktop\3dbb_5.7.2_dangbei.apk

       

    adb reboot

    [root@model test]#

    dos2unix -n:不改變原先的腳本,在副本添加(-k:不改變原先的屬性)

    [root@model test]# dos2unix -n -k linzhou3Dbobo.bat lz3d.bat

    dos2unix: converting file linzhou3Dbobo.bat to file lz3d.bat in UNIX format ...

    正常的:[root@model test]# vim linzhou3Dbobo.bat

       

    @ECHO OFF

    ^M

    echo "á??Y′|àí2?·?3D22?T·¨?y3°2×°"^M

       

    echo "--------------------------------"^M

       

    set /p ip="Please input contorl ip: " ^M

       

    adb kill-server^M

       

    adb start-server^M

       

    adb connect %ip%^M

       

    adb uninstall com.bobo.splayer

       

    adb install C:\Users\Administrator\Desktop\3dbb_5.7.2_dangbei.apk

       

    adb reboot

       

    修改完的:[root@model test]# vim lz3d.bat

       

    @ECHO OFF

       

    echo "á??Y′|àí2?·?3D22?T·¨?y3°2×°"

       

    echo "--------------------------------"

       

    set /p ip="Please input contorl ip: "

       

    adb kill-server

       

    adb start-server

       

    adb connect %ip%

       

    adb uninstall com.bobo.splayer

       

    adb install C:\Users\Administrator\Desktop\3dbb_5.7.2_dangbei.apk

       

    adb reboot

       

    1.3.15 vimdiff

    用命令vimdiff比較aa.txt和passwd的不同

    擴展:ctrl +w:卻換窗格

    1.3.16 rev

    rev:將輸入的文本反過來

    [root@model test]# cat passwd

    root:x:0:0:root:/root:/bin/bash

    bin:x:1:1:bin:/bin:/sbin/nologin

    daemon:x:2:2:daemon:/sbin:/sbin/nologin

    adm:x:3:4:adm:/var/adm:/sbin/nologin

    lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

    sync:x:5:0:sync:/sbin:/bin/sync

    shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

    halt:x:7:0:halt:/sbin:/sbin/halt

    mail:x:8:12:mail:/var/spool/mail:/sbin/nologin

    uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin

    operator:x:11:0:operator:/root:/sbin/nologin

    games:x:12:100:games:/usr/games:/sbin/nologin

    gopher:x:13:30:gopher:/var/gopher:/sbin/nologin

    ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin

    nobody:x:99:99:Nobody:/:/sbin/nologin

    vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin

    saslauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin

    postfix:x:89:89::/var/spool/postfix:/sbin/nologin

    sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin

       

       

    [root@model test]# rev passwd

    hsab/nib/:toor/:toor:0:0:x:toor

    nigolon/nibs/:nib/:nib:1:1:x:nib

    nigolon/nibs/:nibs/:nomead:2:2:x:nomead

    nigolon/nibs/:mda/rav/:mda:4:3:x:mda

    nigolon/nibs/:dpl/loops/rav/:pl:7:4:x:pl

    cnys/nib/:nibs/:cnys:0:5:x:cnys

    nwodtuhs/nibs/:nibs/:nwodtuhs:0:6:x:nwodtuhs

    tlah/nibs/:nibs/:tlah:0:7:x:tlah

    nigolon/nibs/:liam/loops/rav/:liam:21:8:x:liam

    nigolon/nibs/:pcuu/loops/rav/:pcuu:41:01:x:pcuu

    nigolon/nibs/:toor/:rotarepo:0:11:x:rotarepo

    nigolon/nibs/:semag/rsu/:semag:001:21:x:semag

    nigolon/nibs/:rehpog/rav/:rehpog:03:31:x:rehpog

    nigolon/nibs/:ptf/rav/:resU PTF:05:41:x:ptf

    nigolon/nibs/:/:ydoboN:99:99:x:ydobon

    nigolon/nibs/:ved/:renwo yromem elosnoc lautriv:96:96:x:ascv

    nigolon/nibs/:htualsas/ytpme/rav/:resu dhtualsaS:67:994:x:htualsas

    nigolon/nibs/:xiftsop/loops/rav/::98:98:x:xiftsop

    nigolon/nibs/:dhss/ytpme/rav/:HSS detarapes-egelivirP:47:47:x:dhss

    [root@model test]#

    1.3.17 join(后續整理)

    join:相當於將2個文件關聯的內容進行結合

    1.3.18 tr(單個字符之間的替換,不是全部替換)****

    tr 'a-z' 'A-Z':將字符小寫替換成大寫

    [root@model test]# vim 1.txt

    abcdEFG

    [root@model test]# cat 1.txt | tr 'a-z' 'A-Z'

    ABCDEFG

    tr -d '1-9':將查看你到的文件內容包含數字1-9的刪除

    [root@model test]# cat 2.txt

    AAAAAABBBBBBBBBBBBBB1111112222222233333333344444455

    [root@model test]# cat 2.txt | tr -d '1-9'

    AAAAAABBBBBBBBBBBBBB

    [root@model test]#

    tr ' ' '\n':將空格轉換成換行

    [root@model test]# cat 2.txt

    AAAAAABBBBBBBBBBBBBB 111111 2222222233333333344444455

    [root@model test]# cat 2.txt | tr ' ' '\n'

    AAAAAABBBBBBBBBBBBBB

    111111

    2222222233333333344444455

    [root@model test]#

    創建隨機密碼

    [root@oldboy6666 oldboy] # tr -cd 'a-z A-Z 0-9' < /dev/urandom | head -c 5

    mpcek

    [root@oldboy6666 oldboy] # tr -cd 'a-z A-Z 0-9' < /dev/urandom | head -c 5

    QAr7F

    [root@oldboy6666 oldboy] #

    將文件里面的oldboy全部替換成oldgirl

    [root@oldboy6666 oldboy] # tr 'oldboy' 'oldgirl' < oldboy.txt

    ildgir

    ildgirl

    ildgagr

    ilddig

    [root@oldboy6666 oldboy] #

    tr命令口訣

    前后一樣,直接替換

    前短后長,最后不換

    前長后短,多個共用

    前后重復,最新帶上

    1.4 信息顯示命令

    1.4.1 uname****

    uname:打印當前系統的信息(-r:查看內核版本;-a:查看所有的信息;-m:查看操作系統;-n:查看主機名)

    [root@model test]# uname -r

    2.6.32-696.el6.x86_64

    [root@model test]# uname -a

    Linux model 2.6.32-696.el6.x86_64 #1 SMP Tue Mar 21 19:29:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

    [root@model test]# uname -m

    x86_64

    [root@model test]# uname -n

    model

    1.4.2 hostname****

    hostname:查看主機名

    [root@model test]# hostname

    model

    hostname +主機名:修改主機名(臨時的)將主機名改為aa

    [root@model test]# uname -n

    model

    [root@model test]#hostname aa

    [root@model test]# logout

       

    Last login: Sat Apr 20 23:39:56 2019 from 192.168.43.200

    [root@aa ~]#

       

    永久修改主機名(centos 6)

    [root@aa ~]# cat /etc/sysconfig/network

    NETWORKING=yes

    HOSTNAME=model

       

    [root@aa ~]# vim /etc/sysconfig/network

    NETWORKING=yes

    HOSTNAME=aa

    [root@aa ~]#

    [root@aa ~]# . /etc/sysconfig/network

    [root@aa ~]#

    [root@aa ~]#

    永久修改主機名(centos 7)

    第一種:修改配置文件

    [root@oldboy6666 ~]# cat /etc/hostname

    oldboy6666

    [root@oldboy6666 ~]#

    [root@oldboy6666 ~]# cat /etc/hostname

    oldboy6666

    [root@oldboy6666 ~]#

       

    第二種

    [root@oldboy6666 oldboy] # hostnamectl set-hostname oldboy6666

    1.4.3 dmesg

    dmesg:用於檢查和控制內核的緩沖區;開機信息保存在/var/log/dmesg

    [root@model ~]# dmesg |head -10

    Initializing cgroup subsys cpuset

    Initializing cgroup subsys cpu

    Linux version 2.6.32-696.el6.x86_64 (mockbuild@c1bm.rdu2.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) ) #1 SMP Tue Mar 21 19:29:05 UTC 2017

    Command line: ro root=UUID=b262ea2c-9e6d-49cb-83ee-47f50e39f195 rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet

    KERNEL supported cpus:

    Intel GenuineIntel

    AMD AuthenticAMD

    Centaur CentaurHauls

    Disabled fast string operations

    BIOS-provided physical RAM map:

    [root@model ~]#

    1.4.4 uptime

  • (18:23:42:代表當前的系統時間
  • up 3:23:運行了3個多小時
  • 3users:當前連接用戶數為3
  • load:系統在過去的1分鍾、5分鍾和15分鍾內的平均負載

       

    [root@model ~]# uptime

    18:23:42 up 3:23, 3 users, load average: 0.08, 0.02, 0.011.4.5 stat

       

    1.4.6 du

    du:查看使用空間(查看20190420目錄下面的每個文件夾的大小)

    [root@model ~]# du 20190420/

    40 20190420/test

    44 20190420/

    [root@model ~]#

    du -sh 20190420:查看20190420的占用空間總大小

    [root@model ~]# du -sh 20190420/

    44K 20190420/

    [root@model ~]#

    1.4.7 df

    df -h:以人類可讀的方式

    [root@model ~]# df -h

    Filesystem Size Used Avail Use% Mounted on

    /dev/sda3 16G 792M 14G 6% /

    tmpfs 601M 0 601M 0% /dev/shm

    /dev/sda1 190M 27M 154M 15% /boot

    df -a:用於顯示磁盤的空間全部信息

    [root@model ~]# df -a

    Filesystem 1K-blocks Used Available Use% Mounted on

    /dev/sda3 16276904 810496 14632924 6% /

    proc 0 0 0 - /proc

    sysfs 0 0 0 - /sys

    devpts 0 0 0 - /dev/pts

    tmpfs 614692 0 614692 0% /dev/shm

    /dev/sda1 194241 27089 156912 15% /boot

    none 0 0 0 - /proc/sys/fs/binfmt_misc

    [root@model ~]#

    df -i:用於顯示inode號碼

    [root@oldboyedu oldboy02] # df -i

    Filesystem Inodes IUsed IFree IUse% Mounted on

    /dev/sda3 51539456 179242 51360214 1% /

    devtmpfs 120529 441 120088 1% /dev

    tmpfs 124468 1 124467 1% /dev/shm

    tmpfs 124468 1051 123417 1% /run

    tmpfs 124468 16 124452 1% /sys/fs/cgroup

    /dev/sdb1 768 11 757 2% /mnt

    /dev/sda1 75800 346 75454 1% /boot

    tmpfs 124468 18 124450 1% /run/user/988

    tmpfs 124468 1 124467 1% /run/user/0

    You have new mail in /var/spool/mail/root

    [root@oldboyedu oldboy02] #

       

    1.4.8 top

    top:動態檢測系統性能的工具

    [root@model ~]# top

       

    top - 18:37:04 up 3:36, 3 users, load average: 0.00, 0.00, 0.00

    Tasks: 95 total, 1 running, 94 sleeping, 0 stopped, 0 zombie

    Cpu(s): 0.0%us, 0.2%sy, 0.0%ni, 99.8%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

    Mem: 1229388k total, 261676k used, 967712k free, 10608k buffers

    Swap: 4095996k total, 0k used, 4095996k free, 119320k cached

       

    PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND

    12 root 20 0 0 0 0 S 0.3 0.0 0:03.65 events/1

    2439 root 20 0 99.7m 4156 3148 S 0.3 0.3 0:00.58 sshd

    1 root 20 0 19236 1500 1228 S 0.0 0.1 0:01.82 init

    2 root 20 0 0 0 0 S 0.0 0.0 0:00.02 kthreadd

    3 root RT 0 0 0 0 S 0.0 0.0 0:00.60 migration/0

    4 root 20 0 0 0 0 S 0.0 0.0 0:00.01 ksoftirqd/0

    5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0

    6 root RT 0 0 0 0 S 0.0 0.0 0:00.03 watchdog/0

    top字段的介紹

  • 18:37:04                                    當前系統時間
  • up 3:36                                    運行時間
  • 3 users                                    當前連接用戶數
  • Tasks 95 total:                            總進程數
  • 1 running                                    正在運行的數
  • 94 sleeping                                正在睡眠的進程數
  • 0 stopped                                    停止的進程數
  • 0 zombie                                    凍結的進程數
  • Cpu(s)                                    用戶空間占用CPU百分比
  • Us                                        進程空間占用CPU百分比
  • Mem:                                    總共,使用,剩余,緩存(內存)
  • Swap                                    總共,使用,剩余,緩存(交換分區)

       

       

    1.4.9 free****

    free -h:以人類可讀的形式展示

    [root@oldboy6666 oldboy] # free -h

    total used free shared buff/cache available

    Mem: 972M 487M 87M 14M 397M 272M

    Swap: 1.5G 116M 1.4G

    [root@oldboy6666 oldboy] #

    free字段的介紹

  • total                                            內存總數
  • used                                            已使用的內存數
  • free                                            剩余的內存數
  • shared                                        廢棄的內存數
  • buffer/cache                                    寫緩沖/讀緩存
  • available                                        空閑的內存數(最重要)

       

    1.4.10 date****

    date:查看當前的日期

    [root@model ~]# date

    2019 04 20 星期六 19:01:08 CST

    [root@model ~]#

    date字段介紹

  • 代表年
  • 代表年(帶世紀)
  • 代表分鍾
  • 代表月
  • 代表天
  • 代表秒
  • 代表一年的第幾周
  • 代表這周星期幾
  • 代表小時

       

    [root@model ~]# date -d "+1 day" 加一天

    2019 04 21 星期日 19:23:38 CST

    [root@model ~]# date -d "-1 day" 減一天

    2019 04 19 星期五 19:23:47 CST

    [root@model ~]# date -d "-1 month" 減一月

    2019 03 20 星期三 19:23:55 CST

    [root@model ~]# date -d "+1 month" 加一月

    2019 05 20 星期一 19:24:00 CST

    [root@model ~]# date -d "+1 year" 加一年

    2020 04 20 星期一 19:24:08 CST

    [root@model ~]# date -d "-1 year" 減一年

    2018 04 20 星期五 19:24:13 CST

    [root@model ~]#

    傳說中的1234567890秒

    [root@model ~]# date -d "1979-01-01 1234567890 second"

    2018 02 13 星期二 23:31:30 CST

    [root@model ~]#

    1.4.11 cal

    cal:打印日歷

    [root@model ~]# cal

    四月 2019

          

    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@model ~]#

    cal +年份:顯示這年的日歷

    [root@model ~]# cal 2018

    2018

       

    一月 二月 三月

                        

    1 2 3 4 5 6 1 2 3 1 2 3

    7 8 9 10 11 12 13 4 5 6 7 8 9 10 4 5 6 7 8 9 10

    14 15 16 17 18 19 20 11 12 13 14 15 16 17 11 12 13 14 15 16 17

    21 22 23 24 25 26 27 18 19 20 21 22 23 24 18 19 20 21 22 23 24

    28 29 30 31 25 26 27 28 25 26 27 28 29 30 31

       

    四月 五月 六月

                        

    1 2 3 4 5 6 7 1 2 3 4 5 1 2

    8 9 10 11 12 13 14 6 7 8 9 10 11 12 3 4 5 6 7 8 9

    15 16 17 18 19 20 21 13 14 15 16 17 18 19 10 11 12 13 14 15 16

    22 23 24 25 26 27 28 20 21 22 23 24 25 26 17 18 19 20 21 22 23

    29 30 27 28 29 30 31 24 25 26 27 28 29 30

       

    七月 八月 九月

                        

    1 2 3 4 5 6 7 1 2 3 4 1

    8 9 10 11 12 13 14 5 6 7 8 9 10 11 2 3 4 5 6 7 8

    15 16 17 18 19 20 21 12 13 14 15 16 17 18 9 10 11 12 13 14 15

    22 23 24 25 26 27 28 19 20 21 22 23 24 25 16 17 18 19 20 21 22

    29 30 31 26 27 28 29 30 31 23 24 25 26 27 28 29

    30

    十月 十一月 十二月

                        

    1 2 3 4 5 6 1 2 3 1

    7 8 9 10 11 12 13 4 5 6 7 8 9 10 2 3 4 5 6 7 8

    14 15 16 17 18 19 20 11 12 13 14 15 16 17 9 10 11 12 13 14 15

    21 22 23 24 25 26 27 18 19 20 21 22 23 24 16 17 18 19 20 21 22

    28 29 30 31 25 26 27 28 29 30 23 24 25 26 27 28 29

    30 31

       

    [root@model ~]#

    cal -j:顯示當前的日期在今年第幾天

    [root@model ~]# cal -j

    四月 2019

          

    91 92 93 94 95 96

    97 98 99 100 101 102 103

    104 105 106 107 108 109 110

    111 112 113 114 115 116 117

    118 119 120

       

    [root@model ~]#

    cal -3:顯示臨近4個月的日歷

    [root@model ~]# cal -3

    三月 2019 四月 2019 五月 2019

                        

    1 2 1 2 3 4 5 6 1 2 3 4

    3 4 5 6 7 8 9 7 8 9 10 11 12 13 5 6 7 8 9 10 11

    10 11 12 13 14 15 16 14 15 16 17 18 19 20 12 13 14 15 16 17 18

    17 18 19 20 21 22 23 21 22 23 24 25 26 27 19 20 21 22 23 24 25

    24 25 26 27 28 29 30 28 29 30 26 27 28 29 30 31

    31

    [root@model ~]#

    1.4.12 lscpu****

    查看cpu的命令

    [root@oldboy6666 ~]# lscpu

    Architecture: x86_64

    CPU op-mode(s): 32-bit, 64-bit

    Byte Order: Little Endian

    CPU(s): 1

    On-line CPU(s) list: 0

    Thread(s) per core: 1

    Core(s) per socket: 1

    Socket(s): 1

    NUMA node(s): 1

    Vendor ID: AuthenticAMD

    CPU family: 23

    Model: 24

    Model name: AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx

    Stepping: 1

    CPU MHz: 2096.060

    BogoMIPS: 4192.12

    Hypervisor vendor: VMware

    Virtualization type: full

    L1d cache: 32K

    L1i cache: 64K

    L2 cache: 512K

    L3 cache: 4096K

    NUMA node0 CPU(s): 0

    Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc art rep_good nopl tsc_reliable nonstop_tsc extd_apicid aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw retpoline_amd ssbd ibpb vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap xsaveopt xsavec xgetbv1 clzero irperf xsaveerptr arat

    [root@oldboy6666 ~]#

       

    1.5 搜索文件命令

    1.5.1 which****

    which:查找系統命令路徑

    [root@model ~]# which pwd

    /bin/pwd

    [root@model ~]# which cd

    /usr/bin/which: no cd in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)

    [root@model ~]# which mkdir

    /bin/mkdir

    [root@model ~]# which useradd

    /usr/sbin/useradd

    [root@model ~]# which userdel

    /usr/sbin/userdel

    [root@model ~]#

    1.5.2 whereis****

    whereis:用於命令文件路徑查找和man手冊文件和其他有關文件路徑的查找

    查找yum文件的路徑

    [root@model bin]# whereis yum

    yum: /usr/bin/yum /etc/yum.conf /etc/yum /usr/share/man/man8/yum.8.gz

    只查找二進制文件(-b)

    [root@model bin]# whereis -b yum

    yum: /usr/bin/yum /etc/yum.conf /etc/yum1.5.4

    查找yum的源文件(-s(source))

    [root@model bin]# whereis -s yum

    yum:

    [root@model bin]#

    查找yum的man文件(-m(man))

    [root@model bin]# whereis -m yum

    yum: /usr/share/man/man8/yum.8.gz

    [root@model bin]#

    1.5.3 find*****

    語法格式:find 路徑 執行的參數

    根據文件名稱進行查找(-name,-iname(不區分大小寫))

  • 查找/root/oldboy01目錄下1.txt的文件

    [root@oldboy6666 ~] # find /root/oldboy01 -name "1.txt"

    /root/oldboy01/1.txt

    /root/oldboy01/oldboy02/1.txt

    [root@oldboy6666 ~] #

  • 查找/root/oldboy01目錄下a(A).txt的文件

    [root@oldboy6666 oldboy02] # find /root/oldboy01 -iname "a.txt"

    /root/oldboy01/oldboy02/a.txt

    /root/oldboy01/oldboy02/A.txt

    /root/oldboy01/a.txt

    [root@oldboy6666 oldboy02] #

    根據文件的類型進行查找(-type)

  • 文件 f
  • 目錄 d
  • 鏈接 l
  • 塊設備 b
  • 字符流 c
  • 套接字 s
  • 查找/root/oldboy01目錄下文件的並且名字為a.txt的文件

    [root@oldboy6666 oldboy02] # find /root/oldboy01 -type f -name "a.txt"

    /root/oldboy01/oldboy02/a.txt

    /root/oldboy01/a.txt

    [root@oldboy6666 oldboy02] #

    根據文件的大小進行查找(-size)

    常見的文件大小單位

  • 字節單位
  • 塊設備(512字節,塊設備查找只能是512字節的倍數才能查找出來)
  • (1w=2字節)
  • KB
  • MB
  • GB
  • 查找/root/oldboy01目錄下文件大於1M的

    [root@oldboy6666 oldboy01] # find /root/oldboy01 -size +1M

    /root/oldboy01/2.txt

    /root/oldboy01/4.txt

    [root@oldboy6666 oldboy01] #

    注意

    +1M:查找大於1M的文件

    -1M:查找小於1M的文件

    1M:查找等於1M的文件

    根據文件的權限來進行查找(-perm)

  • 查找文件的權限為755的文件或者目錄

    [root@oldboy6666 oldboy01] # find /root/oldboy01 -perm 755

    /root/oldboy01

    /root/oldboy01/oldboy02

    /root/oldboy01/2.txt

    [root@oldboy6666 oldboy01] #

    根據文件的修改時間來進行查找(-mtime)

  • 查找文件的修改時間在7天之內的

    [root@oldboy6666 oldboy01] # find /root/oldboy01 -mtime -7

    /root/oldboy01

    /root/oldboy01/1.txt

    /root/oldboy01/oldboy02

    /root/oldboy01/oldboy02/2.txt

    /root/oldboy01/oldboy02/1.txt

    /root/oldboy01/oldboy02/a.txt

    /root/oldboy01/oldboy02/A.txt

    /root/oldboy01/a.txt

    /root/oldboy01/2.txt

    /root/oldboy01/3.txt

    /root/oldboy01/4.txt

    /root/oldboy01/5.txt

    [root@oldboy6666 oldboy01] #

    注意

  • +7 代表7天以前的信息文件
  • -7 代表7天之內的信息文件
  • 7 代表正好是第7天的信息文件

    根據文件的路徑進行查找(-path)

  • 查找/root/oldboy01/oldboy02目錄

    [root@oldboy6666 oldboy01] # find /root/oldboy01 -path /root/oldboy01/oldboy02

    /root/oldboy01/oldboy02

    根據文件的inode來進行查找(-inum)

  • 查找inode的數為202165184

    [root@oldboy6666 oldboy01] # ll -i

    total 13324

    202165181 -rwxrw-rw- 1 root root 0 Sep 16 19:14 1.txt

    202120440 -rwxr-xr-x 1 root root 2097152 Sep 16 19:28 2.txt

    202120442 -rwxrw-rw- 1 root root 1048576 Sep 16 19:28 3.txt

    202118699 -rwxrw-rw- 1 root root 10485760 Sep 16 19:28 4.txt

    202035674 -rwxrw-rw- 1 root root 10240 Sep 16 19:28 5.txt

    202035661 -rwxrw-rw- 1 root root 0 Sep 16 19:19 a.txt

    202165184 -rw-r--r-- 2 root root 0 Sep 16 19:14 hard.txt

    202165182 drwxr-xr-x 2 root root 58 Sep 16 19:19 oldboy02

    [root@oldboy6666 oldboy01] # find /root/oldboy01/ -inum "202165184"

    /root/oldboy01/oldboy02/1.txt

    /root/oldboy01/hard.txt

    [root@oldboy6666 oldboy01] #

    根據文件的最大深度進行查找(-maxdepth)

    查找/etc/目錄下面最大深度為1的目錄,並且統計有多少個目錄

    [root@oldboy6666 ~] # find /etc -maxdepth 1 -type d | wc -l

    80

    [root@oldboy6666 ~] #

    根據文件的最小深度進行查找(mindepth)

    查找/etc/目錄下面最小深度為2的目錄,並且統計有多少個目錄

    [root@oldboy6666 ~] # find /etc -mindepth 2 -type d | wc -l

    534

    [root@oldboy6666 ~] #

       

       

    1.5.3.1 查找文件的信息,並且進行刪除

    -delete參數的使用

    [root@oldboy6666 oldboy01] # find /root/oldboy01/ -inum "202165184"

    /root/oldboy01/oldboy02/1.txt

    /root/oldboy01/hard.txt

    [root@oldboy6666 oldboy01] # find /root/oldboy01/ -inum "202165184" -delete

    [root@oldboy6666 oldboy01] # find /root/oldboy01/ -inum "202165184"

    [root@oldboy6666 oldboy01] #

    -exec命令的使用

    [root@oldboy6666 oldboy02] # find /root/oldboy01/ -name "2.txt"

    /root/oldboy01/oldboy02/2.txt

    /root/oldboy01/2.txt

    [root@oldboy6666 oldboy02] # find /root/oldboy01/ -name "2.txt" -exec rm {} \;

    [root@oldboy6666 oldboy02] # find /root/oldboy01/ -name "2.txt"

       

    [root@oldboy6666 oldboy02] #

       

    1.5.4 locate****

    locate:使用locate命令的時候要記得更新數據庫(updatedb),比如查找/etc/*.sh的文件(-i:忽略大小寫)

    [root@model bin]# updatedb

    [root@model bin]# locate /etc/*.sh

    /etc/bash_completion.d/gdbus-bash-completion.sh

    /etc/dhcp/dhclient-exit-hooks.d/azure-cloud.sh

    /etc/profile.d/colorls.sh

    /etc/profile.d/glib2.sh

    /etc/profile.d/lang.sh

    /etc/profile.d/less.sh

    /etc/profile.d/vim.sh

    /etc/profile.d/which2.sh

    1.6 用戶管理命令

    1.6.1 useradd****

    /etc/passwd:用戶

    /etc/shadow:密碼

       

    創建一個用戶test1

    [root@model aa]# useradd test1

    useradd:警告:此主目錄已經存在。

    不從 skel 目錄里向其中復制任何文件。

    正在創建信箱文件文件已存在

    [root@model aa]# cat /etc/passwd

    .....................

    sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin

    test1:x:500:500::/home/test1:/bin/bash

    [root@model aa]# cat /etc/group

    ......................

    sshd:x:74:

    slocate:x:21:

    test1:x:500:

    [root@model aa]#

    創建一個用戶test2,並且test2可以登陸,不創建用戶家目錄test

    [root@model aa]# useradd test2 -s /bin/bash -d /home/test -M

    useradd:警告:此主目錄已經存在。

    不從 skel 目錄里向其中復制任何文件。

    正在創建信箱文件文件已存在

    [root@model aa]# cat /etc/passwd

    .....................

    sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin

    test1:x:500:500::/home/test1:/bin/bash

    test2:x:501:501::/home/test:/bin/bash

    [root@model aa]# cat /etc/group

    ......................

    sshd:x:74:

    slocate:x:21:

    test1:x:500:

    test2:x:501

       

    創建一個用戶test3,並且test3可以登陸,創建用戶家目錄

    [root@model aa]# useradd test3 -s /bin/bash -d /home/test -m

    useradd:警告:此主目錄已經存在。

    不從 skel 目錄里向其中復制任何文件。

    正在創建信箱文件文件已存在

    [root@model aa]# cd /home/test

    [root@model aa]# cat /etc/passwd

    .....................

    sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin

    test1:x:500:500::/home/test1:/bin/bash

    test2:x:501:501::/home/test:/bin/bash

    test3:x:502:502::/home/test:/bin/bash

    [root@model aa]# cat /etc/group

    ......................

    sshd:x:74:

    slocate:x:21:

    test1:x:500:

    test2:x:501

    test3:x:502:

       

    創建一個用戶test4,並且test4不可以登錄,並且指定用戶初始化組為aa

    [root@model test]# useradd test4 -s /sbin/nologin -g aa

    useradd:警告:此主目錄已經存在。

    不從 skel 目錄里向其中復制任何文件。

    正在創建信箱文件文件已存在

    [root@model aa]# cat /etc/passwd

    .....................

    sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin

    test1:x:500:500::/home/test1:/bin/bash

    test2:x:501:501::/home/test:/bin/bash

    test3:x:502:502::/home/test:/bin/bash

    test4:x:503:503::/home/test4:/sbin/nologin

    [root@model aa]# cat /etc/group

    ......................

    sshd:x:74:

    slocate:x:21:

    test1:x:500:

    test2:x:501

    test3:x:502:

    aa:x:503:

       

    創建一個用戶test5,並且test5的用戶組初始化

    [root@model test]# useradd test5 -N 創建一個與用戶不同的用戶組

    正在創建信箱文件文件已存在

    [root@model aa]# cat /etc/passwd

    .....................

    sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin

    test1:x:500:500::/home/test1:/bin/bash

    test2:x:501:501::/home/test:/bin/bash

    test3:x:502:502::/home/test:/bin/bash

    test4:x:503:503::/home/test4:/sbin/nologin

    test5:x:504:100::/home/test5:/bin/bash

    [root@model aa]# cat /etc/group

    ......................

    sshd:x:74:

    slocate:x:21:

    test1:x:500:

    test2:x:501

    test3:x:502:

    aa:x:503:

    1.6.2 usermod*****

    usermod -d:修改用戶登錄時的家目錄(修改登錄用戶test1的家目錄為/home/test)

    [root@model test]# cat /etc/passwd

    root:x:0:0:root:/root:/bin/bash

    ...............................

    test1:x:500:500::/home/test1:/bin/bash

    [root@model test]# usermod -d /home/test test1

    [root@model test]# cat /etc/passwd

    root:x:0:0:root:/root:/bin/bash

    ...............................

    test1:x:500:500::/home/test:/bin/bash

       

    1.6.3 userdel******

    userdel:刪除用戶,但是不刪除用戶家目錄

    [root@model test4]# userdel test4

    test1:x:500:500::/home/test:/bin/bash

    test2:x:501:501::/home/test:/bin/bash

    test3:x:502:502::/home/test:/bin/bash

    test5:x:504:100::/home/test5:/bin/bash

    [root@model test4]# cd /home/test4

    [root@model test4]#

    userdel -rf:強制刪除用戶,並且用戶家目錄也會一並刪除(-r:刪除家目錄,-f:強制刪除)

    [root@model test5]# cat /etc/passwd

    root:x:0:0:root:/root:/bin/bash

    .............................

    test1:x:500:500::/home/test:/bin/bash

    test2:x:501:501::/home/test:/bin/bash

    test3:x:502:502::/home/test3:/bin/bash

    [root@model test5]# cd /home/test3

    [root@model test3]# userdel -rf test3

    [root@model test3]# cd /home/test3

    -bash: cd: /home/test3: 沒有那個文件或目錄

    [root@model test3]# cat /etc/passwd

    root:x:0:0:root:/root:/bin/bash

    .......................

    test1:x:500:500::/home/test:/bin/bash

    test2:x:501:501::/home/test:/bin/bash

    [root@model test3]#

    1.6.4 groupadd*****

    /etc/group 組賬戶信息。

    /etc/gshadow 安全組賬戶信息。

    /etc/login.defs Shadow密碼套件配置

    創建一個用戶組bb,並且指定ID為123

    [root@model ~]# groupadd -g 123 bb

    [root@model ~]# cat /etc/group

    root:x:0:

    .......................

    test1:x:500:

    test2:x:501:

    aa:x:503:

    bb:x:123:

    1.6.5 passwd****

    [root@model ~]# passwd

    更改用戶 root 的密碼 

    新的 密碼:

    無效的密碼: WAY 過短

    無效的密碼: 過於簡單

    重新輸入新的 密碼:

    抱歉,密碼不匹配。

    新的 密碼:

    無效的密碼: 過於簡單化/系統化

    重新輸入新的 密碼:

    passwd 所有的身份驗證令牌已經成功更新。

    [root@model ~]#

       

    passwd修改密碼免交互方式

    [root@oldboy6666 ~]# echo "123456" | passwd --stdin oldboy101

    Changing password for user oldboy101.

    1.6.6 chage

    chage:用來修改賬號和密碼的有效期限

    /etc/login.dfs里面配置用戶的密碼、UID、GID的使用期限

    [root@model data]# cat /etc/login.defs

    #

    # Please note that the parameters in this configuration file control the

    # behavior of the tools from the shadow-utils component. None of these

    # tools uses the PAM mechanism, and the utilities that use PAM (such as the

    # passwd command) should therefore be configured elsewhere. Refer to

    # /etc/pam.d/system-auth for more information.

    #

       

    # *REQUIRED*

    # Directory where mailboxes reside, _or_ name of file, relative to the

    # home directory. If you _do_ define both, MAIL_DIR takes precedence.

    # QMAIL_DIR is for Qmail

    #

    #QMAIL_DIR Maildir

    MAIL_DIR /var/spool/mail

    #MAIL_FILE .mail

       

    # Password aging controls:

    #

    # PASS_MAX_DAYS Maximum number of days a password may be used.

    # PASS_MIN_DAYS Minimum number of days allowed between password changes.

    # PASS_MIN_LEN Minimum acceptable password length.

    # PASS_WARN_AGE Number of days warning given before a password expires.

    #

    PASS_MAX_DAYS 99999

    PASS_MIN_DAYS 0

    PASS_MIN_LEN 5

    PASS_WARN_AGE 7

       

    #

    # Min/max values for automatic uid selection in useradd

    #

    UID_MIN 500

    UID_MAX 60000

       

    #

    # Min/max values for automatic gid selection in groupadd

    #

    GID_MIN 500

    GID_MAX 60000

       

    #

    # If defined, this command is run when removing a user.

    # It should remove any at/cron/print jobs etc. owned by

    # the user to be removed (passed as the first argument).

    #

    #USERDEL_CMD /usr/sbin/userdel_local

       

    #

    # If useradd should create home directories for users by default

    # On RH systems, we do. This option is overridden with the -m flag on

    # useradd command line.

    #

    CREATE_HOME yes

       

    # The permission mask is initialized to this value. If not specified,

    # the permission mask will be initialized to 022.

    UMASK 077

       

    # This enables userdel to remove user groups if no members exist.

    #

    USERGROUPS_ENAB yes

       

    # Use SHA512 to encrypt password.

    ENCRYPT_METHOD SHA512

    /etc/default/useradd:添加用戶的一些默認信息

    [root@model data]# cat /etc/default/useradd

    # useradd defaults file

    GROUP=123

    HOME=/data

    INACTIVE=-1

    EXPIRE=

    SHELL=/bin/bash

    SKEL=/etc/skel

    CREATE_MAIL_SPOOL=yes

    chage命令的一些參數

    -m

    最小天數

    -M

    最大天數

    -W

    提醒天數

    -I

    密碼失效時期

    chage -l +用戶:查看用戶的賬號密碼策略信息

    [root@model data]# chage -l root

    最近一次密碼修改時間 4 21, 2019

    密碼過期時間 :從不

    密碼失效時間 :從不

    帳戶過期時間 :從不

    兩次改變密碼之間相距的最小天數 0

    兩次改變密碼之間相距的最大天數 99999

    在密碼過期之前警告的天數 7

    2次密碼更改時間的最大天數

    [root@model data]# chage -M 60 root

    [root@model data]# chage -l root

    最近一次密碼修改時間 4 21, 2019

    密碼過期時間 6 20, 2019

    密碼失效時間 :從不

    帳戶過期時間 :從不

    兩次改變密碼之間相距的最小天數 0

    兩次改變密碼之間相距的最大天數 60

    在密碼過期之前警告的天數 7

    更改密碼失效時間

    [root@model data]# chage -I 5 root

    [root@model data]# chage -l root

    最近一次密碼修改時間 4 21, 2019

    密碼過期時間 6 20, 2019

    密碼失效時間 6 25, 2019

    帳戶過期時間 :從不

    兩次改變密碼之間相距的最小天數 0

    兩次改變密碼之間相距的最大天數 60

    在密碼過期之前警告的天數 7

    [root@model data]#

    1.6.7 id****

    [root@model data]# id

    uid=0(root) gid=0(root) =0(root) 環境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

    [root@model data]# id aa

    id: aa:無此用戶

    [root@model data]# id test1

    uid=500(test1) gid=500(test1) =500(test1)

    [root@model data]#

    1.6.8 su****

    su -:用於切換當前用戶的身份

    [root@model data]# su - test10

    [test10@model data]$ ls

    test10 test11 test9

    [test10@model data]$

    1.6.9 visudo*******

    vim /etc/sudoers(不檢查語法)(visudo檢查語法)

    ## Sudoers allows particular users to run various commands as

    ## the root user, without needing the root password.

    ## 該文件允許特定用戶像root用戶一樣使用各種各樣的命令,而不需要root用戶的密碼

    ##

    ## Examples are provided at the bottom of the file for collections

    ## of related commands, which can then be delegated out to particular

    ## users or groups.

    ## 在文件的底部提供了很多相關命令的示例以供選擇,這些示例都可以被特定用戶或

    ## 用戶組所使用

    ##

    ## This file must be edited with the 'visudo' command.

    ## 該文件必須使用"visudo"命令編輯

       

    ## Host Aliases

    ## Groups of machines. You may prefer to use hostnames (perhaps using

    ## wildcards for entire domains) or IP addresses instead.

    ## 對於一組服務器,你可能會更喜歡使用主機名(可能是全域名的通配符)

    ## 、或IP地址,這時可以配置主機別名

    # Host_Alias FILESERVERS = fs1, fs2

    # Host_Alias MAILSERVERS = smtp, smtp2

       

    ## User Aliases

    ## These aren't often necessary, as you can use regular groups

    ## (ie, from files, LDAP, NIS, etc) in this file - just use %groupname

    ## rather than USERALIAS

    ## 這並不很常用,因為你可以通過使用組來代替一組用戶的別名

    # User_Alias ADMINS = jsmith, mikem

       

    ## Command Aliases

    ## These are groups of related commands...

    ## 指定一系列相互關聯的命令(當然可以是一個)的別名,通過賦予該別名sudo權限,

    ## 可以通過sudo調用所有別名包含的命令,下面是一些示例

       

    ## Networking 網絡操作相關命令別名

    # Cmnd_Alias NETWORKING = /sbin/route, /sbin/ifconfig, /bin/ping, /sbin/dhclient

    , /usr/bin/net, /sbin/iptables, /usr/bin/rfcomm, /usr/bin/wvdial, /sbin/iwconfig

    , /sbin/mii-tool

       

    ## Installation and management of software 軟件安裝管理相關命令別名

    # Cmnd_Alias SOFTWARE = /bin/rpm, /usr/bin/up2date, /usr/bin/yum

       

    ## Services 服務相關命令別名

    # Cmnd_Alias SERVICES = /sbin/service, /sbin/chkconfig

       

    ## Updating the locate database 本地數據庫升級命令別名

    # Cmnd_Alias LOCATE = /usr/bin/updatedb

       

    ## Storage 磁盤操作相關命令別名

    # Cmnd_Alias STORAGE = /sbin/fdisk, /sbin/sfdisk, /sbin/parted, /sbin/partprobe

    , /bin/mount, /bin/umount

       

    ## Delegating permissions 代理權限相關命令別名

    # Cmnd_Alias DELEGATING = /usr/sbin/visudo, /bin/chown, /bin/chmod, /bin/chgrp

       

    ## Processes 進程相關命令別名

    # Cmnd_Alias PROCESSES = /bin/nice, /bin/kill, /usr/bin/kill, /usr/bin/killall

       

    ## Drivers 驅動命令別名

    # Cmnd_Alias DRIVERS = /sbin/modprobe

       

    # Defaults specification

       

    #

    # Disable "ssh hostname sudo <cmd>", because it will show the password in clear.

    # You have to run "ssh -t hostname sudo <cmd>".

    一些環境變量的相關配置,具體情況可見man soduers

    Defaults requiretty

       

    Defaults env_reset

    Defaults env_keep = "COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS"

    Defaults env_keep += "MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE"

    Defaults env_keep += "LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES"

    Defaults env_keep += "LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE"

    Defaults env_keep += "LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY"

       

    Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin

       

    ## Next comes the main part: which users can run what software on

    ## which machines (the sudoers file can be shared between multiple

    ## systems).

    ## 下面是規則配置:什么用戶在哪台服務器上可以執行哪些命令(sudoers文件可以在多個系統上共享)

    ## Syntax(語法):

    ##

    ##     user    MACHINE=COMMANDS 用戶 登錄的主機=(可以變換的身份) 可以執行的命令

    ##

    ## The COMMANDS section may have other options added to it.

    ## 命令部分可以附帶一些其它的選項

    ##

    ## Allow root to run any commands anywhere

    ## 允許root用戶執行任意路徑下的任意命令

    root    ALL=(ALL)     ALL

       

    ## Allows members of the 'sys' group to run networking, software,

    ## service management apps and more.

    ## 允許sys中戶組中的用戶使用NETWORKING等所有別名中配置的命令

    # %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE

    , DRIVERS

       

    ## Allows people in group wheel to run all commands

    ## 允許wheel用戶組中的用戶執行所有命令

    %wheel    ALL=(ALL)    ALL

       

    ## Same thing without a password

    ## 允許wheel用戶組中的用戶在不輸入該用戶的密碼的情況下使用所有命令

    # %wheel    ALL=(ALL)    NOPASSWD: ALL

       

    ## Allows members of the users group to mount and unmount the

    ## cdrom as root

    ## 允許users用戶組中的用戶像root用戶一樣使用mountunmountchrom命令

    # %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom

       

    ## Allows members of the users group to shutdown this system

    ## 允許users用戶組中的用戶關閉localhost這台服務器

    # %users localhost=/sbin/shutdown -h now

       

    ## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)

    ## 讀取放置在/etc/sudoers.d/文件夾中的文件(此處的#不意味着這是一個聲明)

    #includedir /etc/sudoers.d

    1.6.10 sudo*******

    [root@model sudoers.d]# su admin

    [admin@model sudoers.d]$ sudo ls

       

    We trust you have received the usual lecture from the local System

    Administrator. It usually boils down to these three things:

       

    #1) Respect the privacy of others.

    #2) Think before you type.

    #3) With great power comes great responsibility.

       

    [sudo] password for admin:

    [admin@model sudoers.d]$ passwd

    1.7 基礎網絡操作命令

    1.7.1 telnet****

    查看rpcbind的鏈路是否通

    telnet 192.168.1.199 111

    Trying 192.168.1.199...

    Connected to 192.168.1.199 (192.168.1.199).

    Escape character is '^]'.

       

    localhost (Linux release 2.6.18-274.18.1.el5 #1 SMP Thu Feb 9 12:45:44 EST 2012) (1)

    login: root

    Password:

    Login incorrect

       

    1.7.2 ssh(no)

    1.7.3 scp(no)

    1.7.4 wget****

    wget:下載lrzsz安裝包

    [root@model sudoers.d]# wget https://ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz

    --2019-04-21 12:27:17-- https://ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz

    正在解析主機 ohse.de... 94.130.158.36

    正在連接 ohse.de|94.130.158.36|:443... 已連接。

    已發出 HTTP 請求,正在等待回應... 200 OK

    長度:280938 (274K) [application/x-gzip]

    正在保存至"lrzsz-0.12.20.tar.gz"

       

    52% [=================================================================> ] 147,456 42.6K/s eta(英國中部時58% [=========================================================================> ] 163,840 37.8K/s eta(英國中部時69% [=======================================================================================> ] 196,608 42.0K/s eta(英國中部時75% [===============================================================================================> ] 212,992 41.9K/s eta(英國中部時81% [======================================================================================================> ] 229,376 38.6K/s eta(英國中部時93% [=========================================================================================================== ==========> ] 262,144 38.3K/s eta(英國中部時99% [============================================================================================================================> ] 278,528 36.5K/s eta(英國中部時100%[==============================================================================================================================>] 280,938 36.8K/s in 7.5s

       

    2019-04-21 12:27:26 (36.8 KB/s) - 已保存 "lrzsz-0.12.20.tar.gz" [280938/280938])

       

    [root@model sudoers.d]#

    wget -b:后台下載,默認會輸出日志(使用 tail -f wget-log)

    [root@model sudoers.d]# wget -b https://ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz

    繼續在后台運行,pid  1949

    將把輸出寫入至 "wget-log"

    [root@model sudoers.d]# ll

    總用量 280

    -rw-r--r--. 1 root root 280938 12 31 1998 lrzsz-0.12.20.tar.gz

    -rw-r--r--. 1 root root 865 4 21 12:32 wget-log

    [root@model sudoers.d]#

    wget -spider:測試下載的鏈接是否有效

    [root@model sudoers.d]# wget --spider https://ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz

    開啟 Spider 模式。檢查是否存在遠程文件。

    --2019-04-21 12:36:28-- https://ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz

    正在解析主機 ohse.de... 94.130.158.36

    正在連接 ohse.de|94.130.158.36|:443... 已連接。

    已發出 HTTP 請求,正在等待回應... 200 OK

    長度:280938 (274K) [application/x-gzip]

    存在遠程文件。

       

    [root@model sudoers.d]#

    wget -i:下載多個鏈接

    [root@model sudoers.d]# cat a.txt

    https://ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz

    ftp://ftp.vim.org/ftp/pub/vim/unix/vim-7.4.tar.bz2

    [root@model sudoers.d]#

       

    [root@model sudoers.d]# wget -i a.txt

    --2019-04-21 12:41:25-- https://ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz

    正在解析主機 ohse.de... 94.130.158.36

    正在連接 ohse.de|94.130.158.36|:443... 已連接。

    已發出 HTTP 請求,正在等待回應... 200 OK

    長度:280938 (274K) [application/x-gzip]

    正在保存至: "lrzsz-0.12.20.tar.gz.1"

       

    33% [=========================================> ] 95,011 25.3K/s eta(英國中部時40% [==================================================> ] 114,688 27.1K/s eta(英國中部時46% [============================================================================================================================> ] 278,528 22.5K/s eta(英國中部時100%[==============================================================================================================================>] 280,938 19.9K/s eta(英國中部時100%[==============================================================================================================================>] 280,938 19.9K/s in 14s

       

    2019-04-21 12:41:42 (19.9 KB/s) - 已保存 "lrzsz-0.12.20.tar.gz.1" [280938/280938])

       

    --2019-04-21 12:41:42-- ftp://ftp.vim.org/ftp/pub/vim/unix/vim-7.4.tar.bz2

    => "vim-7.4.tar.bz2"

    正在解析主機 ftp.vim.org... 2001:67c:6ec:221:145:220:21:40, 145.220.21.40

    正在連接 ftp.vim.org|2001:67c:6ec:221:145:220:21:40|:21... 已連接。

    正在以 anonymous 登錄 ... 登錄成功!

    ==> SYST ... 完成。 ==> PWD ... 完成。

    ==> TYPE I ... 完成。 ==> CWD (1) /ftp/pub/vim/unix ... 完成。

    ==> SIZE vim-7.4.tar.bz2 ... 9843297

    ==> EPSV ... 完成。 ==> RETR vim-7.4.tar.bz2 ... 完成。

    長度:9843297 (9.4M) (非正式數據)

       

    1% [> ] 104,100 31.8K/s eta(英國中部時 1% ] 231,796 29.3K/s eta(英國中部時間) 5m 20s^C

    [root@model sudoers.d]#

    wget -c:斷點續傳

    [root@model sudoers.d]# wget -c ftp://ftp.vim.org/ftp/pub/vim/unix/vim-7.4.tar.bz2

    --2019-04-21 12:53:00-- ftp://ftp.vim.org/ftp/pub/vim/unix/vim-7.4.tar.bz2

    => "vim-7.4.tar.bz2"

    正在解析主機 ftp.vim.org... 2001:67c:6ec:221:145:220:21:40, 145.220.21.40

    正在連接 ftp.vim.org|2001:67c:6ec:221:145:220:21:40|:21... 已連接。

    正在以 anonymous 登錄 ... 登錄成功!

    ==> SYST ... 完成。 ==> PWD ... 完成。

    ==> TYPE I ... 完成。 ==> CWD (1) /ftp/pub/vim/unix ... 完成。

    ==> SIZE vim-7.4.tar.bz2 ... 9843297

    ==> EPSV ... 完成。 ==> REST 235960 ... 完成。

    ==> RETR vim-7.4.tar.bz2 ... 完成。

    長度:9843297 (9.4M)9607337 (9.2M) 字節剩余 (非正式數據)

       

    3% [+++> ] 333,120 24.1K/s eta(英國中部時 3% [+++> ] 349,504 26.2K/s eta(英國中部時 3% [+++> ] 366,432 27.1K/s eta(英國中部時 3% [+++> ] 367,820 25.5K/s eta(英國中部時 3% [+++> ] 374,760 24.6K/s eta(英國中部時間) 6m 2s^C

    [root@model sudoers.d]#

    wget --limit-rate=300k:限速300K下載

    [root@model sudoers.d]# wget --limit-rate=10k https://ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz

    --2019-04-21 12:57:51-- https://ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz

    正在解析主機 ohse.de... 94.130.158.36

    正在連接 ohse.de|94.130.158.36|:443... 已連接。

    已發出 HTTP 請求,正在等待回應... 200 OK

    長度:280938 (274K) [application/x-gzip]

    正在保存至: "lrzsz-0.12.20.tar.gz.2"

       

    11% [=============> ] 32,768 10.0K/s eta(英國中部時15% [==================> ] 43,008 10.0K/s eta(英國中部時19% [=======================> ] 53,619 [==========================================================> ] 131,072 10.0K/s eta(英國中部時50% [==============================================================> ] 141,312 10.0K/s eta(英國中部時52% [=================================================================> ] 147,456 10.0K/s eta(英國中部時間) 14s^C

    [root@model sudoers.d]#

    1.7.5 ping****

    ping 192.168.43.200地址

    -c num

    要求返回的次數

    -I 網卡

    從指定網卡ping

    -s 包大小

    設定每一個包的大小

    -t

    設定每一個ttl的大小

       

    [root@model sudoers.d]# ping 192.168.43.200

    PING 192.168.43.200 (192.168.43.200) 56(84) bytes of data.

    64 bytes from 192.168.43.200: icmp_seq=1 ttl=128 time=0.511 ms

    64 bytes from 192.168.43.200: icmp_seq=2 ttl=128 time=0.613 ms

    64 bytes from 192.168.43.200: icmp_seq=3 ttl=128 time=0.605 ms

    ^C

    --- 192.168.43.200 ping statistics ---

    3 packets transmitted, 3 received, 0% packet loss, time 2459ms

    rtt min/avg/max/mdev = 0.511/0.576/0.613/0.050 ms

    [root@model sudoers.d]#

    1.7.6 route(centos 6)****

    route:查看路由

    [root@model sudoers.d]# route

    Kernel IP routing table

    Destination Gateway Genmask Flags Metric Ref Use Iface

    192.168.1.0 * 255.255.255.0 U 0 0 0 eth1

    192.168.43.0 * 255.255.255.0 U 0 0 0 eth0

    link-local * 255.255.0.0 U 1002 0 0 eth0

    link-local * 255.255.0.0 U 1003 0 0 eth1

    default bogon 0.0.0.0 UG 0 0 0 eth0

    route -n:直接顯示數字形式的IP地址

    [root@model sudoers.d]# route -n

    Kernel IP routing table

    Destination Gateway Genmask Flags Metric Ref Use Iface

    192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1

    192.168.43.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

    169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0

    169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth1

    0.0.0.0 192.168.43.1 0.0.0.0 UG 0 0 0 eth0

    U

    路由為啟動

    UG

    表示此網關為一路由器

    H

    表示為主機路由

      

      

      

      

       

    添加一條路由(192.168.43.1)

    [root@model sudoers.d]# route add host 192.168.43.210 gw 192.168.43.1 dev eth0 主機路由(H)

    [root@model sudoers.d]# route add -net 192.168.43.210 netmask 255.255.255.255 gw 192.168.43.1 dev eth0 網絡路由(N)

    [root@model sudoers.d]# route add default gw 192.168.43.1 添加一條默認路由

    屏蔽一條已經添加的路由(192.168.1.1)

    [root@model sudoers.d]# route add host 192.168.43.210 gw 192.168.43.1 dev eth0 reject 主機路由(H)

    [root@model sudoers.d]# route add -net 192.168.43.210 netmask 255.255.255.255 gw 192.168.43.1 dev eth0 reject 網絡路由(N)

    [root@model sudoers.d]# route add default gw 192.168.43.1 reject 添加一條默認路由

    刪除路由

    [root@model sudoers.d]# route del host 192.168.43.210 gw 192.168.43.1 dev eth0 主機路由(H)

    [root@model sudoers.d]# route del -net 192.168.43.210 netmask 255.255.255.255 gw 192.168.43.1 dev eth0 網絡路由(N)

    [root@model sudoers.d]# route del default gw 192.168.43.1 添加一條默認路由

    1.7.7 ifconfig(centos6)****

    ifconfig:查看開機自啟的網卡

    [root@model sudoers.d]# ifconfig

    eth0 Link encap:Ethernet HWaddr 00:0C:29:89:18:0B

    inet addr:192.168.43.210 Bcast:192.168.43.255 Mask:255.255.255.0

    inet6 addr: 2408:805f:e222:eefa:20c:29ff:fe89:180b/64 Scope:Global

    inet6 addr: fe80::20c:29ff:fe89:180b/64 Scope:Link

    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

    RX packets:107820 errors:0 dropped:0 overruns:0 frame:0

    TX packets:116404 errors:0 dropped:0 overruns:0 carrier:0

    collisions:0 txqueuelen:1000

    RX bytes:13020163 (12.4 MiB) TX bytes:12201465 (11.6 MiB)

       

    lo Link encap:Local Loopback

    inet addr:127.0.0.1 Mask:255.0.0.0

    inet6 addr: ::1/128 Scope:Host

    UP LOOPBACK RUNNING MTU:65536 Metric:1

    RX packets:254 errors:0 dropped:0 overruns:0 frame:0

    TX packets:254 errors:0 dropped:0 overruns:0 carrier:0

    collisions:0 txqueuelen:0

    RX bytes:982788 (959.7 KiB) TX bytes:982788 (959.7 KiB)

       

    [root@model sudoers.d]#

    ifconfig -a:查看所有的網卡

    [root@model sudoers.d]# ifconfig -a

    eth0 Link encap:Ethernet HWaddr 00:0C:29:89:18:0B

    inet addr:192.168.43.210 Bcast:192.168.43.255 Mask:255.255.255.0

    inet6 addr: 2408:805f:e222:eefa:20c:29ff:fe89:180b/64 Scope:Global

    inet6 addr: fe80::20c:29ff:fe89:180b/64 Scope:Link

    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

    RX packets:107833 errors:0 dropped:0 overruns:0 frame:0

    TX packets:116413 errors:0 dropped:0 overruns:0 carrier:0

    collisions:0 txqueuelen:1000

    RX bytes:13021219 (12.4 MiB) TX bytes:12203289 (11.6 MiB)

       

    eth1 Link encap:Ethernet HWaddr 00:0C:29:89:18:15

    BROADCAST MULTICAST MTU:1500 Metric:1

    RX packets:367 errors:0 dropped:0 overruns:0 frame:0

    TX packets:11 errors:0 dropped:0 overruns:0 carrier:0

    collisions:0 txqueuelen:1000

    RX bytes:44019 (42.9 KiB) TX bytes:766 (766.0 b)

       

    lo Link encap:Local Loopback

    inet addr:127.0.0.1 Mask:255.0.0.0

    inet6 addr: ::1/128 Scope:Host

    UP LOOPBACK RUNNING MTU:65536 Metric:1

    RX packets:254 errors:0 dropped:0 overruns:0 frame:0

    TX packets:254 errors:0 dropped:0 overruns:0 carrier:0

    collisions:0 txqueuelen:0

    RX bytes:982788 (959.7 KiB) TX bytes:982788 (959.7 KiB)

       

    [root@model sudoers.d]#

    查找eth0的網卡信息

    [root@model sudoers.d]# ifconfig eth0

    eth0 Link encap:Ethernet HWaddr 00:0C:29:89:18:0B

    inet addr:192.168.43.210 Bcast:192.168.43.255 Mask:255.255.255.0

    inet6 addr: 2408:805f:e222:eefa:20c:29ff:fe89:180b/64 Scope:Global

    inet6 addr: fe80::20c:29ff:fe89:180b/64 Scope:Link

    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

    RX packets:107849 errors:0 dropped:0 overruns:0 frame:0

    TX packets:116422 errors:0 dropped:0 overruns:0 carrier:0

    collisions:0 txqueuelen:1000

    RX bytes:13022547 (12.4 MiB) TX bytes:12205603 (11.6 MiB)

       

    [root@model sudoers.d]#

    1.7.8 ifup(centos6,7)****

    ifup:只適用於centos 6版本:啟動單個網卡

    [root@model sudoers.d]# ifup eth1

    Determining if ip address 192.168.1.197 is already in use for device eth1...

    [root@model sudoers.d]#

    1.7.9 ifdown(centos6,7)****

    ifdown:只適用於centos 6版本:啟關閉單個網卡

    [root@model sudoers.d]# ifdown eth1

    [root@model sudoers.d]#

    1.7.10 netstat(centos6)****

    netstat -anptu

  • a                                All,顯示全部的信息
  • n                                直接使用IP地址,不使用域名服務器
  • p                                程序名稱
  • t                                顯示tcp端口的傳輸信息
  • u                                顯示udp端口的傳輸信息
  • l                                Licence:顯示監聽端口
  • c                                持續輸出netstat信息(1秒)

    [root@model sudoers.d]# netstat -anptulc

    Active Internet connections (servers and established)

    Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

    tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1280/sshd

    tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1360/master

    tcp 0 0 192.168.43.210:22 192.168.43.200:52229 ESTABLISHED 1649/sshd

    tcp 0 0 :::22 :::* LISTEN 1280/sshd

    tcp 0 0 ::1:25 :::* LISTEN 1360/master

    Active Internet connections (servers and established)

    Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

    tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1280/sshd

    tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1360/master

    tcp 0 0 192.168.43.210:22 192.168.43.200:52229 ESTABLISHED 1649/sshd

    tcp 0 0 :::22 :::* LISTEN 1280/sshd

    tcp 0 0 ::1:25 :::* LISTEN 1360/master

    Active Internet connections (servers and established)

    Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

    tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1280/sshd

    tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1360/master

    tcp 0 0 192.168.43.210:22 192.168.43.200:52229 ESTABLISHED 1649/sshd

    tcp 0 0 :::22 :::* LISTEN 1280/sshd

    tcp 0 0 ::1:25 :::* LISTEN 1360/master

    ^C

    [root@model sudoers.d]#

    netstat -rn(相當於route -n):查看路由

    [root@model sudoers.d]# netstat -rn

    Kernel IP routing table

    Destination Gateway Genmask Flags MSS Window irtt Iface

    192.168.43.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

    169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0

    0.0.0.0 192.168.43.1 0.0.0.0 UG 0 0 0 eth0

    netstat -ie(相當於ifconfig):查看網卡信息

    [root@model sudoers.d]# netstat -ie

    Kernel Interface table

    eth0 Link encap:Ethernet HWaddr 00:0C:29:89:18:0B

    inet addr:192.168.43.210 Bcast:192.168.43.255 Mask:255.255.255.0

    inet6 addr: 2408:805f:e222:eefa:20c:29ff:fe89:180b/64 Scope:Global

    inet6 addr: fe80::20c:29ff:fe89:180b/64 Scope:Link

    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

    RX packets:108250 errors:0 dropped:0 overruns:0 frame:0

    TX packets:116700 errors:0 dropped:0 overruns:0 carrier:0

    collisions:0 txqueuelen:1000

    RX bytes:13057114 (12.4 MiB) TX bytes:12258698 (11.6 MiB)

       

    lo Link encap:Local Loopback

    inet addr:127.0.0.1 Mask:255.0.0.0

    inet6 addr: ::1/128 Scope:Host

    UP LOOPBACK RUNNING MTU:65536 Metric:1

    RX packets:254 errors:0 dropped:0 overruns:0 frame:0

    TX packets:254 errors:0 dropped:0 overruns:0 carrier:0

    collisions:0 txqueuelen:0

    RX bytes:982788 (959.7 KiB) TX bytes:982788 (959.7 KiB)

       

    [root@model sudoers.d]#

    1.7.11 ss(centos7)

    ss -anptu:(相當於netstat,但是查詢速度比netstat較快)

    • a                                All,顯示全部的信息
    • n                                直接使用IP地址,不使用域名服務器
    • p                                程序名稱
    • t                                顯示tcp端口的傳輸信息
    • u                                顯示udp端口的傳輸信息

    [root@model sudoers.d]# ss -aputn

    Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port

    tcp LISTEN 0 128 :::22 :::* users:(("sshd",1280,4))

    tcp LISTEN 0 128 *:22 *:* users:(("sshd",1280,3))

    tcp LISTEN 0 100 ::1:25 :::* users:(("master",1360,13))

    tcp LISTEN 0 100 127.0.0.1:25 *:* users:(("master",1360,12))

    tcp ESTAB 0 52 192.168.43.210:22 192.168.43.200:52229 users:(("sshd",1649,3))

    [root@model sudoers.d]#

    1.7.12 ip route(centos 7)****

    ip route:查看路由

    [root@oldboyedu ~]# ip route show

    default via 10.0.0.254 dev eth0 proto static metric 100

    10.0.0.0/24 dev eth0 proto kernel scope link src 10.0.0.200 metric 100

    添加一條路由

    [root@oldboyedu ~]# ip route add 10.0.0.0/24 via 10.0.0.254 dev eth0

    刪除一條路由

    [root@oldboyedu ~]# ip route del 10.0.0.0/24

    1.7.13 ip addr:(centos7)*****

    查看IP地址:ip addr show

    [root@oldboyedu ~]# ip addr show

    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000

    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

    inet6 ::1/128 scope host

    valid_lft forever preferred_lft forever

    2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

    link/ether 00:0c:29:16:07:30 brd ff:ff:ff:ff:ff:ff

    inet 10.0.0.200/24 brd 10.0.0.255 scope global noprefixroute eth0

    valid_lft forever preferred_lft forever

    inet6 fe80::b736:dc22:2ec6:1b47/64 scope link noprefixroute

    valid_lft forever preferred_lft forever

    [root@oldboyedu ~]#

    查看指定IP地址:ip addr show interface

    [root@oldboyedu ~]# ip addr show eth0

    2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

    link/ether 00:0c:29:16:07:30 brd ff:ff:ff:ff:ff:ff

    inet 10.0.0.200/24 brd 10.0.0.255 scope global noprefixroute eth0

    valid_lft forever preferred_lft forever

    inet6 fe80::b736:dc22:2ec6:1b47/64 scope link noprefixroute

    valid_lft forever preferred_lft forever

    [root@oldboyedu ~]#

    1.7.14

    1.8 深入網絡操作命令

    1.8.1 nmap

    nmap命令: 一款開放源代碼的網絡探測和安全審核工具

    [root@oldboyedu ~]# nmap www.baidu.com

       

    Starting Nmap 6.40 ( http://nmap.org ) at 2019-09-06 10:15 CST

       

    [root@oldboyedu ~]#

    nmap -sn:查看10.0.0.0/24位主機里面的所有IP和mac地址

    [root@oldboyedu ~]# nmap -sn 10.0.0.0/24

       

    Starting Nmap 6.40 ( http://nmap.org ) at 2019-09-06 10:27 CST

    Nmap scan report for 10.0.0.1

    Host is up (0.00019s latency).

    MAC Address: 00:50:56:C0:00:08 (VMware)

    Nmap scan report for 10.0.0.254

    Host is up (0.000086s latency).

    MAC Address: 00:50:56:E9:AC:6B (VMware)

    Nmap scan report for 10.0.0.200

    Host is up.

    Nmap done: 256 IP addresses (3 hosts up) scanned in 2.33 seconds

    [root@oldboyedu ~]#

    1.8.2 lsof

    lsof:查看打開的進程文件

    [root@oldboyedu ~]# lsof

    COMMAND PID TID USER FD TYPE DEVICE SIZE/OFF NODE NAME

    systemd 1 root cwd DIR 8,3 4096 64 /

    systemd 1 root rtd DIR 8,3 4096 64 /

    systemd 1 root txt REG 8,3 1616360 410278 /usr/lib/systemd/systemd

    systemd 1 root mem REG 8,3 20112 84983 /usr/lib64/libuuid.so.1.3.0

    lsof -i TCP:只顯示TCP的連接

    [root@oldboyedu ~]# lsof -i TCP

    COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

    sshd 7389 root 3u IPv4 40544 0t0 TCP *:ssh (LISTEN)

    sshd 7389 root 4u IPv6 40553 0t0 TCP *:ssh (LISTEN)

    master 7547 root 13u IPv4 41145 0t0 TCP localhost:smtp (LISTEN)

    master 7547 root 14u IPv6 41146 0t0 TCP localhost:smtp (LISTEN)

    sshd 7761 root 3u IPv4 45009 0t0 TCP oldboyedu.com:ssh->10.0.0.1:59778 (ESTABLISHED)

    [root@oldboyedu ~]#

    lsof -i :port:查詢端口為(port)的網絡信息

    [root@oldboyedu ~]# lsof -i :22

    COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

    sshd 7389 root 3u IPv4 40544 0t0 TCP *:ssh (LISTEN)

    sshd 7389 root 4u IPv6 40553 0t0 TCP *:ssh (LISTEN)

    sshd 7761 root 3u IPv4 45009 0t0 TCP oldboyedu.com:ssh->10.0.0.1:59778 (ESTABLISHED)

    [root@oldboyedu ~]#

    lsof -i@IP地址:指定某個主機的連接是否成功

    [root@oldboyedu ~]# lsof -i@10.0.0.200

    COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

    sshd 7761 root 3u IPv4 45009 0t0 TCP oldboyedu.com:ssh->10.0.0.1:59778 (ESTABLISHED)

    [root@oldboyedu ~]# lsof -i@192.168.21.109

    [root@oldboyedu ~]# lsof -i@192.168.21.109

    [root@oldboyedu ~]# lsof -i@192.168.21.109

    [root@oldboyedu ~]#

    lsof | grep "EST*":查找以EST為首字母的進程信息

    [root@oldboyedu ~]# lsof | grep "EST*"

    abrtd 6329 root mem REG 8,3 546 201865084 /usr/share/locale/en_US/LC_MESSAGES/abrt.mo

    abrt-watc 6330 root mem REG 8,3 546 201865084 /usr/share/locale/en_US/LC_MESSAGES/abrt.mo

    sshd 7761 root 3u IPv4 45009 0t0 TCP oldboyedu.com:ssh->10.0.0.1:59778 (ESTABLISHED)

    [root@oldboyedu ~]#

    1.8.3 mail(后續整理)

    mail:電子郵件的接收和發送命令

       

    1.8.4 mutt(后續整理)

       

    1.8.5 nslookup

    安裝: yum install bind-utils -y

    nslookup:查看域名服務器的程序(非交互模式)

    [root@oldboyedu ~]# nslookup baidu.com

    Server:        223.5.5.5

    Address:    223.5.5.5#53

       

    Non-authoritative answer:

    Name:    baidu.com

    Address: 39.156.69.79

    Name:    baidu.com

    Address: 220.181.38.148

    nslookup:查看域名服務器的程序(交互模式)

    [root@oldboyedu ~]# nslookup

    > baidu.com

    Server:        223.5.5.5

    Address:    223.5.5.5#53

       

    Non-authoritative answer:

    Name:    baidu.com

    Address: 39.156.69.79

    Name:    baidu.com

    Address: 220.181.38.148

    > qq.com

    Server:        223.5.5.5

    Address:    223.5.5.5#53

       

    Non-authoritative answer:

    Name:    qq.com

    Address: 111.161.64.48

    Name:    qq.com

    Address: 111.161.64.40

       

    1.8.6 dig(后續整理)

    dig dns 查詢樣式

    dig dns

    [root@oldboyedu ~]# dig baidu.com

       

    ; <<>> DiG 9.9.4-RedHat-9.9.4-74.el7_6.2 <<>> baidu.com

    ;; global options: +cmd

    ;; Got answer:

    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 47861

    ;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

       

    ;; QUESTION SECTION:

    ;baidu.com.            IN    A

       

    ;; ANSWER SECTION:

    baidu.com.        15    IN    A    39.156.69.79

    baidu.com.        15    IN    A    220.181.38.148

       

    ;; Query time: 30 msec

    ;; SERVER: 223.5.5.5#53(223.5.5.5)

    ;; WHEN: Fri Sep 06 11:30:36 CST 2019

    ;; MSG SIZE rcvd: 59

       

    1.8.7 host

    host:查詢的DNS地址,轉換主機名稱的主機名為IP地址

    host DNS:查詢DNS

    [root@oldboyedu ~]# host baidu.com

    baidu.com has address 39.156.69.79

    baidu.com has address 220.181.38.148

    baidu.com mail is handled by 20 mx50.baidu.com.

    baidu.com mail is handled by 20 mx1.baidu.com.

    baidu.com mail is handled by 20 jpmx.baidu.com.

    baidu.com mail is handled by 15 mx.n.shifen.com.

    baidu.com mail is handled by 10 mx.maillb.baidu.com.

    [root@oldboyedu ~]#

    host -a DNS:詳細列出DNS信息

    [root@oldboyedu ~]# host -a baidu.com

    Trying "baidu.com"

    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56447

    ;; flags: qr rd ra; QUERY: 1, ANSWER: 12, AUTHORITY: 0, ADDITIONAL: 0

       

    ;; QUESTION SECTION:

    ;baidu.com.            IN    ANY

       

    ;; ANSWER SECTION:

    baidu.com.        503    IN    MX    20 mx1.baidu.com.

    baidu.com.        503    IN    MX    20 jpmx.baidu.com.

    baidu.com.        503    IN    MX    20 mx50.baidu.com.

    baidu.com.        503    IN    MX    10 mx.maillb.baidu.com.

    baidu.com.        503    IN    MX    15 mx.n.shifen.com.

    baidu.com.        503    IN    A    220.181.38.148

    baidu.com.        503    IN    A    39.156.69.79

    baidu.com.        503    IN    NS    ns2.baidu.com.

    baidu.com.        503    IN    NS    dns.baidu.com.

    baidu.com.        503    IN    NS    ns3.baidu.com.

    baidu.com.        503    IN    NS    ns4.baidu.com.

    baidu.com.        503    IN    NS    ns7.baidu.com.

       

    Received 265 bytes from 223.5.5.5#53 in 68 ms

    [root@oldboyedu ~]#

    1.8.8 traceroute

    traceroute:追蹤數據包的路由途徑

    [root@oldboyedu ~]# traceroute baidu.com

    traceroute to baidu.com (220.181.38.148), 30 hops max, 60 byte packets

    1 gateway (10.0.0.254) 0.140 ms 0.092 ms 0.109 ms

    2 * * *

    3 * * *

    traceroute -m 10:將跳數設置為10次

    [root@oldboyedu ~]# traceroute -m 10 baidu.com

    traceroute to baidu.com (39.156.69.79), 10 hops max, 60 byte packets

    1 gateway (10.0.0.254) 0.157 ms 0.086 ms 0.062 ms

    2 * * *

    3 * * *

    4 * * *

    5 * * *

    6 * * *

    traceroute -n :顯示IP地址不顯示主機名

    [root@oldboyedu ~]# traceroute -n baidu.com

    traceroute to baidu.com (220.181.38.148), 30 hops max, 60 byte packets

    1 10.0.0.254 0.086 ms 0.066 ms 0.060 ms

    7 * * *

    8 * * *

    9 * * *

    traceroute -p 6888 baidu.com :探測包使用的基本UDP端口設置6888

    [root@oldboyedu ~]# traceroute -p 6888 baidu.com

    traceroute to baidu.com (220.181.38.148), 30 hops max, 60 byte packets

    1 gateway (10.0.0.254) 0.322 ms 0.203 ms 0.203 ms

    2 * * *

    3 * * *

    4 * * *

    5 * * *

    [root@oldboyedu ~]#

    1.8.9 tcpdump(后續整理)

       

    1.9 有關磁盤與文件系統的命令

    1.9.1 mount****

    mount:磁盤存儲設備掛載命令

    [root@oldboy6666 ~]# mount /dev/cdrom /mnt

    mount: /dev/sr0 is write-protected, mounting read-only

    [root@oldboy6666 ~]# df -h

    Filesystem Size Used Avail Use% Mounted on

    /dev/sda3 99G 1.7G 97G 2% /

    devtmpfs 476M 0 476M 0% /dev

    tmpfs 487M 0 487M 0% /dev/shm

    tmpfs 487M 7.7M 479M 2% /run

    tmpfs 487M 0 487M 0% /sys/fs/cgroup

    /dev/sda1 197M 105M 93M 54% /boot

    tmpfs 98M 0 98M 0% /run/user/0

    /dev/sr0 4.3G 4.3G 0 100% /mnt

    [root@oldboy6666 ~]#

    1.9.2 umount****

    umount:磁盤設備卸載命令

    [root@oldboy6666 ~]# umount /mnt

    [root@oldboy6666 ~]# df -h

    Filesystem Size Used Avail Use% Mounted on

    /dev/sda3 99G 1.7G 97G 2% /

    devtmpfs 476M 0 476M 0% /dev

    tmpfs 487M 0 487M 0% /dev/shm

    tmpfs 487M 7.7M 479M 2% /run

    tmpfs 487M 0 487M 0% /sys/fs/cgroup

    /dev/sda1 197M 105M 93M 54% /boot

    tmpfs 98M 0 98M 0% /run/user/0

    [root@oldboy6666 ~]#

    1.9.3 fsck

    fsck:用於檢查試圖修復文件中的錯誤

    fsck -y:用於檢查指定硬盤的錯誤,檢查完畢就可以reboot重啟

    [root@oldboy6666 ~] # fsck -y /dev/sda3

    fsck from util-linux 2.23.2

    /sbin/fsck.xfs: XFS file system.

    [root@oldboy6666 ~] #

    fsck -a:自動修復文件,不進行任何提示

    [root@oldboy6666 ~] # fsck -a /dev/sda3

    fsck from util-linux 2.23.2

    /sbin/fsck.xfs: XFS file system.

    [root@oldboy6666 ~] #

    fsck -r :互動方式檢查

    [root@oldboy6666 ~] # fsck -r /dev/sda3

    fsck from util-linux 2.23.2

    If you wish to check the consistency of an XFS filesystem or

    repair a damaged filesystem, see xfs_repair(8).

    /dev/sda3: status 0, rss 1464, real 0.001992, user 0.001653, sys 0.000000

    [root@oldboy6666 ~] #

    1.9.4 dd****

    dd:用於復制文件對源文件的格式進行轉換和格式化的處理

    [root@oldboy6666 ~] # dd if=/dev/zero of=sun.txt bs=1b count=10000

    10000+0 records in

    10000+0 records out

    5120000 bytes (5.1 MB) copied, 0.0259372 s, 197 MB/s

    [root@oldboy6666 ~] # du -sh sun.txt

    4.9M    sun.txt

    [root@oldboy6666 ~] #

    參數解釋

  • if                                    輸入的設備文件(從黑洞中拿出來多少信息)
  • of                                    輸出的文件(將這些信息放到硬盤什么地方)
  • bs                                    每個塊的大小(每次取出來多少)
  • count                                一共有多少塊(一共取多少次)

    1.9.5 dumpe2fs(centos 6)

    dumpe2fs:用於打印文件系統的快組信息

    [root@oldboyedu ~] # dumpe2fs /dev/sda1

    dumpe2fs 1.41.12 (17-May-2010)

    Filesystem volume name: <none>

    Last mounted on: /boot

    Filesystem UUID: 0dc58de8-08a7-46dd-af2d-668a34a440cc

    Filesystem magic number: 0xEF53

    Filesystem revision #: 1 (dynamic)

    Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize

    Filesystem flags: signed_directory_hash

    Default mount options: user_xattr acl

    Filesystem state: clean

    Errors behavior: Continue

    Filesystem OS type: Linux

    Inode count: 51200

    Block count: 204800

    Reserved block count: 10240

    Free blocks: 167150

    Free inodes: 51162

    First block: 1

    Block size: 1024

    Fragment size: 1024

    Reserved GDT blocks: 256

    Blocks per group: 8192

    Fragments per group: 8192

    Inodes per group: 2048

    Inode blocks per group: 256

    Flex block group size: 16

    Filesystem created: Mon Sep 9 22:07:07 2019

    Last mount time: Sat Sep 14 23:32:06 2019

    Last write time: Sat Sep 14 23:32:06 2019

    Mount count: 12

    Maximum mount count: -1

    Last checked: Mon Sep 9 22:07:07 2019

    Check interval: 0 (<none>)

    Lifetime writes: 36 MB

    Reserved blocks uid: 0 (user root)

    Reserved blocks gid: 0 (group root)

    First inode: 11

    Inode size:     128

    Journal inode: 8

    Default directory hash: half_md4

    Directory Hash Seed: de2e40af-8694-4d07-be95-bfd80a33b5d5

    Journal backup: inode blocks

    Journal features: (none)

    Journal size: 4096k

    Journal length: 4096

    Journal sequence: 0x0000001a

    Journal start: 0

       

    1.9.6 dump(后續整理)

    1.9.7 fdisk********

       

  • d    delete a partition                            刪除一個分區
  • g    create a new empty GPT partition table            創建一個新的GPT分區表(默認dos)
  • l    list known partition types                    列出已知的分區類型
  • m    print this menu                            列出幫助菜單
  • n    add a new partition                            添加一個新的分區
  • p    print the partition table                        打印分區表
  • q    quit without saving changes                    退出不保存
  • t    change a partition's system id                    改變一個分區的系統ID
  • w    write table to disk and exit                    保存並且退出

    fdisk分區的方式

    [root@oldboyedu scripts] # fdisk /dev/sdb 開始磁盤分區

    Welcome to fdisk (util-linux 2.23.2).

       

    Changes will remain in memory only, until you decide to write them.

    Be careful before using the write command.

       

    Device does not contain a recognized partition table

    Building a new DOS disklabel with disk identifier 0x12ca22cf.

    Command (m for help): 創建一個新的分區

    Partition type:

    p primary (0 primary, 0 extended, 4 free)

    e extended

    Select (default p): p

    Partition number (1-4, default 1): 開始分第一個主分區

    First sector (2048-2097151, default 2048):

    Using default value 2048

    Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): +100M 第一個主分區分100M

    Partition 1 of type Linux and of size 100 MiB is set

       

    Command (m for help): n 再次創建新的主分區

    Partition type:

    p primary (1 primary, 0 extended, 3 free)

    e extended

    Select (default p): p

    Partition number (2-4, default 2): 2 開始分第二個分區

    First sector (206848-2097151, default 206848):

    Using default value 206848

    Last sector, +sectors or +size{K,M,G} (206848-2097151, default 2097151): +100M 第二個主分區分100M

    Partition 2 of type Linux and of size 100 MiB is set

       

    Command (m for help):

    Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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: 0x12ca22cf

       

    Device Boot Start End Blocks Id System

    /dev/sdb1 2048 206847 102400 83 Linux 查看分的2個主分區

    /dev/sdb2 206848 411647 102400 83 Linux

       

    Command (m for help):

    Command (m for help):

    ….

    繼續分區…………..

       

    1.9.8 parted*****

  • mklabel,mktable LABEL-TYPE                            創建分區表的類型
  • mkpart PART-TYPE [FS-TYPE] START END                創建主分區並且設置類型其實和終點
  • print [devices|free|list,all|NUMBER]                        查看分區信息
  • quit                                                    退出,並且會自動保存
  • rm NUMBER                                            刪除分區(以ID代表)

    parted分區方式

    [root@oldboyedu ~] # parted /dev/sdc 使用parted開始分區

    GNU Parted 3.1

    Using /dev/sdc

    Welcome to GNU Parted! Type 'help' to view a list of commands.

    (parted) mklabel gpt 修改分區類型為GPT

    Warning: The existing disk label on /dev/sdc will be destroyed and all data on this disk will be lost. Do you want to continue?

    Yes/No? yes

    (parted) p 查看當前是否有分區信息

    Model: VMware, VMware Virtual S (scsi)

    Disk /dev/sdc: 3221GB

    Sector size (logical/physical): 512B/512B

    Partition Table: gpt

    Disk Flags:

       

    Number Start End Size File system Name Flags

       

    (parted) mkpart primary xfs 0 2500G 創建一個文件系統為xfs的並且大小為2500G的分區

    Warning: The resulting partition is not properly aligned for best performance.

    Ignore/Cancel? I

    (parted) p 分區創建成功

    Model: VMware, VMware Virtual S (scsi)

    Disk /dev/sdc: 3221GB

    Sector size (logical/physical): 512B/512B

    Partition Table: gpt

    Disk Flags:

       

    Number Start End Size File system Name Flags

    1 17.4kB 2500GB 2500GB primary

       

    (parted) q 保存與退出

    Information: You may need to update /etc/fstab.

       

    [root@oldboyedu ~] # mkfs.xfs /dev/sdc1 格式化分區

    meta-data=/dev/sdc1 isize=512 agcount=4, agsize=152587890 blks

    = sectsz=512 attr=2, projid32bit=1

    = crc=1 finobt=0, sparse=0

    data = bsize=4096 blocks=610351558, imaxpct=5

    = sunit=0 swidth=0 blks

    naming =version 2 bsize=4096 ascii-ci=0 ftype=1

    log =internal log bsize=4096 blocks=298023, version=2

    = sectsz=512 sunit=0 blks, lazy-count=1

    realtime =none extsz=4096 blocks=0, rtextents=0

    You have new mail in /var/spool/mail/root

    [root@oldboyedu ~] # mount /dev/sdc1 /mnt/ 掛載分區

    [root@oldboyedu ~] # df -h

    Filesystem Size Used Avail Use% Mounted on

    /dev/sda3 99G 5.2G 94G 6% /

    devtmpfs 471M 0 471M 0% /dev

    tmpfs 487M 0 487M 0% /dev/shm

    tmpfs 487M 8.4M 478M 2% /run

    tmpfs 487M 0 487M 0% /sys/fs/cgroup

    /dev/sda1 197M 160M 37M 82% /boot

    tmpfs 98M 12K 98M 1% /run/user/42

    tmpfs 98M 0 98M 0% /run/user/0

    /dev/sdc1 2.3T 33M 2.3T 1% /mnt 查看創建的分區是否掛載成功並且分區大小一致

    [root@oldboyedu ~] #

       

    1.9.9 mkfs*****

    centos6將xfs改成ext4則可

       

    [root@oldboyedu ~] # mkfs.xfs /dev/sdc1 格式化分區,不使用參數的方法

    meta-data=/dev/sdc1 isize=512 agcount=4, agsize=152587890 blks

    = sectsz=512 attr=2, projid32bit=1

    = crc=1 finobt=0, sparse=0

    data = bsize=4096 blocks=610351558, imaxpct=5

    = sunit=0 swidth=0 blks

    naming =version 2 bsize=4096 ascii-ci=0 ftype=1

    log =internal log bsize=4096 blocks=298023, version=2

    = sectsz=512 sunit=0 blks, lazy-count=1

    realtime =none extsz=4096 blocks=0, rtextents=0

    You have new mail in /var/spool/mail/root

       

    [root@oldboyedu ~] # mkfs -t xfs /dev/sdc1 格式化分區,使用參數-t的方法

    meta-data=/dev/sdc1 isize=512 agcount=4, agsize=152587890 blks

    = sectsz=512 attr=2, projid32bit=1

    = crc=1 finobt=0, sparse=0

    data = bsize=4096 blocks=610351558, imaxpct=5

    = sunit=0 swidth=0 blks

    naming =version 2 bsize=4096 ascii-ci=0 ftype=1

    log =internal log bsize=4096 blocks=298023, version=2

    = sectsz=512 sunit=0 blks, lazy-count=1

    realtime =none extsz=4096 blocks=0, rtextents=0

    You have new mail in /var/spool/mail/root

       

       

    1.9.10 partprobe(后續整理)

    1.9.11 e2fsck(后續整理)

    1.9.12 mkswap******

    [root@oldboyedu mnt] # dd if=/dev/zero of=/tmp/1G bs=100M count=10

    從黑洞中拿出來1G交給/tmp/1G使用

    10+0 records in

    10+0 records out

    1048576000 bytes (1.0 GB) copied, 3.58782 s, 292 MB/s

    [root@oldboyedu mnt] # ll -h /tmp/1G

    -rw-r--r-- 1 root root 1000M Oct 5 15:26 /tmp/1G

    [root@oldboyedu mnt] #

    標記給swap空間

    [root@oldboyedu mnt] # mkswap /tmp/1G 標記給swap空間

    Setting up swapspace version 1, size = 1023996 KiB

    no label, UUID=8eea78e2-8f88-4c77-89a4-9910047d1983

    [root@oldboyedu mnt] #

       

    1.9.13 swapon******

    [root@oldboyedu mnt] # free -h

    total used free shared buff/cache available

    Mem: 972M 343M 154M 10M 473M 436M

    Swap: 1.5G 0B 1.5G 空閑1.5G

    You have new mail in /var/spool/mail/root

    [root@oldboyedu mnt] # swap

    swaplabel swapoff swapon

    [root@oldboyedu mnt] # swapon /tmp/1G 增加1G

    swapon: /tmp/1G: insecure permissions 0644, 0600 suggested.

    [root@oldboyedu mnt] # free -h

    total used free shared buff/cache available

    Mem: 972M 344M 153M 10M 474M 435M

    Swap: 2.5G 0B 2.5G 空閑2.5G

    [root@oldboyedu mnt] #

       

    1.9.14 swapoff*****

    [root@oldboyedu mnt] # free -h

    total used free shared buff/cache available

    Mem: 972M 344M 153M 10M 474M 435M

    Swap: 2.5G 0B 2.5G 空閑2.5G

    [root@oldboyedu mnt] # swapoff /tmp/1G 增加1G

    You have new mail in /var/spool/mail/root

    [root@oldboyedu mnt] # free -h

    total used free shared buff/cache available

    Mem: 972M 344M 154M 10M 474M 436M

    Swap: 1.5G 0B 1.5G 空閑1.5G

    [root@oldboyedu mnt] #

       

    1.9.15 sync(后續整理)

    1.9.16 resize2fs(后續整理)

    1.9.17 blkid****

    blkid:查看磁盤的UUID

    [root@oldboy6666 ~]# blkid /dev/cdrom

    /dev/cdrom: UUID="2018-11-25-23-54-16-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"

    [root@oldboy6666 ~]#

    1.10 系統權限及用戶授權相關命令

    1.10.1 chmod*******

    chmod命令單個來修改權限

    (1) u+r:修改單個用戶的屬主讀權限

    [root@oldboyedu oldboy02] # chmod a=- aa.txt

    [root@oldboyedu oldboy02] # ll

    total 0

    d--------- 2 root root 6 Oct 1 20:00 aa.txt

    [root@oldboyedu oldboy02] # chmod u+r aa.txt

    [root@oldboyedu oldboy02] # ll

    total 0

    dr-------- 2 root root 6 Oct 1 20:00 aa.txt

    [root@oldboyedu oldboy02] #

    (2) u+w:修改單個用戶的屬主寫權限

    [root@oldboyedu oldboy02] # chmod u+w aa.txt

    [root@oldboyedu oldboy02] # ll

    total 0

    drw------- 2 root root 6 Oct 1 20:00 aa.txt

    [root@oldboyedu oldboy02] #

    (3) u+x:修改單個用戶的屬主執行權限

    [root@oldboyedu oldboy02] # chmod u+x aa.txt

    [root@oldboyedu oldboy02] # ll

    total 0

    drwx------ 2 root root 6 Oct 1 20:00 aa.txt

    [root@oldboyedu oldboy02] #

    同樣:g(group):代表用戶的屬組

    o(other):代表其他用戶

    chmod命令批量修改權限

    (1).利用數值進行修改

    [root@oldboyedu oldboy02] # chmod 777 aa.txt aa.txt屬主,屬組,其他全部修改成777

    [root@oldboyedu oldboy02] # ll

    total 0

    drwxrwxrwx 2 root root 6 Oct 1 20:00 aa.txt

    [root@oldboyedu oldboy02] #

    (2).利用符號a進行修改

    [root@oldboyedu oldboy02] # chmod a=rwx aa.txt aa.txt屬主,屬組,其他全部修改成777

    [root@oldboyedu oldboy02] # ll

    total 0

    drwxrwxrwx 2 root root 6 Oct 1 20:00 aa.txt

    [root@oldboyedu oldboy02] #

    (3).利用-R遍歷修改

    [root@oldboyedu oldboy02] # chmod -R 777 aa aa/bb/cc.txt全部修改成權限777

    [root@oldboyedu oldboy02] # ll aa

    total 0

    drwxrwxrwx 3 root root 20 Oct 1 20:08 bb

    [root@oldboyedu oldboy02] # cd bb

    -bash: cd: bb: No such file or directory

    [root@oldboyedu oldboy02] # cd aa/bb

    [root@oldboyedu bb] # ll

    total 0

    drwxrwxrwx 2 root root 6 Oct 1 20:08 cc.txt

    [root@oldboyedu bb] #

       

    1.10.2 chown*******

    chown命令修改權限

    (1).屬主信息

    [root@oldboyedu oldboy02] # chown oldboy01 aa.txt 將屬主更換成oldboy01

    [root@oldboyedu oldboy02] # ll

    total 0

    drwxrwxrwx 3 root root 16 Oct 1 20:08 aa

    d--------- 2 oldboy01 root 6 Oct 1 20:00 aa.txt

    [root@oldboyedu oldboy02] #

    (2).屬組信息

    [root@oldboyedu oldboy02] # chown .oldboy01 aa.txt 將屬組更換成oldboy01(.oldboy01)

    [root@oldboyedu oldboy02] # l

    bash: l: command not found...

    [root@oldboyedu oldboy02] # ll

    total 0

    drwxrwxrwx 3 root root 16 Oct 1 20:08 aa

    d--------- 2 oldboy01 oldboy01 6 Oct 1 20:00 aa.txt

    [root@oldboyedu oldboy02] #

    (3).全部信息

    drwxrwxrwx 3 root root 16 Oct 1 20:08 aa

    d--------- 2 oldboy01 oldboy01 6 Oct 1 20:00 aa.txt

    [root@oldboyedu oldboy02] # chown root.root aa.txt 將屬主和屬組都更換成root

    [root@oldboyedu oldboy02] # ll

    total 0

    drwxrwxrwx 3 root root 16 Oct 1 20:08 aa

    d--------- 2 root root 6 Oct 1 20:00 aa.txt

    [root@oldboyedu oldboy02]

       

    [root@oldboyedu oldboy02] # ll

    total 0

    drwxrwxrwx 3 root root 16 Oct 1 20:08 aa

    d--------- 2 root root 6 Oct 1 20:00 aa.txt

    [root@oldboyedu oldboy02] # chown oldboy01. aa.txt 將屬主和屬組都更換成oldboy01

       

    [root@oldboyedu oldboy02] # ll

    total 0

    drwxrwxrwx 3 root root 16 Oct 1 20:08 aa

    d--------- 2 oldboy01 oldboy01 6 Oct 1 20:00 aa.txt

    [root@oldboyedu oldboy02] #

    (4).屬主.屬組遍歷(-R)

    [root@oldboyedu oldboy02] # chown -R oldboy01. aa aa目錄下面的所有文件和目錄都更換成 oldboy01的屬主和屬組

    [root@oldboyedu oldboy02] # ll

    total 0

    drwxrwxrwx 3 oldboy01 oldboy01 16 Oct 1 20:08 aa

    d--------- 2 oldboy01 oldboy01 6 Oct 1 20:00 aa.txt

    [root@oldboyedu oldboy02] # ll -d aa/bb

    drwxrwxrwx 3 oldboy01 oldboy01 20 Oct 1 20:08 aa/bb

    [root@oldboyedu oldboy02] # ll aa/bb/cc.txt

    total 0

    [root@oldboyedu oldboy02] # cd aa/bb/cc.txt

    [root@oldboyedu cc.txt] # ll

    total 0

    [root@oldboyedu cc.txt] # ls

    [root@oldboyedu cc.txt] # cd ..

    [root@oldboyedu bb] # ls

    cc.txt

    [root@oldboyedu bb] # ll

    total 0

    drwxrwxrwx 2 oldboy01 oldboy01 6 Oct 1 20:08 cc.txt

    [root@oldboyedu bb] #

       

       

    1.10.3 chgrp

  • -c                        效果類似"-v"參數,但僅回報更改的部分
  • -f或–quiet                不顯示錯誤信息;
  • -h                        只對符號連接的文件作修改,而不是該其他任何相關文件;
  • -R                        遞歸處理,將指令目錄下的所有文件及子目錄一並處理;
  • -v                        顯示指令執行過程;
  • –reference                把指定文件或目錄的所屬群組全部設成和參考文件或目錄

    的所屬群組相同;

    將bb.txt文件的屬組用戶更改為oldboy10

    [root@oldboyedu ~] # ll

    total 0

    dr--r--r-- 2 root root 6 Sep 29 17:05 bb

    -r--r--r-- 1 root root 0 Sep 29 17:05 bb.txt

    [root@oldboyedu ~] # chgrp oldboy10 bb.txt

    [root@oldboyedu ~] # ll

    total 0

    dr--r--r-- 2 root root 6 Sep 29 17:05 bb

    -r--r--r-- 1 root oldboy10 0 Sep 29 17:05 bb.txt

    [root@oldboyedu ~] #

       

    1.10.4 umask******

    umask值的查看

    [root@oldboyedu /] # umask

    0022

    [root@oldboyedu /] #

    uamsk的修改

    umask的臨時修改

    [root@oldboyedu /] # umask 000 將umask值修改為000

    [root@oldboyedu /] # touch aa.txt

    [root@oldboyedu /] # ll aa.txt

    -rw-rw-rw- 1 root root 0 Sep 29 16:58 aa.txt 查看文件umask值發現是666

    [root@oldboyedu /] #

    [root@oldboyedu /] # mkdir aa

    [root@oldboyedu /] # ll aa

    total 0

    [root@oldboyedu /] # ll aa -d

    drwxrwxrwx 2 root root 6 Sep 29 17:00 aa 查看目錄umask值為777

    [root@oldboyedu /] #

       

    [root@oldboyedu ~] # umask 333 將umask改為333

    [root@oldboyedu ~] # rm aa.txt

    rm: cannot remove 'aa.txt': No such file or directory

    [root@oldboyedu ~] # touch aa.txt

    [root@oldboyedu ~] # ll aa.txt

    -r--r--r-- 1 root root 0 Sep 29 17:05 aa.txt 文件權限為444

    [root@oldboyedu ~] # mkdir bb

    [root@oldboyedu ~] # ll -d bb

    dr--r--r-- 2 root root 6 Sep 29 17:05 bb 目錄權限為444

    [root@oldboyedu ~] #

    文件權限umaks為333的時候,為什么創建出來的文件默認權限為444?

    文件默認權限創建出來為奇數的時候回默認加1(333)+(111)=(444)

    umask的永久修改

    在/etc/profile文件中查找出if判斷語句

    if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then

    umask 002

    else

    umask 022

    fi

    if判斷語句的說明

  • $UID 得到當前用戶的ID值
  • -gn 代表用戶組的ID和名稱
  • -un 代表用戶的ID和名稱

       

    1.11 查看系統用戶登陸信息的命令

    1.11.1 whoami****

    whoami:查看當前登陸的用戶

    [root@oldboy6666 ~] # whoami

    root

    [root@oldboy6666 ~]

       

    1.11.2 who****

    who:顯示目前用戶登陸的信息(這個信息是以終端開啟為主的,目前開了1個)

    [root@oldboy6666 ~] # who

    root pts/0 2019-09-14 15:35 (10.0.0.1)

       

    1.11.3 w***

    w:用於登陸系統的用戶信息

    [root@oldboy6666 ~] # w

    18:08:21 up 9:30, 3 users, load average: 0.00, 0.01, 0.05

    USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT

    root pts/0 10.0.0.1 17:11 5.00s 0.08s 0.03s w

    root pts/3 10.0.0.1 15:11 57:33 0.04s 0.04s -bash

    root pts/4 10.0.0.1 15:00 57:41 0.38s 0.28s -bash

    [root@oldboy6666 ~] #

  • USER                                    目前登陸的用戶
  • TTY                                        連接用戶的方式為遠程連接
  • FROM                                    從哪台機器登陸的
  • LOGIN@                                幾點開始連接服務器的
  • IDLE                                    目前連接了多長時間
  • JCPU/PCPU                                cpu的使用率
  • WHAT                                    終端目前正在操作什么

    1.11.4 last****

    last:顯示用戶最近登陸的信息(-n)

    [root@oldboy6666 ~] # last -10

    root pts/1 10.0.0.1 Sat Sep 14 16:55 - 16:58 (00:03)

    root pts/0 10.0.0.1 Sat Sep 14 15:35 still logged in

    reboot system boot 3.10.0-957.el7.x Sat Sep 14 15:34 - 17:00 (01:26)

    root pts/0 10.0.0.1 Thu Sep 12 16:55 - down (00:45)

    root pts/0 10.0.0.1 Thu Sep 12 16:00 - 16:55 (00:55)

    root pts/0 10.0.0.1 Thu Sep 12 11:05 - 16:00 (04:54)

    root pts/0 10.0.0.1 Thu Sep 12 11:05 - 11:05 (00:00)

    root pts/0 10.0.0.1 Thu Sep 12 10:42 - 11:05 (00:22)

    reboot system boot 3.10.0-957.el7.x Thu Sep 12 10:42 - 17:41 (06:59)

    root pts/0 10.0.0.1 Thu Sep 12 10:28 - down (00:13)

       

    wtmp begins Fri Aug 30 12:29:17 2019

    [root@oldboy6666 ~] #

    last -x +命令:輸出最近執行命令的信息

    [root@oldboy6666 ~] # last -x reboot -n 2

    reboot system boot 3.10.0-957.el7.x Sat Sep 14 15:34 - 17:05 (01:31)

    reboot system boot 3.10.0-957.el7.x Thu Sep 12 10:42 - 17:41 (06:59)

       

    wtmp begins Fri Aug 30 12:29:17 2019

    [root@oldboy6666 ~] #

    1.11.5 lastlog********

    lastlog:用於顯示最近所有登陸用戶信息記錄

    [root@oldboy6666 ~] # lastlog

    Username Port From Latest

    root pts/1 10.0.0.1 Sat Sep 14 16:55:14 +0800 2019

    bin **Never logged in**

    daemon **Never logged in**

    adm **Never logged in**

    lp **Never logged in**

    sync **Never logged in**

    shutdown **Never logged in**

    halt **Never logged in**

    mail **Never logged in**

    operator **Never logged in**

    games **Never logged in**

    ftp **Never logged in**

    nobody **Never logged in**

    systemd-network **Never logged in**

    dbus **Never logged in**

    polkitd **Never logged in**

    tss **Never logged in**

    abrt **Never logged in**

    sshd **Never logged in**

    postfix **Never logged in**

    chrony **Never logged in**

    apache **Never logged in**

    oldboy01 **Never logged in**

    oldboy02 **Never logged in**

    oldboy03 **Never logged in**

    oldboy04 **Never logged in**

    oldboy05 **Never logged in**

    oldboy06 **Never logged in**

    oldboy07 **Never logged in**

    oldboy08 **Never logged in**

    oldboy09 **Never logged in**

    oldboy10 **Never logged in**

    ntp **Never logged in**

    [root@oldboy6666 ~] #

    1.11.6 users

    users: 用於顯示當前登錄系統所有的用戶的用戶列表

    [root@oldboy6666 ~] # users

    root

    1.11.7 finger

    finger:顯示用戶的登陸信息(包括帳號名稱,真實姓名,登入終端機)

    [root@oldboy6666 ~] # finger

    Login Name Tty Idle Login Time Office Office Phone Host

    root root pts/0 Sep 14 15:35 (10.0.0.1)

    root root pts/1 27 Sep 14 17:10 (10.0.0.1)

    [root@oldboy6666 ~] #

       

    1.12 內置命令及其它

    1.12.1 echo*****

    echo:將信息輸入到屏幕上

    [root@oldboy6666 ~]# echo "aa"

    aa

    [root@oldboy6666 ~]#

    標准輸出重定向

    [root@oldboy6666 ~]# echo "aa" > 2.txt

    [root@oldboy6666 ~]# cat 2.txt

    aa

    [root@oldboy6666 ~]#

    標准追加輸出重定向

    [root@oldboy6666 ~]# echo "bb" >> 2.txt

    [root@oldboy6666 ~]# cat 2.txt

    aa

    bb

    [root@oldboy6666 ~]#

    echo -e:可以支持控制字符

    -n:輸出內容后不會在下一行切換

    [root@oldboy6666 scripts] # echo -n "c.biancheng.net"

    c.biancheng.net[root@oldboy6666 scripts] #

    錯誤輸出重定向

    [root@oldboy6666 scripts] # ech 111 2> error.log

    [root@oldboy6666 scripts] # cat error.log

    -bash: ech: command not found

    錯誤追加輸出重定向

    [root@oldboy6666 scripts] # ech 222 2>> error.log

    [root@oldboy6666 scripts] # cat error.log

    -bash: ech: command not found

    -bash: ech: command not found

       

    生成序列

    [root@oldboy6666 oldboy] # echo {01..10}

    01 02 03 04 05 06 07 08 09 10

    [root@oldboy6666 oldboy] #

    1.12.2 printf

    進行格式化的輸出

    printf 格式 文本1 文本2 ..

       

    普通格式轉換符

  • %s                字符串
  • %f                浮點格式
  • %c                ASCII字符,即顯示對應參數的第一個字符
  • %d,%i            十進制整數
  • %o                八進制值
  • %u                不帶正負號的十進制值
  • %x                十六進制值(a-f)
  • %X                十六進制值(A-F)
  • %%                表示%本身

       

    常用的轉義字符

  • \a                警告字符,通常為ASCII的BEL字符
  • \b                后退
  • \f                換頁
  • \n                換行
  • \r                回車
  • \t                水平制表符
  • \v                垂直制表符
  • \\                表示\本身

       

    字符串格式並且換行

    [root@oldboyedu scripts] # printf "%s\n" 1 2 3 4

    1

    2

    3

    4

    [root@oldboyedu scripts] #

    浮點格式並且換行(默認6位)

    [root@oldboyedu scripts] # printf "%f\n" 1 2 3 4

    1.000000

    2.000000

    3.000000

    4.000000

    [root@oldboyedu scripts] #

    浮點格式只保留2位並切換行

    [root@oldboyedu scripts] # printf "%.2f\n" 1.1 2.1 3 4

    1.10

    2.10

    3.00

    4.00

    [root@oldboyedu scripts] #

    浮點格式第一個保留2位,第二個保留3位,第三個保留1位,並且換行

    [root@oldboyedu scripts] # printf "%.2f %.3f %.1f\n" 1.1 2.1 3 4

    1.10 2.100 3.0

    4.00 0.000 0.0

    [root@oldboyedu scripts] #

    字符格式顯示出下列姓名,性別,學歷信息

    "-":表示左邊對齊

    -n:n代表的是中間隔幾個字符

    [root@oldboyedu scripts] # printf "%-8s %-6s %-7s\n" 姓名 性別 學歷 梁宇星  大專

    姓名 性別 學歷

    梁宇星  大專

    [root@oldboyedu scripts] #

    10進制轉16進制%x(小寫)%X(大寫)

    [root@oldboyedu scripts] # printf "%x\n" 14 printf 需要被轉換成的進制數 轉換的進制數

    e

    [root@oldboyedu scripts] #

       

    [root@oldboyedu scripts] # printf "%X\n" 14 printf 需要被轉換成的進制數 轉換的進制數

    E

    [root@oldboyedu scripts] #

    16進制轉10進制%d或者%i

    [root@oldboyedu scripts] # printf "%i\n" 0xc

    12

    [root@oldboyedu scripts] # printf "%d\n" 0xc

    12

    [root@oldboyedu scripts] #

    1.12.3 rpm*****

    語法:rpm -ivh *.rpm

  • i:install 安裝的意思
  • v: verbose 顯示安裝信息的詳細過程
  • h:human 以人類可以認知的方式閱讀
  • -qa 查找軟件包完整名字
  • -ql 查找軟件包的詳細信息
  • rpm -e 卸載軟件包(需要該軟件沒有關聯性)
  • rpm -e *.rpm –nodes 卸載軟件包(可以忽略關聯包的信息)

       

    特點:先要把軟件包下載好,在安裝

    沒有解決依賴關系

       

    1.12.4 yum****

  • yum -y groupinstall                    軟件名稱 安裝包組
  • yum -y reinstall                    軟件名稱 重新安裝
  • yum list                            遍歷軟件
  • yum grouplist                        遍歷軟件包
  • yum repolist                        查看系統具有的yum源信息
  • yum provides                        查看安裝的軟件屬於哪個大禮包

       

    [root@oldboy6666 ~] # yum -y install figner

    Loaded plugins: fastestmirror

    Loading mirror speeds from cached hostfile

    * base: mirrors.aliyun.com

    * extras: mirrors.aliyun.com

    * updates: mirrors.aliyun.com

    No package figner available.

    Error: Nothing to do

    [root@oldboy6666 ~] # yum -y install finger

    Loaded plugins: fastestmirror

    Loading mirror speeds from cached hostfile

    * base: mirrors.aliyun.com

    * extras: mirrors.aliyun.com

    * updates: mirrors.aliyun.com

    Resolving Dependencies

    --> Running transaction check

    ---> Package finger.x86_64 0:0.17-52.el7 will be installed

    --> Finished Dependency Resolution

       

    Dependencies Resolved

       

    ======================================================================================================================================================

    Package Arch Version Repository Size

    ======================================================================================================================================================

    Installing:

    finger x86_64 0.17-52.el7 base 25 k

       

    Transaction Summary

    ======================================================================================================================================================

    Install 1 Package

       

    Total download size: 25 k

    Installed size: 32 k

    Downloading packages:

    finger-0.17-52.el7.x86_64.rpm | 25 kB 00:00:00

    Running transaction check

    Running transaction test

    Transaction test succeeded

    Running transaction

    Installing : finger-0.17-52.el7.x86_64 1/1

    Verifying : finger-0.17-52.el7.x86_64 1/1

       

    Installed:

    finger.x86_64 0:0.17-52.el7

       

    Complete!

    查找yum指定安裝包的包名(provides)

    [root@oldboy6666 ~] # yum install -y locate

    Loaded plugins: fastestmirror

    No package locate available.

    Error: Nothing to do----------------沒有找到這個安裝包

    [root@oldboy6666 ~] # yum provides locate

    Loaded plugins: fastestmirror

    Loading mirror speeds from cached hostfile

       

    mlocate-0.26-8.el7.x86_64 : An utility for finding files by name 安裝包的名字為mlocate

    Repo : base

    Matched from:

    Filename : /usr/bin/locate

       

    [root@oldboy6666 ~] # yum install -y mlocate 重新安裝mlocate

    Loaded plugins: fastestmirror

    Loading mirror speeds from cached hostfile

    * base: mirrors.aliyun.com

    * extras: mirrors.aliyun.com

    * updates: mirrors.aliyun.com

       

    Installed:

    mlocate.x86_64 0:0.26-8.el7

       

    Complete! 安裝成功

    1.12.5 watch

    watch :會周期性的檢測一個命令的運行結果

    1.12.6 alias*****

    將別名ifname輸入,得到查看主機名的信息

    [root@oldboy6666 ~] # alias ifname='cat /etc/hostname'

    [root@oldboy6666 ~] # ifname

    oldboy6666

    [root@oldboy6666 ~] #

    1.12.7 unalias*****

    將別名ifname失效

    [root@oldboy6666 ~] # unalias ifname

    [root@oldboy6666 ~] # ifname

    -bash: ifname: command not found

    [root@oldboy6666 ~] #

    1.12.8 date*****

  • 代表年
  • 代表年(帶世紀)
  • 代表分鍾
  • 代表月
  • 代表天
  • 代表秒
  • 代表一年的第幾周
  • 代表這周星期幾
  • 代表小時

       

    11.5.1.1 date命令

    [root@oldboy6666 oldboy] # date

    Tue Sep 17 08:28:48 CST 2019

    [root@oldboy6666 oldboy] #

    將時間修改成人類可讀的時間類型

    [root@oldboy6666 oldboy] # date "+%Y-%m-%d %H:%M:%S"

    2019-09-17 10:05:20

    [root@oldboy6666 oldboy] #

    修改時間

  • -s 修改時間

    [root@oldboy6666 oldboy] # date -s "20190918 10:20:00"

    Wed Sep 18 10:20:00 CST 2019

    [root@oldboy6666 oldboy] # date

    Wed Sep 18 10:20:02 CST 2019

    [root@oldboy6666 oldboy] # date "+%Y-%m-%d %H:%M:%S"

    2019-09-18 10:20:05

    [root@oldboy6666 oldboy] #

    將時間進行穿越式的修改

    查看后20天的時間

    [root@oldboy6666 ~] # date -d "+20 day" "+%Y-%m-%d"

    2019-10-08

    [root@oldboy6666 ~] #

    查看前5天的時間

    [root@oldboy6666 ~] # date -d "-5 day" "+%Y-%m-%d"

    2019-09-13

    [root@oldboy6666 ~] #

    查看197001-01后的1234567890秒時間

    [root@oldboy6666 tmp] # date -d "1970-01-01 +1234567890second" "+%F %T"

    2009-02-13 23:31:30

    [root@oldboy6666 tmp] #

       

       

    1.12.9 clear

    清除終端信息

    1.12.10 history****

    history:查看歷史記錄

    [root@oldboy6666 ~] # history

    35 192.168.21.201

    36 ping 192.168.21.201

    37 ping 192.168.22.201

    38 ping 10.0.0.202

    39 ip route del gw 10.0.0.254

    40 ip route del default gw 10.0.0.254

    41 systemctl restart network

    42 ip route show

    43 ping 223.5.5.5

    44 ping 10.0.0.1

    45 ping 10.0.0.254

    46 ping 192.168.21.21

    47 vi /etc/sysconfig/network-scripts/ifcfg-eth0

    48 ls

    49 vi /etc/sysconfig/network-scripts/ifcfg-eth0

    50 ls

    51 systemctl restrat network

    52 systemctl restart network

    53 poweroff

    54 c

    55 ls --help

    56 ls -d /mnt/

    57 ls

    58 ls /m

    59 ls /mnt/

    60 ks

    history 10:顯示最近的10條記錄

    [root@oldboy6666 ~] # history 10

    1028 date -d "-1 day" +"%Y-%m-%d"

    1029 date -d "-1 mo'n't'ho" +"%Y-%m-%d"

    1030 date -d "-1 month" +"%Y-%m-%d"

    1031 date -d "+1 month" +"%Y-%m-%d"

    1032 date -d "+1 year" +"%Y-%m-%d"

    1033 date -d "-1 year" +"%Y-%m-%d"

    1034 history

    1035 history -n 10

    1036 history 10

    1037 history 10

    history -c:清除歷史記錄

    [root@oldboy6666 ~] # history -c

    [root@oldboy6666 ~] # histoy

    -bash: histoy: command not found

    [root@oldboy6666 ~] # history

    39 histoy

    40 history

    [root@oldboy6666 ~] #

    [root@oldboy6666 ~] #

    history -w:保存歷史數據到~/.bash_history目錄下

    [root@oldboy6666 ~] # history -w

    [root@oldboy6666 ~] # cat ~/.bash_history

    cat ~/.bash_history

    ls

    cat

    cd .

    ls

    ll

    history

    history -w

    [root@oldboy6666 ~] #

    1.12.11 eject

    用於退出抽取式設備

    [root@oldboyedu scripts] # eject /dev/cdrom

    [root@oldboyedu scripts] #

    1.12.12 time****

    [root@oldboy6666 ~] # ntpdate ntp1.aliyun.com

    12 Sep 16:57:03 ntpdate[8479]: adjust time server 120.25.115.20 offset 0.000488 sec

    [root@oldboy6666 ~] #

    自動更新時間常用的參數

    [root@oldboy6666 ~] # timedatectl

    list-timezones 顯示所有時區(timedatectl list-timezones)

       

    set-local-rtc 更新硬件(bios)時間(timedatectl set-local-rtc 1)

    1:代表開啟 0代表關閉

    set-ntp ntp服務器時間的更新(timedatectl set-ntp 1)

    1:代表開啟 0代表關閉

    set-time 更新時間(timedatectl set-time 20190528)

       

    set-timezone 設置時區(timedatectl set-timezone +時區)

    [root@oldboy6666 ~] # timedatectl

    1.12.13 nc(后續整理)

    nc:簡稱neicat用來設置路由器

    1.12.14 xargs*********

    用於整合數據和分組

    xargs -n num:分組為n num, 分組

    [root@oldboy6666 oldboy01] # find /root/oldboy01/ -name "*.txt" | xargs -n2

    /root/oldboy01/oldboy1.txt /root/oldboy01/oldboy2.txt

    /root/oldboy01/oldboy3.txt /root/oldboy01/oldboy4.txt

    /root/oldboy01/oldboy5.txt /root/oldboy01/oldboy6.txt

    /root/oldboy01/oldboy7.txt /root/oldboy01/oldboy8.txt

    /root/oldboy01/oldboy9.txt /root/oldboy01/oldboy10.txt

    [root@oldboy6666 oldboy01] #

       

    xargs -i :將執行結果放循環放到后面的{}里面 整合

    [root@oldboy6666 oldboy01] # find /root/oldboy01/ -name "*.txt" | xargs -i cp {} /tmp/oldboy_tmp/

    [root@oldboy6666 oldboy01] # cd /tmp/oldboy_tmp/

       

    [root@oldboy6666 oldboy_tmp] # ls

    oldboy10.txt oldboy1.txt oldboy2.txt oldboy3.txt oldboy4.txt oldboy5.txt oldboy6.txt oldboy7.txt oldboy8.txt oldboy9.txt

    [root@oldboy6666 oldboy_tmp] #

       

       

       

    1.12.15 exec******

    \;和+;的區別

    1.exec執行原理不同

  • \;會查找出來一條數據就會進行直接處理,處理完成才會進行第二條數據的處理,直到處理完畢
  • +;會講所有數據查詢完畢,在一起處理,例如(tar命令打包操作)

    2.輸入方式有區別

  • \;可以在{}后面添加數據
  • +;只能和{}直接相連,不能中間插入數據

    查找文件並且刪除(使用\來解決)

    [root@oldboy6666 oldboy02] # find /root/oldboy01/ -name "2.txt"

    /root/oldboy01/oldboy02/2.txt

    /root/oldboy01/2.txt

    [root@oldboy6666 oldboy02] # find /root/oldboy01/ -name "2.txt" -exec rm {} \;

    [root@oldboy6666 oldboy02] # find /root/oldboy01/ -name "2.txt"

       

    [root@oldboy6666 oldboy02] #

       

    將文件進行打包(使用+號來不進行覆蓋,進行累加)

    [root@oldboy6666 tmp] # find /oldboy -name "*.txt" -exec tar zcvf /tmp/oldboy1.tar.gz {} +;
    tar: Removing leading `/&apos; from member names
    /oldboy/1.txt
    /oldboy/2.txt
    /oldboy/3.txt
    /oldboy/4.txt
    /oldboy/aa.txt
    /oldboy/bb.txt
    [root@oldboy6666 tmp] # tar tf oldboy1.tar.gz 
    oldboy/1.txt
    oldboy/2.txt
    oldboy/3.txt
    oldboy/4.txt
    oldboy/aa.txt
    oldboy/bb.txt
    [root@oldboy6666 tmp] #

       

    1.12.16 export

    用於設置和顯示環境變量

    列出當前環境的變量名

    [root@oldboyedu ~] # export -p

    declare -x HISTCONTROL="ignoredups"

    declare -x HISTSIZE="1000"

    declare -x HOME="/root"

    declare -x HOSTNAME="oldboyedu"

    declare -x LANG="en_US.UTF-8"

    declare -x LESSOPEN="||/usr/bin/lesspipe.sh %s"

    declare -x LOGNAME="root"

    declare -x LS_COLORS="rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:"

    declare -x MAIL="/var/spool/mail/root"

    declare -x OLDPWD

    declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin"

    declare -x PS1="[\\[\\e[35;1m\\]\\u\\[\\e[31;1m\\]@\\[\\e[36;1m\\]\\h \\[\\e[33;1m\\]\\W\\[\\e[0m\\]] \\[\\e[34;1m\\]\\\$ \\[\\e[0m\\]"

    declare -x PWD="/root"

    declare -x QT_GRAPHICSSYSTEM_CHECKED="1"

    declare -x SHELL="/bin/bash"

    declare -x SHLVL="1"

    declare -x SSH_CLIENT="10.0.0.1 61038 22"

    declare -x SSH_CONNECTION="10.0.0.1 61038 10.0.0.200 22"

    declare -x SSH_TTY="/dev/pts/1"

    declare -x TERM="linux"

    declare -x USER="root"

    declare -x XDG_DATA_DIRS="/root/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share"

    declare -x XDG_RUNTIME_DIR="/run/user/0"

    declare -x XDG_SESSION_ID="243"

    [root@oldboyedu ~] #

       

    1.12.17 unset

    取消變量的設置

    [root@oldboyedu ~] # aa=`cat /etc/hosts`

    [root@oldboyedu ~] # echo $aa

    127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

    [root@oldboyedu ~] # unset aa

    [root@oldboyedu ~] # echo $aa

    1.12.18 type

    判斷一個名字當前是否是alias、keyword、function、builtin、file或者什么都不是

       

  • type ls 的輸出是 ls 是 `ls --color=auto' 的別名

       

  • type if 的輸出是 if 是 shell 關鍵字

       

  • type type 的輸出是 type 是 shell 內嵌

       

  • type frydsh 的輸出是 bash: type: frydsh: 未找到

       

    判斷一個名字當前是否是alias、keyword、function、builtin、file或者什么都不是的另一種方法(適用於腳本編程)

       

  • type -t ls 的輸出是 alias

       

  • type -t if 的輸出是 keyword

       

  • type -t type 的輸出是 builtin

       

  • type -t gedit 的輸出是 file

       

  • type -t frydsh 沒有輸出

       

    顯示一個名字的所有可能

       

  • type -a kill 的輸出是 kill 是 shell 內嵌 和 kill 是 /bin/kill

       

  • type -at kill 的輸出是 builtin 和 file

       

    查看一個命令的執行路徑(如果它是外部命令的話)

       

  • type -p gedit 的輸出是 /usr/bin/gedit

       

  • type -p kill 沒有輸出(因為kill是內置命令)

       

    強制搜索外部命令

       

  • type -P kill 的輸出是 /bin/kill

    1.12.19 bc

    整數計算,並且結果是整數

    [root@oldboyedu ~] # bc

    bc 1.06.95

    Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.

    This is free software with ABSOLUTELY NO WARRANTY.

    For details type `warranty'.

    3+2+5+9

    19

    整數計算,最后得出的有小數的(需要輸入scale=n[n代表的是小數位有幾位])

    [root@oldboyedu ~] # bc

    bc 1.06.95

    Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.

    This is free software with ABSOLUTELY NO WARRANTY.

    For details type `warranty'.

    scale=4

    100/3

    33.3333

    1.12.20 seq*****

    生成序列

    [root@oldboy6666 oldboy] # seq 1 10

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    [root@oldboy6666 oldboy] #

    生成等差序列

       

    生成奇數序列

    [root@oldboy6666 oldboy] # seq 1 2 10

    1

    3

    5

    7

    9

    生成偶數序列

    [root@oldboy6666 oldboy] # seq 0 2 10

    0

    2

    4

    6

    8

    10

    [root@oldboy6666 oldboy] #

    對齊序列

    [root@oldboy6666 oldboy] # seq -w 1 10

    01

    02

    03

    04

    05

    06

    07

    08

    09

    10

    [root@oldboy6666 oldboy] #

    1.13 系統管理與性能監視命令

    1.13.1 chkconfig(后續整理)

    1.13.2 vmstat(后續整理)

    1.13.3 mpstat(后續整理)

    1.13.4 iostat(后續整理)

    1.13.5 sar(后續整理)

    1.13.6 ipcs(后續整理)

    1.13.7 ipcrm(后續整理)

    1.13.8 strace(后續整理)

    1.13.9 ltrace(后續整理)

    1.14 關機/重啟/注銷和查看系統信息的命令

    1.14.1 shutdown****

    shutdown :重啟/關閉

    shutdown -r 5:5分鍾之后重啟(0/now是立即重啟)

    [root@oldboyedu ~]# shutdown -r 5 "system will 5 after reboot"

    Shutdown scheduled for Wed 2019-09-04 14:38:14 CST, use 'shutdown -c' to cancel.

       

    Broadcast message from root@oldboyedu.com (Wed 2019-09-04 14:33:14 CST):

    system will 5 after reboot

    The system is going down for reboot at Wed 2019-09-04 14:38:14 CST!

       

    Shutdown -h 5:5分鍾之后關機(0/now是立即關機)

    [root@oldboyedu ~]# shutdown -h 5 "system will 5 after poweroff"

    Shutdown scheduled for Wed 2019-09-04 14:42:33 CST, use 'shutdown -c' to cancel.

    [root@oldboyedu ~]#

    Broadcast message from root@oldboyedu.com (Wed 2019-09-04 14:37:33 CST):

       

    system will 5 after poweroff

    The system is going down for power-off at Wed 2019-09-04 14:42:33 CST

    1.14.2 halt****

    halt:用來關閉linux系統,關閉會檢測linux的運行狀態(0,6才會使用)

    halt -d:關閉系統,但不留下記錄

    halt -f:不論目前什么等級都不調用shutdown來強制關閉系統

    halt -p:關閉系統后關閉電源

    1.14.3 poweroff*****

    poweroff:立即關閉系統

    Last login: Wed Sep 4 14:49:25 2019 from 10.0.0.1

    [root@oldboyedu ~]# poweroff

       

    Connection closed by foreign host.

       

    Disconnected from remote host(老男孩66-模板主機) at 14:50:17.

       

    Type `help' to learn how to use Xshell prompt.

    1.14.4 logout*****

    Logout:退出當前登陸的shell,相當於ctrl+d

    [root@oldboyedu ~]# logout

       

    Connection closed by foreign host.

       

    Disconnected from remote host(老男孩66-模板主機) at 14:52:54.

       

    Type `help' to learn how to use Xshell prompt.

    1.14.5 exit*****

    exit:和logout差不多,也是指退出當前shell

    [root@oldboyedu ~]# exit

    logout

       

    Connection closed by foreign host.

       

    Disconnected from remote host(老男孩66-模板主機) at 14:57:04.

       

    Type `help' to learn how to use Xshell prompt.

       

    在shell腳本里面,指狀態值,如果是0,則成功,如果是其他數字,則表示失敗

    [root@oldboyedu ~]# cd aa | exit 0

    -bash: cd: aa: No such file or directory

    [root@oldboyedu ~]# cd aa | exit 1

    -bash: cd: aa: No such file or directory

    [root@oldboyedu ~]#

    1.14.6 init*****

    init 0:關機命令

    init 6:重啟命令

    init1:單用戶模式(救援模式)

    init 3:多用戶模式

    init 2:多用戶模式(沒有網絡)

    init4:未設置的,空余的

       

    1.15 進程管理相關命令

    1.15.1 bg

    將一個后台暫停的命令,變成繼續執行

    1.15.2 fg

    將一個前台暫停的命令變成繼續執行

    1.15.3 jobs

    有多少在后台暫停的任務

    [root@oldboyedu oldboy01] # jobs

    [1]- Stopped vim /etc/hosts

    [2]+ Stopped vim /etc/selinux/config

    [root@oldboyedu oldboy01] #

    1.15.4 kill

    kill表示的是殺死指定進程,默認不帶任何參數是15信號發送

       

  • 1                                終端斷線
  • 2                                等同 Ctrl + C
  • 3                                等同Ctrl + \
  • 15                                終止(可以使得進程在退出之前清理並釋放資源)
  • 9                                 強制終止
  • 18                                繼續(與19相反)
  • 19                                 暫停(等同 Ctrl + Z)

    查看kill的所有信號信息

    [root@oldboyedu oldboy01] # kill -l

    1) SIGHUP     2) SIGINT     3) SIGQUIT     4) SIGILL     5) SIGTRAP

    6) SIGABRT     7) SIGBUS     8) SIGFPE     9) SIGKILL    10) SIGUSR1

    11) SIGSEGV    12) SIGUSR2    13) SIGPIPE    14) SIGALRM    15) SIGTERM

    16) SIGSTKFLT    17) SIGCHLD    18) SIGCONT    19) SIGSTOP    20) SIGTSTP

    21) SIGTTIN    22) SIGTTOU    23) SIGURG    24) SIGXCPU    25) SIGXFSZ

    26) SIGVTALRM    27) SIGPROF    28) SIGWINCH    29) SIGIO    30) SIGPWR

    31) SIGSYS    34) SIGRTMIN    35) SIGRTMIN+1    36) SIGRTMIN+2    37) SIGRTMIN+3

    38) SIGRTMIN+4    39) SIGRTMIN+5    40) SIGRTMIN+6    41) SIGRTMIN+7    42) SIGRTMIN+8

    43) SIGRTMIN+9    44) SIGRTMIN+10    45) SIGRTMIN+11    46) SIGRTMIN+12    47) SIGRTMIN+13

    48) SIGRTMIN+14    49) SIGRTMIN+15    50) SIGRTMAX-14    51) SIGRTMAX-13    52) SIGRTMAX-12

    53) SIGRTMAX-11    54) SIGRTMAX-10    55) SIGRTMAX-9    56) SIGRTMAX-8    57) SIGRTMAX-7

    58) SIGRTMAX-6    59) SIGRTMAX-5    60) SIGRTMAX-4    61) SIGRTMAX-3    62) SIGRTMAX-2

    63) SIGRTMAX-1    64) SIGRTMAX    

    [root@oldboyedu oldboy01] #

    強制殺死crond(定時任務)的進程

    [root@oldboyedu oldboy01] # ps -ef | grep crond

    root 1330 1 0 07:48 ? 00:00:00 /usr/sbin/crond -n

    root 2704 1385 0 08:26 pts/1 00:00:00 grep --color=auto crond

    [root@oldboyedu oldboy01] # kill -9 1330

    [root@oldboyedu oldboy01] # ps -ef | grep crond

    root 2706 1385 0 08:26 pts/1 00:00:00 grep --color=auto crond

    [root@oldboyedu oldboy01] #

    init進程是殺不死的

    [root@oldboyedu oldboy01] # ps -ef | grep init 查看init進程

    root 950 1 0 07:47 ? 00:00:00 /usr/sbin/alsactl -s -n 19 -c -E ALSA_CONFIG_PATH=/etc/alsa/alsactl.conf --initfile=/lib/alsa/init/00main rdaemon

    root 2734 1385 0 08:29 pts/1 00:00:00 grep --color=auto init

    [root@oldboyedu oldboy01] # pkill -9 950 殺死init進程ID

    [root@oldboyedu oldboy01] # ps -ef | grep init 再次查看發現進程還存在

    root 950 1 0 07:47 ? 00:00:00 /usr/sbin/alsactl -s -n 19 -c -E ALSA_CONFIG_PATH=/etc/alsa/alsactl.conf --initfile=/lib/alsa/init/00main rdaemon

    root 2737 1385 0 08:29 pts/1 00:00:00 grep --color=auto init

    [root@oldboyedu oldboy01] # pkill -9 950 再強制殺死進程ID

    [root@oldboyedu oldboy01] # ps -ef | grep init 再次查看發現進程還存在

    root 950 1 0 07:47 ? 00:00:00 /usr/sbin/alsactl -s -n 19 -c -E ALSA_CONFIG_PATH=/etc/alsa/alsactl.conf --initfile=/lib/alsa/init/00main rdaemon

    root 2740 1385 0 08:29 pts/1 00:00:00 grep --color=auto init

    殺死連接在終端不需要的用戶(-t指定終斷連接的用戶)

    [root@oldboyedu ~] # w 查看

    08:39:28 up 51 min, 2 users, load average: 0.00, 0.01, 0.05

    USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT

    root pts/1 10.0.0.1 07:48 10:08 0.37s 0.30s -bash

    root pts/0 10.0.0.1 08:35 0.00s 0.03s 0.00s w

    [root@oldboyedu ~] # pkill -kill -t pts/1

    [root@oldboyedu ~] # 2

    bash: 2: command not found...

    [root@oldboyedu ~] # w

    08:40:30 up 52 min, 1 user, load average: 0.00, 0.01, 0.05

    USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT

    root pts/0 10.0.0.1 08:35 6.00s 0.03s 0.00s w

    [root@oldboyedu ~] #

    1.15.5 killall

  • -9                                強制殺死進程名稱

    殺死指定進程的名稱

    [root@oldboyedu ~] # ps -ef | grep crond 查看進程

    root 3541 1 0 09:36 ? 00:00:00 /usr/sbin/crond -n

    root 3546 3439 0 09:36 pts/1 00:00:00 grep --color=auto crond

    [root@oldboyedu ~] # killall crond 殺死指定進程名稱

    [root@oldboyedu ~] # ps -ef | grep crond 再次查看發現已經殺死

    root 3549 3439 0 09:36 pts/1 00:00:00 grep --color=auto crond

    [root@oldboyedu ~] #

    1.15.6 pkill

    pkill和killall的使用基本一樣,都是殺死進程名稱

    1.15.7 crontab********

    一個命令

    crontab -l:查看配置的定時任務

    [root@oldboyedu ~] # crontab -l

    30 2 * * * cp -rf /etc/hosts /etc/hosts.bak

    [root@oldboyedu ~] #

    crontab -e:編寫定時任務

    [root@oldboyedu ~] # crontab -e

    no crontab for root - using an empty one

    30 2 * * *

    crontab -r:清空定時任務配置的任務信息

    [root@oldboyedu ~] # crontab -l 查看定時任務信息

    #30 */1 * * * cp /etc/hosts /etc/hosts_lyx.bak

    #*/5 * * * * /usr/sbin/ntpdate ntp1.aliyun.com

    #*/5 * * * * sh /server/scripts/ntpdate_sync.sh & > /dev/null

    #* * * * * tar zcvf /opt/hosts_$(date +\%F).tar.gz /etc/hosts

    #* * * * * sh /server/scripts/tar_sync.sh & >/dev/null

    [root@oldboyedu ~] # crontab -r 清除定時任務信息

    [root@oldboyedu ~] # crontab -l 再次查看發現已經沒有信息

    no crontab for root

    [root@oldboyedu ~] #

    倆個文件

    root用戶設置定時任務的配置文件

    [root@oldboyedu ~] # ll /var/spool/cron/root root用戶設置定時任務的配置文件

       

    -rw------- 1 root root 44 Oct 2 15:25 /var/spool/cron/root

    [root@oldboyedu ~] #

    root用戶定時任務的日志文件

    [root@oldboyedu ~] # tail -f /var/log/cron root用戶定時任務的日志文件

    Oct 2 19:30:01 oldboyedu CROND[8172]: (root) CMD (/usr/lib64/sa/sa1 1 1)

    Oct 2 19:40:01 oldboyedu CROND[8258]: (root) CMD (/usr/lib64/sa/sa1 1 1)

    Oct 2 19:50:01 oldboyedu CROND[8345]: (root) CMD (/usr/lib64/sa/sa1 1 1)

    Oct 2 20:00:01 oldboyedu CROND[8431]: (root) CMD (/usr/lib64/sa/sa1 1 1)

    Oct 2 20:01:02 oldboyedu CROND[8444]: (root) CMD (run-parts /etc/cron.hourly)

    Oct 2 20:01:02 oldboyedu run-parts(/etc/cron.hourly)[8444]: starting 0anacron

    Oct 2 20:01:02 oldboyedu run-parts(/etc/cron.hourly)[8453]: finished 0anacron

       

  • Oct 2 20:01:02                                    產生定時任務信息的時間
  • oldboyedu                                         用戶主機名
  • run-parts(/etc/cron.hourly)[8453]                        讀取什么定時任務文件信息
  • finished 0anacron                                    執行了什么定時任務

       

       

    1.15.8 ps

    ps -ef:查看所有進程

    [root@oldboyedu ~] # ps -ef

    UID PID PPID C STIME TTY TIME CMD

    root 1 0 0 07:47 ? 00:00:05 /usr/lib/systemd/systemd --switched-root --system --deserialize 22

    root 634 2 0 07:47 ? 00:00:00 [xfs-log/sda1]

    root 636 2 0 07:47 ? 00:00:00 [xfs-eofblocks/s]

    root 641 2 0 07:47 ? 00:00:00 [xfsaild/sda1]

    root 691 2 0 07:47 ? 00:00:00 [jbd2/sdb1-8]

    root 694 2 0 07:47 ? 00:00:00 [ext4-rsv-conver]

    root 787 2 0 07:47 ? 00:00:00 [kdmflush]

    root 788 2 0 07:47 ? 00:00:00 [bioset]

    root 790 2 0 07:47 ? 00:00:00 [kdmflush]

    root 791 2 0 07:47 ? 00:00:00 [bioset]

    root 918 1 0 07:47 ? 00:00:00 /sbin/auditd

    root 920 918 0 07:47 ? 00:00:00 /sbin/audispd

    root 922 920 0 07:47 ? 00:00:00 /usr/sbin/sedispatch

    root 925 2 0 07:47 ? 00:00:00 [rpciod]

    root 926 2 0 07:47 ? 00:00:00 [xprtiod]

    libstor+ 949 1 0 07:47 ? 00:00:00 /usr/bin/lsmd -d

    dbus 971 1 0 07:47 ? 00:00:00 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation

    ……….省略進程信息

    root 3598 1 0 09:41 ? 00:00:00 /usr/sbin/crond -n

    root 3604 3439 0 09:41 pts/1 00:00:00 ps -ef

    ps -ef | grep 進程名字:查找指定進程名稱

    [root@oldboyedu ~] # ps -ef | grep crond 查找crond進程信息

    root 3598 1 0 09:41 ? 00:00:00 /usr/sbin/crond -n

    root 3603 3439 0 09:41 pts/1 00:00:00 grep --color=auto crond

    1.15.9 pstree

    以樹狀圖的方式展現進程之間的派生關系,顯示效果比較直觀

    pstree -p:顯示所有的進程

    [oldboy10@oldboyedu sysconfig] $ pstree -p

    systemd(1)─┬─ModemManager(970)─┬─{ModemManager}(978)

    │ └─{ModemManager}(982)

    ├─NetworkManager(1021)─┬─{NetworkManager}(1039)

    │ └─{NetworkManager}(1042)

    ├─VGAuthService(986)

    │ └─{ibus-portal}(1911)

    ├─ibus-x11(1902)─┬─{ibus-x11}(1909)

    …………..省略

    │ └─{ibus-x11}(1912)

    licant(1934)

    └─xdg-permission-(1915)─┬─{xdg-permission-}(1916)

    └─{xdg-permission-}(1918)

    [oldboy10@oldboyedu sysconfig] $

    pstree -u:顯示所有的用戶名稱

    [oldboy10@oldboyedu sysconfig] $ pstree -u

    systemd─┬─ModemManager───2*[{ModemManager}]

    ├─NetworkManager───2*[{NetworkManager}]

    ├─auditd─┬─audispd─┬─sedispatch

      └─{audispd}

     └─{auditd}

    ……….省略

    ├─dnsmasq(nobody)───dnsmasq(root)

    ├─gdm─┬─X───{X}

     ├─gdm-session-wor─┬─gnome-session-b(gdm)─┬─gnome-shell─┬─

    ├─vmtoolsd───{vmtoolsd}

    ├─wpa_supplicant

    └─xdg-permission-(gdm)───2*[{xdg-permission-}]

    [oldboy10@oldboyedu sysconfig] $

       

    1.15.10 nice/renice

    調整程序優先執行的命令

    [root@oldboyedu ~] # ps -l

    F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD

    4 S 0 4524 4520 0 80 0 - 29195 do_wai pts/1 00:00:00 bash

    0 R 0 4585 4524 0 80 0 - 38309 - pts/1 00:00:00 ps

    [root@oldboyedu ~] # nice -n 5 cat&

    [1] 4586

    [root@oldboyedu ~] # ps -l

    F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD

    4 S 0 4524 4520 0 80 0 - 29195 do_wai pts/1 00:00:00 bash

    0 T 0 4586 4524 0 85 5 - 26993 do_sig pts/1 00:00:00 cat

    0 R 0 4587 4524 0 80 0 - 38309 - pts/1 00:00:00 ps

       

    [1]+ Stopped nice -n 5 cat

    1.15.11 nohup(后續整理)

       

    1.15.12 pgrep

    以程序為名稱從運行進程隊列中查找進程

    pgrep -la:你要查找的進程名稱的詳細信息

    [root@oldboyedu ~] # pgrep -la httpd

    2378 /usr/sbin/httpd -DFOREGROUND

    2379 /usr/sbin/httpd -DFOREGROUND

    2380 /usr/sbin/httpd -DFOREGROUND

    2381 /usr/sbin/httpd -DFOREGROUND

    2382 /usr/sbin/httpd -DFOREGROUND

    2383 /usr/sbin/httpd -DFOREGROUND

    [root@oldboyedu ~] #

    pgrep -l:查看進程ID和名稱

    [root@oldboyedu ~] # pgrep -l httpd

    2378 httpd

    2379 httpd

    2380 httpd

    2381 httpd

    2382 httpd

    2383 httpd

    [root@oldboyedu ~] #

    pgrep -lo:查看進程名稱最小的ID號碼

    [root@oldboyedu ~] # pgrep -lo httpd

    2378 httpd

    [root@oldboyedu ~] #

    pgrep -ln: 查看進程名稱最大ID號碼

    [root@oldboyedu ~] # pgrep -ln httpd

    2383 httpd

    [root@oldboyedu ~] #

    pgrep:查看進程名稱的ID

    [root@oldboyedu ~] # pgrep ttpd

    2378

    2379

    2380

    2381

    2382

    2383

    [root@oldboyedu ~] #

       

    1.15.13 runlevel

    查看系統的運行級別

    [root@oldboy6666 ~] # runlevel

    N 3

    [root@oldboy6666 ~] #

    1.15.14 init

    init 0:關機命令

    init 6:重啟命令

    init1:單用戶模式(救援模式)

    init 3:多用戶模式

    init 2:多用戶模式(沒有網絡)

    init4:未設置的,空余的

       

    1.15.15 service

    service默認等於/etc/init.d

  • service 服務名稱 status                        查看服務的狀態
  • service 服務名稱 start                            將服務啟動
  • service 服務名稱 stop                            將服務停止
  • service 服務名稱 restart                        將服務重啟

    1.15.16 systemctl

  • systemctl status 服務名稱                        查看服務狀態
  • systemctl start 務名稱                            啟動服務(臨時)
  • systemctl stop 服務名稱                        停止服務(臨時)
  • systemctl enable 服務名稱                        永久開啟服務
  • systemctl disable 服務名稱                        永遠關閉服務
  • systemctl set-default 運行target                    設置什么模式開啟系統
  • systemctl get-default                            查看當前是什么模式運行的系統

       

    1.16 文件壓縮及解壓縮命令

    1.16.1 tar*******

    1.16.1.1 壓縮命令

    壓縮常見的參數詳解

    標准模式czvf 特殊模式:czvPhf

  • c 創建一個壓縮文件
  • z 壓縮成gzip文件格式的
  • v 詳細顯示壓縮的過程
  • 指定壓縮包的路徑
  • h 壓縮的時候不會壓縮軟連接文件,會直接壓縮真正的文件
  • P 壓縮的時候采用絕對路徑的壓縮,解壓的時候也是,(會造成文件的覆蓋)
  • --exclude-from=指定的文件 將文件中的內容排除,不進行打包
  • --exclude=排除的文件目錄 將指定的文件進行排除

    壓縮文件格式

    格式:tar czvf 壓縮包的名字 壓縮的數據

    /root/oldboy01/下面的文件找到,並且進行打包,打包名字為oldboy_tar.tar.gz

    [root@oldboy6666 ~] # find /root/oldboy01/ -name "*.txt" | xargs tar czvf /root/oldboy_tar.tar.gz

    tar: Removing leading `/' from member names

    /root/oldboy01/oldboy1.txt

    /root/oldboy01/oldboy2.txt

    /root/oldboy01/oldboy3.txt

    /root/oldboy01/oldboy4.txt

    /root/oldboy01/oldboy5.txt

    /root/oldboy01/oldboy6.txt

    /root/oldboy01/oldboy7.txt

    /root/oldboy01/oldboy8.txt

    /root/oldboy01/oldboy9.txt

    /root/oldboy01/oldboy10.txt

    [root@oldboy6666 ~] # ls

    anaconda-ks.cfg oldboy01 oldboy_tar.tar.gz passwd

    [root@oldboy6666 ~] #

    /etc/rc.local進行打包(必須加參數h,要不就的去打包本身的路徑)

    [root@oldboy6666 ~] # tar zcvfh rc.local.tar.gz /etc/rc.local

    tar: Removing leading `/' from member names

    /etc/rc.local

    [root@oldboy6666 ~] # ls

    anaconda-ks.cfg h oldboy01 oldboy_tar.tar.gz passwd rc.local.tar.gz

    [root@oldboy6666 ~] # tar tf rc.local.tar.gz

    etc/rc.local

    [root@oldboy6666 ~] #

       

    將/oldboy/oldboy01下面的a.txt,b.txt打包, 將/oldboy/oldboy02下面的c.txt,a.txt不打包,剩余的打包

  1. 使用- -exclude-from方法解決

    [root@oldboy6666 oldboy] # tar zcvf oldboy01.tar.gz ./oldboy01 ./oldboy02 --exclude-from=./1.txt

    ./oldboy01/

    ./oldboy01/a.txt

    ./oldboy01/b.txt

    ./oldboy02/

    ./oldboy02/b.txt

    ./oldboy02/c.txt

    [root@oldboy6666 oldboy] # cat 1.txt

    ./oldboy01/c.txt

    ./oldboy02/a.txt

    [root@oldboy6666 oldboy] #

       

    (2)使用- -exclude進行解決

    [root@oldboy6666 oldboy] # tar zcvf oldboy01.tar.gz ./oldboy01 --exclude=./oldboy01/c.txt ./oldboy02 --exclude=./oldboy02/a.txt

    ./oldboy01/

    ./oldboy01/a.txt

    ./oldboy01/b.txt

    ./oldboy02/

    ./oldboy02/b.txt

    ./oldboy02/c.txt

    [root@oldboy6666 oldboy] #

    解答

  • tar: Removing leading `/' from member names?

    出現這個問題是因為:一個警告,告訴你打包的時候會將根排除,因為如果將根打包會造成解壓的時候數據覆蓋

    解決辦法

    • 采取相對路徑進行打包操作
    • 采取帶P參數進行操作

    1.16.1.2 查看壓縮命令

    查看壓縮文件的格式

    tar tf 查看的壓縮包

    查看oldboy_tar.tar.gz里面的內容是否壓縮完整

    [root@oldboy6666 ~] # tar tf oldboy_tar.tar.gz

    root/oldboy01/oldboy1.txt

    root/oldboy01/oldboy2.txt

    root/oldboy01/oldboy3.txt

    root/oldboy01/oldboy4.txt

    root/oldboy01/oldboy5.txt

    root/oldboy01/oldboy6.txt

    root/oldboy01/oldboy7.txt

    root/oldboy01/oldboy8.txt

    root/oldboy01/oldboy9.txt

       

    [root@oldboy6666 ~] #

    1.16.1.3 解壓命令

    解壓常見的參數

  • x 進行解壓
  • -C 指定解壓的路徑

    解壓格式

    tar xf 解壓的壓縮包

    oldboy01.tar.gz進行解壓

    [root@oldboy6666 oldboy_tmp] # tar xf oldboy01.tar.gz

    [root@oldboy6666 oldboy_tmp] # ls

    oldboy01.tar,gz oldboy01.tar.gz root

    [root@oldboy6666 oldboy_tmp] # ls

    oldboy01.tar,gz oldboy01.tar.gz root

    [root@oldboy6666 oldboy_tmp] # ls

    oldboy01.tar,gz oldboy01.tar.gz root

    [root@oldboy6666 oldboy_tmp] # cd /root/oldboy01/

    [root@oldboy6666 oldboy01] # ls

    oldboy02 oldboy10.txt oldboy1.txt oldboy2.txt oldboy3.txt oldboy4.txt oldboy5.txt oldboy6.txt oldboy7.txt oldboy8.txt oldboy9.txt

    [root@oldboy6666 oldboy01] #

       

    oldboy01.tar.gz解壓到/tmp目錄下

    [root@oldboy6666 oldboy] # ls

    oldboy01.tar.gz oldboy01.txt oldboy02.txt oldboy03.txt

    [root@oldboy6666 oldboy] # tar xf oldboy01.tar.gz -C /tmp

    [root@oldboy6666 oldboy] # cd -

    /tmp

    [root@oldboy6666 tmp] # ls

    oldboy01.txt oldboy02.txt oldboy03.txt

    [root@oldboy6666 tmp] #

       

    1.16.2 unzip

    unzip是解壓后綴為zip的壓縮包

    [root@oldboyedu oldboy01] # unzip /oldboy02/oldboy.zip

    Archive: /oldboy02/oldboy.zip

    extracting: oldboy01.txt

    extracting: oldboy02.txt

    extracting: oldboy.txt

    inflating: passwd_lyx.txt

    [root@oldboyedu oldboy01] # ll

    total 16

    dr-xr-xr-x 2 1019 root 20 Sep 28 22:07 aa

    -rw-r--r-- 1 root root 9 Oct 8 20:08 oldboy01.txt

    -rw-r--r-- 1 root root 9 Oct 8 20:08 oldboy02.txt

    -rw-r--r-- 1 root root 7 Oct 8 20:08 oldboy.txt

    -rw-r--r-- 1 root root 654 Oct 8 20:31 passwd_lyx.txt

    [root@oldboyedu oldboy01] #

    1.16.3 gzip

    壓縮文件(-v)

    [root@oldboyedu oldboy02] # gzip -v *

    oldboy01.txt:    -22.2% -- replaced with oldboy01.txt.gz

    oldboy02.txt:    -22.2% -- replaced with oldboy02.txt.gz

    oldboy.txt:    -28.6% -- replaced with oldboy.txt.gz

    passwd_lyx.txt:     54.0% -- replaced with passwd_lyx.txt.gz

    [root@oldboyedu oldboy02] # ll

    total 16

    -rw-r--r-- 1 root root 42 Oct 8 20:08 oldboy01.txt.gz

    -rw-r--r-- 1 root root 42 Oct 8 20:08 oldboy02.txt.gz

    -rw-r--r-- 1 root root 38 Oct 8 20:08 oldboy.txt.gz

    -rw-r--r-- 1 root root 334 Oct 8 20:31 passwd_lyx.txt.gz

    [root@oldboyedu oldboy02] #

    壓縮目錄(-vr)

    [root@oldboyedu oldboy02] # gzip -vr /oldboy01 壓縮目錄.使用遞歸r

    /oldboy01/aa/aa.txt:     0.0% -- replaced with /oldboy01/aa/aa.txt.gz

    /oldboy01/oldboy01.txt:    -22.2% -- replaced with /oldboy01/oldboy01.txt.gz

    /oldboy01/oldboy02.txt:    -22.2% -- replaced with /oldboy01/oldboy02.txt.gz

    /oldboy01/oldboy.txt:    -28.6% -- replaced with /oldboy01/oldboy.txt.gz

    /oldboy01/passwd_lyx.txt:     54.0% -- replaced with /oldboy01/passwd_lyx.txt.gz

    /oldboy01/oldboy02/oldboy.txt:    -28.6% -- replaced with /oldboy01/oldboy02/oldboy.txt.gz

    /oldboy01/oldboy02/oldboy01.txt:    -22.2% -- replaced with /oldboy01/oldboy02/oldboy01.txt.gz

    /oldboy01/oldboy02/oldboy02.txt:    -22.2% -- replaced with /oldboy01/oldboy02/oldboy02.txt.gz

    /oldboy01/oldboy02/passwd_lyx.txt:     54.0% -- replaced with /oldboy01/oldboy02/passwd_lyx.txt.gz

    /oldboy01/oldboy02/oldboy.zip:     41.8% -- replaced with /oldboy01/oldboy02/oldboy.zip.gz

    /oldboy01/oldboy02.zip:     67.7% -- replaced with /oldboy01/oldboy02.zip.gz

    [root@oldboyedu oldboy02] # ll /oldboy01 查看oldboy01里面的內容都為后綴*.gz的文件

    total 20

    -rw-r--r-- 1 root root 42 Oct 8 20:08 oldboy01.txt.gz

    -rw-r--r-- 1 root root 42 Oct 8 20:08 oldboy02.txt.gz

    -rw-r--r-- 1 root root 773 Oct 9 17:56 oldboy02.zip.gz

    -rw-r--r-- 1 root root 38 Oct 8 20:08 oldboy.txt.gz

    -rw-r--r-- 1 root root 334 Oct 8 20:31 passwd_lyx.txt.gz

    查看壓縮的文件(-l)

    [root@oldboyedu oldboy02] # gzip -l /oldboy01/*

    gzip: /oldboy01/aa is a directory -- ignored

    compressed uncompressed ratio uncompressed_name

    42 9 -22.2% /oldboy01/oldboy01.txt

    gzip: /oldboy01/oldboy02 is a directory -- ignored

    42 9 -22.2% /oldboy01/oldboy02.txt

    773 2296 67.7% /oldboy01/oldboy02.zip

    38 7 -28.6% /oldboy01/oldboy.txt

    334 654 54.0% /oldboy01/passwd_lyx.txt

    1229 2975 59.8% (totals)

    [root@oldboyedu oldboy02] #

    解壓文件(-dv)

    [root@oldboyedu oldboy02] # gzip -dv *

    oldboy01.txt.gz:    -22.2% -- replaced with oldboy01.txt

    oldboy02.txt.gz:    -22.2% -- replaced with oldboy02.txt

    oldboy.txt.gz:    -28.6% -- replaced with oldboy.txt

    passwd_lyx.txt.gz:     54.0% -- replaced with passwd_lyx.txt

    [root@oldboyedu oldboy02] # ll

    total 16

    -rw-r--r-- 1 root root 9 Oct 8 20:08 oldboy01.txt

    -rw-r--r-- 1 root root 9 Oct 8 20:08 oldboy02.txt

    -rw-r--r-- 1 root root 7 Oct 8 20:08 oldboy.txt

    -rw-r--r-- 1 root root 654 Oct 8 20:31 passwd_lyx.txt

    [root@oldboyedu oldboy02] #

    解壓目錄(-drv)

    [root@oldboyedu oldboy02] # gzip -dvr /oldboy01

    /oldboy01/aa/aa.txt.gz:     0.0% -- replaced with /oldboy01/aa/aa.txt

    /oldboy01/oldboy02/oldboy.txt.gz:    -28.6% -- replaced with /oldboy01/oldboy02/oldboy.txt

    /oldboy01/oldboy02/oldboy01.txt.gz:    -22.2% -- replaced with /oldboy01/oldboy02/oldboy01.txt

    /oldboy01/oldboy02/oldboy02.txt.gz:    -22.2% -- replaced with /oldboy01/oldboy02/oldboy02.txt

    /oldboy01/oldboy02/passwd_lyx.txt.gz:     54.0% -- replaced with /oldboy01/oldboy02/passwd_lyx.txt

    /oldboy01/oldboy02/oldboy.zip.gz:     41.8% -- replaced with /oldboy01/oldboy02/oldboy.zip

    /oldboy01/oldboy01.txt.gz:    -22.2% -- replaced with /oldboy01/oldboy01.txt

    /oldboy01/oldboy02.txt.gz:    -22.2% -- replaced with /oldboy01/oldboy02.txt

    /oldboy01/oldboy.txt.gz:    -28.6% -- replaced with /oldboy01/oldboy.txt

    /oldboy01/passwd_lyx.txt.gz:     54.0% -- replaced with /oldboy01/passwd_lyx.txt

    /oldboy01/oldboy02.zip.gz:     67.7% -- replaced with /oldboy01/oldboy02.zip

    [root@oldboyedu oldboy02] #

    1.16.4 zip

    打包為后綴為.zip的文件

    [root@oldboyedu oldboy01] # zip oldboy02.zip *

    adding: aa/ (stored 0%)

    adding: oldboy01.txt (stored 0%)

    adding: oldboy02/ (stored 0%)

    adding: oldboy02.txt (stored 0%)

    adding: oldboy.txt (stored 0%)

    adding: passwd_lyx.txt (deflated 54%)

    [root@oldboyedu oldboy02] # ll

    total 20

    -rw-r--r-- 1 root root 9 Oct 8 20:08 oldboy01.txt

    -rw-r--r-- 1 root root 9 Oct 8 20:08 oldboy02.txt

    -rw-r--r-- 1 root root 7 Oct 8 20:08 oldboy.txt

    -rw-r--r-- 1 root root 956 Oct 9 17:48 oldboy.zip

    -rw-r--r-- 1 root root 654 Oct 8 20:31 passwd_lyx.txt

    [root@oldboyedu oldboy02] #

    打包目錄需要加r進行遍歷打包

    錯誤的操作

    [root@oldboyedu oldboy01] # zip oldboy02.zip /oldboy02 打包只把目錄本身打包進去,並未將目錄里面的

    文件打包進去

    adding: oldboy02/ (stored 0%)

    [root@oldboyedu oldboy01] # unzip oldboy02.zip

    Archive: oldboy02.zip

    creating: oldboy02/

    [root@oldboyedu oldboy01] #

    正確的操作

    [root@oldboyedu oldboy01] # zip -r oldboy02.zip /oldboy02 打包已經將目錄里面的內容都已經遍歷打包

                                                 進去

    adding: oldboy02/ (stored 0%)

    adding: oldboy02/oldboy.txt (stored 0%)

    adding: oldboy02/oldboy01.txt (stored 0%)

    adding: oldboy02/oldboy02.txt (stored 0%)

    adding: oldboy02/passwd_lyx.txt (deflated 54%)

    adding: oldboy02/oldboy.zip (stored 0%)

    [root@oldboyedu oldboy01] # unzip oldboy02.zip

    Archive: oldboy02.zip

    extracting: oldboy02/oldboy.txt

    extracting: oldboy02/oldboy01.txt

    extracting: oldboy02/oldboy02.txt

    inflating: oldboy02/passwd_lyx.txt


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM