day 10 greb 重定向

?

Day 10

?

作者:翟玉龍

歸檔:課堂筆記

2019/3/13

快捷鍵:

Ctrl + 1??? 標題1

Ctrl + 2??? 標題2

Ctrl + 3??? 標題3

Ctrl + 4??? 實例

Ctrl + 5??? 程序代碼

Ctrl + 6??? 正文

格式說明:

藍色字體:注釋

黃色背景:重要

綠色背景:注意

老男孩教育教學(xué)核心思想6重:重目標、重思路、重方法、重實踐、重習(xí)慣、重總結(jié)

學(xué)無止境,老男孩教育成就你人生的起點!

聯(lián)系方式:

網(wǎng)站運維QQ交流群:

Linux?385168604架構(gòu)師390642196

Python 29215534大數(shù)據(jù)421358633

官方網(wǎng)站:

http://www.oldboyedu.com?

目錄

學(xué)無止境,老男孩教育成就你人生的起點!... 1

第1章 課堂思想... 1

1.1 如何提升自學(xué)能力... 1

1.1.1 養(yǎng)成主動看書的習(xí)慣... 1

1.1.2 養(yǎng)成預(yù)習(xí)的習(xí)慣... 1

(工作中領(lǐng)導(dǎo)分配任務(wù),讓你去搞定的模擬)... 1

1.1.3 課堂上要積極思考,對老師提問的問題主動回答... 1

1.1.4 對老師留的課后拓展的作業(yè)要能夠完成。... 1

1.1.5 對學(xué)習(xí)的內(nèi)容要深度總結(jié)... 1

1.1.6 課后遇到不會的不要輕易問別人,要學(xué)會自己解決問題。... 1

1.1.7 提升閱讀外語的能力... 1

第2章 基本命令... 1

2.1 Tr? 替換/刪除字符... 1

2.2 Greb?? 過濾? (重要性 前三)... 2

2.2.1 Greb參數(shù)... 2

2.2.2 Greb參數(shù)的應(yīng)用... 2

第3章 重定向符號... 3

3.1 >?? 標準輸出重定向... 3

3.2 >>追加輸出重定向... 4

3.3 < 標準輸入重定向... 4

3.4 << 追加輸入重定向,箭頭方向就是數(shù)據(jù)流向... 5

3.5 2>錯誤輸出重定向箭頭方向就是數(shù)據(jù)流向,吧左邊的報錯輸入到右邊(覆蓋)... 5

3.6 2>>錯誤追加輸出重定向,箭頭方向就是數(shù)據(jù)流向,把左邊的報錯輸入到右邊(追加)... 5

3.7 如何保存替換字符后的文件... 5

3.8 <<. 5

第4章 Linux文件屬性描述... 7

4.1 文件屬性... 7

4.2 第二列詳解... 8

(1)第二列第一個字符:文件類型... 8

?

?

?

?

????????????????????????????????????????????????????????????

[if !supportLists]第1章 [endif]課堂思想

[if !supportLists]1.1 [endif]如何提升自學(xué)能力

[if !supportLists]1.1.1 [endif]養(yǎng)成主動看書的習(xí)慣

[if !supportLists]1.1.2 [endif]養(yǎng)成預(yù)習(xí)的習(xí)慣

(工作中領(lǐng)導(dǎo)分配任務(wù),讓你去搞定的模擬)

[if !supportLists]1.1.3 [endif]課堂上要積極思考,對老師提問的問題主動回答

對于不會的要主動發(fā)問

[if !supportLists]1.1.4 [endif]對老師留的課后拓展的作業(yè)要能夠完成。

[if !supportLists]1.1.5 [endif]對學(xué)習(xí)的內(nèi)容要深度總結(jié)

(思維導(dǎo)圖總結(jié),畫圖總結(jié)等等)

知識======》短時記憶======》編碼加工======》長時記憶(存儲大腦里)======》提取

[if !supportLists]1.1.6 [endif]課后遇到不會的不要輕易問別人,要學(xué)會自己解決問題。

筆記、書、搜索引擎、加一些Linux交流群、身邊的人。

[if !supportLists]1.1.7 [endif]提升閱讀外語的能力

通過計算機技術(shù)知識反向?qū)W習(xí)外語

學(xué)過的命令記錄對應(yīng)意思的英文。

Fhs目錄層次標準里去查或者man cp 看名字

?

總結(jié)100個報錯英語

[if !supportLists]第2章 [endif]基本命令

[if !supportLists]2.1[endif]?Tr? 替換/刪除字符9

(Linux里嚴格區(qū)分大小寫)

?

[root@oldgirl~]# cat test.txt

Welcome tooldboy training.

we areexcellent.

[root@oldgirl~]# tr "w" "9" < test.txt

Welcome tooldboy training.

9e areexcellent.

[root@oldgirl~]# tr w 9 < test.txt

Welcome tooldboy training.

9e areexcellent.

所有字符盡量加雙引號。

[if !supportLists]2.2 [endif]Grep?? 過濾?(重要性 前三)

※※※※※※

[if !supportLists]2.2.1 [endif]Grep參數(shù)

--color=auto?? 給篩選出來的東西上色

-v??????????? invert取反 ※※

-i??????????? ignore不區(qū)分大小寫

-n??????????? 顯示行號(對過濾的內(nèi)容顯示它在原文件中的行號)※※

-w?????????? 按單詞為單位過濾※※

-o??????????? 只顯示過濾的內(nèi)容

-E??????????? 擴展的grep,即egrep※※

[if !supportLists]2.2.2 [endif]Grep參數(shù)的應(yīng)用

-i 的應(yīng)用

[root@oldgirl?~]#?cat?test.txt??

Welcome?to?oldboy?training.

we?are?excellent.

[root@oldgirl?~]#?grep?-i?"w"?test.txt

Welcome?to?oldboy?training.

we?are?excellent.

[root@oldgirl?~]#?grep??"w"?test.txt

we?are?excellent.

[root@oldgirl?~]#?grep?-iv?"w"?test.tx

-w的應(yīng)用

?[root@oldgirl ~]# cat test.txt

Welcome tooldboy training.

we areexcellent.

oldboy1

[root@oldgirl~]# grep -w "oldboy" test.txt

Welcome tooldboy training.

[root@oldgirl~]# grep? "oldboy" test.txt

Welcome tooldboy training.

oldboy1

[root@oldgirl~]# grep -w "oldboy" test.txt

Welcome tooldboy training.

-o 的應(yīng)用

[root@oldgirl?~]#?grep?"oldboy"?test.txt

Welcome?to?oldboy?training.

oldboy1

[root@oldgirl?~]#?grep?-o?"oldboy"?test.txt

oldboy

oldboy

?

-E 的應(yīng)用

[root@zyl666? 18:11:09??~]# grep -E? "are|to"1.txt

Welcome tooldboy training.

we areexcellent.~????????????????????????????????????????????????????????????????????????????????????????????

[root@zyl666? 18:13:49??~]# egrep "are|to" 1.txt

Welcome tooldboy training.

we areexcellent.~?

egrep

他可以實現(xiàn)grep所不具備的功能,例如和

[if !supportLists]第3章 [endif]重定向符號

[if !supportLists]3.1[endif]??>?? 標準輸出重定向

箭頭方向就是數(shù)據(jù)流向,會把左邊的數(shù)據(jù)流向到右邊,會清空右邊之前的數(shù)據(jù)

[root@zyl666? 18:23:08??/data]# cat oldboy.txt

i love stud

i love sd

i love sd

[root@zyl666? 18:23:10??/data]# cat oldboy.txt

i love stud

i love sd

i love sd

[root@zyl666? 18:25:27??/data]# echo "zyl66666" >oldboy.txt

[root@zyl666? 18:25:41??/data]# cat oldboy.txt

zyl66666

[root@zyl666? 18:25:43??/data]#

清空前備份,清空文件

?

[if !supportLists]3.2 [endif]>>追加輸出重定向

???? 內(nèi)容追加到文件尾部

[root@zyl666? 18:22:45??/data]# cat oldboy.txt

i love stud

[root@zyl666? 18:22:48??/data]# echo "i love sd">>oldboy.txt

[root@zyl666? 18:23:02??/data]# echo "i love sd" >>oldboy.txt

[root@zyl666? 18:23:08??/data]# cat oldboy.txt

i love stud

i love sd

i love sd

[if !supportLists]3.3 [endif]< 標準輸入重定向

箭頭方向就是數(shù)據(jù)流向

[if !supportLists]3.4 [endif]<< 追加輸入重定向,箭頭方向就是數(shù)據(jù)流向

[if !supportLists]3.5[endif]??2>錯誤輸出重定向箭頭方向就是數(shù)據(jù)流向,吧左邊的報錯輸入到右邊(覆蓋)

[if !supportLists]3.6[endif]??2>>錯誤追加輸出重定向,箭頭方向就是數(shù)據(jù)流向,把左邊的報錯輸入到右邊(追加)

固定定義

數(shù)字0 標準輸入standardinput??????? <? 相當于0<?? 0<<??

數(shù)字1 標準輸出standardoutput??????>? 相當于1>?? 1>>

數(shù)字2 錯誤輸出erroroutput????? ?????2>錯誤輸出重定向 接收錯誤信息

[root@oldboyedu?~]#?echo?"I?am?studying?linux."?1>/data/oldboy.txt

[root@oldboyedu?~]#?cat?/data/oldboy.txt

I?am?studying?linux.

[root@oldboyedu?~]#?echo?"I?am?studying?linux.."?1>>/data/oldboy.txt

[root@oldboyedu?~]#?cat?/data/oldboy.txt

I?am?studying?linux.

I?am?studying?linux..

[root@oldboyedu?~]#?tr?"am"?"01"?0

I?01?studying?linux.

I?01?studying?linux..

?

?

[if !supportLists]3.7 [endif]如何保存替換字符后的文件

?

[if !supportLists]3.8[endif]???<<

EOF

##成對出現(xiàn),后面這個頂格

用法:

Cat <

I anoldboy

EOF

Cat>oldboy.txt<

Iamoldboy

EOF

?

?

?

?

????????????? 考題:已知文件test.txt內(nèi)容為:

test

liyao

oldboy

請給出再屏幕輸出test.txt內(nèi)容時,不包含oldboy字符串的命令

[root@oldboyedu?~]#?grep?-v?"oldboy"?test.txt

test

liyao

[root@oldboyedu?~]#?head?-2?test.txt

test

liyao

[root@oldboyedu?~]#?grep?-E?"test|liyao"?test.txt

test

liyao

[if !supportLists]第4章 [endif]Linux文件屬性描述

[if !supportLists]4.1 [endif]文件屬性

文件的大小,時間,類型,權(quán)限,屬主

索引節(jié)點:文件的唯一標識

身份證:人的唯一標識

進程號:進程的唯一標識

[root@oldboyedu?~]#?ls?-lhi

total?24K

33631870?-rw-r--r--.?1?root?root???4?Mar?13?11:29?a.txt

33631871?-rw-r--r--.?1?root?root??30?Mar?13?11:28?b.txt

16777289?drwxr-xr-x.?2?root?root??64?Mar??7?11:57?data1

33631866?-rw-r--r--.?1?root?root?712?Mar?11?15:58?grep.txt

33631863?-rw-r--r--.?1?root?root??12?Mar?13?11:23?oldboy.txt

16964029?drwxr-xr-x.?2?root?root???6?Mar??7?10:56?test

33631865?-rw-r--r--.?1?root?root??24?Mar?13?11:46?test.txt

33631864?-rw-r--r--.?1?root?root??54?Mar?13?10:26?test.txt.ori

1??????????2????????3???4????5????6??7???8???9????10

共10列第一列:inode索引節(jié)點編號(相當于人的身份證、家庭住址,全國唯一);系統(tǒng)讀取文件時首先通過文件名找到inode號碼,然后才能讀取到文件內(nèi)容。第二列:文件類型及權(quán)限。這一列共11個字符,其中第一個字符為文件類型,隨后的9個字符為文件的對應(yīng)權(quán)限,最后一個字符點號“.”是和selinux有關(guān)的一個標識;

第三列:?硬連接數(shù)第四列:?屬主:文件的擁有者,用戶第五列:?屬組:文件屬于的組,用戶組第六列:?大小第七列:?月份第八列:??日第九列:?時間第十列:?文件名

[if !supportLists]4.2 [endif]第二列詳解

1)第二列第一個字符:文件類型

一切皆文件

[if !supportLists]-???[endif]普通文件

圖片,視頻,文檔等等都是文件

Windows用擴展名區(qū)分文件,Linux里有自己的文件類型,Linux的擴展名兼容Windows,方便區(qū)分文件

?

創(chuàng)建文件:touch vim echo cat

拷貝:cp

刪除:rm

移動:mv

Linux中的三種文件類型

[if !supportLists]1.? [endif]純文本文件:字符數(shù)字等信息

[if !supportLists]2.? [endif]數(shù)據(jù)文件:存放命令收集的信息

[if !supportLists]3.? [endif]二進制文件:可執(zhí)行的命令

?

(2)d 目錄(directory

生成:mkdir -p??

復(fù)制:cp -a /-r

刪除:rm -fr

區(qū)分:開頭為d的就是目錄,

????? 顏色為藍色的是目錄

Ls -p區(qū)分目錄和文件

?

UID

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

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