day 11特殊字符,find,打包

Day11


作者:翟玉龍

歸檔:課堂筆記

2019/3/14

快捷鍵:

Ctrl? + 1??? 標(biāo)題1

Ctrl? + 2??? 標(biāo)題2

Ctrl? + 3??? 標(biāo)題3

Ctrl? + 4??? 實(shí)例

Ctrl? + 5??? 程序代碼

Ctrl? + 6??? 正文

格式說(shuō)明:

藍(lán)色字體:注釋

黃色背景:重要

綠色背景:注意

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

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

聯(lián)系方式:

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

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

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

官方網(wǎng)站:

http://www.oldboyedu.com?

目錄

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

第1章 課堂思想... 1

1.1 如何提升記憶力... 1

第2章... 1

2.1 符號(hào)鏈接文件... 1

2.1.1 鏈接... 1

2.2 字符(character)/塊(block)設(shè)備文件... 1

2.3 套接口文件... 2

2.4 Which. 2

2.5 重點(diǎn)? $path. 3

2.6 Whereis 顯示命令,源碼及說(shuō)明文檔全路徑... 3

2.7 Locate. 3

2.8 重點(diǎn)Find 查找目錄下的文件... 4

2.8.1 按文件類型查找 -type. 4

2.8.2 -o 取并集... 5

2.8.3 -exec 對(duì)查找的結(jié)果再處理... 6

2.8.4 按修改時(shí)間查找?? -mtime. 6

2.9 Xargs?? 分組... 7

第3章 特殊字符... 8

3.1 .??? 當(dāng)前目錄... 8

3.2 ..? 上一級(jí)目錄... 8

3.3 -??? 上一次所在目錄... 8

3.4 ~??? 家目錄... 8

3.5 \???? 轉(zhuǎn)義字符... 8

3.6 *??? 所有字符... 8

3.7 !?? ?取反... 8

3.8 |?? 管道... 8

3.8.1 把前面的命令的處理結(jié)果通過(guò)管道送到后面這個(gè)命令進(jìn)行再處理... 8

.. 8

3.9 Date??? 顯示系統(tǒng)時(shí)間和日期... 10

3.10 Tar? 打包壓縮... 11






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

[if !supportLists]1.1 [endif]如何提升記憶力


[if !supportLists]第2章 [endif]?

[if !supportLists]2.1 [endif]符號(hào)鏈接文件

[if !supportLists]2.1.1 [endif]鏈接

以l開3頭的是軟鏈接,他相當(dāng)于一個(gè)快捷方式,進(jìn)入目標(biāo)程序的一個(gè)入口。

刪掉軟鏈接對(duì)原文件不影響。

Ln? -s??? soft創(chuàng)建軟鏈接

[if !supportLists]2.2 [endif]字符(character)/塊(block)設(shè)備文件

以C開頭的就是字符設(shè)備?貓,等串口設(shè)備。

以b開頭的就是塊設(shè)備。硬盤,光驅(qū)等都屬于塊設(shè)備。

[if !vml]

[endif]

創(chuàng)建字符設(shè)備:

[if !vml]

[endif]

創(chuàng)建塊設(shè)備:

[if !vml]

[endif]

[if !supportLists]2.3[endif]??套接口文件

以s開頭.sock文件也是一類特殊的文件,這類文件通常用在網(wǎng)絡(luò)之間,進(jìn)行數(shù)據(jù)連接,如,我們可以啟動(dòng)一個(gè)程序來(lái)監(jiān)聽客戶端


[if !vml]

[endif]

[if !supportLists]2.4 [endif]Which

查命令所在的路徑。

[if !vml]

[endif]

[if !supportLists]2.5 [endif]重點(diǎn)?$path

?命令行執(zhí)行命令會(huì)從path對(duì)應(yīng)的路徑中查找命令,

Path 對(duì)應(yīng)的路徑中沒有這個(gè)命令就會(huì)報(bào)command。

自定義命令:

[if !vml]

[endif]

[if !supportLists]2.6 [endif]Whereis 顯示命令,源碼及說(shuō)明文檔全路徑

Whereis -b?? 只顯示二進(jìn)制命令

[if !supportLists]2.7 [endif]Locate

快速定位文件路徑

查找文件


[if !vml]

[endif]

查一個(gè)安裝包下載路徑

[if !vml]

[endif]用yum直接安裝


[if !supportLists]2.8 [endif]重點(diǎn)Find 查找目錄下的文件

查找原理:磁盤遍歷,速度慢,

準(zhǔn)確查找和模糊查找。模糊查找加*

[root@zyl666?18:26:27?? /]# find / -name "小澤瑪利亞"

/tmp/小澤瑪利亞

[root@zyl666?18:26:38?? /]# find / -name "小*"

/tmp/小澤瑪利亞

/tmp/小澤瑪利亞/小澤瑪利亞.txt

[if !supportLists]2.8.1 [endif]按文件類型查找 -type

?-type f??查找文本

-type d?查找目錄

文件類型詳解:

????????????? File is of type c:

? 塊文件??????? b?????block (buffered) special

? 字符文件??????????? c????? character (unbuffered) special

?? 目錄文件?????????? d????? directory

??????????? p????? named pipe (FIFO)

?文本文件???????????? f????? regular file

? 軟鏈接?????? ?????l?????symbolic link; this is never true if the -L option or the -followoption? is? in? effect,

???????????????????? unless? the symbolic link is broken.? If you want to search for symbolic links when-L is

???????????????????? in effect, use -xtype.

[if !supportLists]2.8.2 [endif]-o 取并集

[if !vml]

[endif]


不加參數(shù)相當(dāng)于取交集

如果取并集即或者用-o分割查找的項(xiàng)

-a? and

-o? or

!?取反



!在哪里就對(duì)那里后邊的值進(jìn)行取反

??? [if !vml]

[endif][root@oldboyedu?/data]#?touch?oldboy{1..10}.txt

[root@oldboyedu?/data]#?ls

oldboy10.txt??oldboy2.txt??oldboy4.txt??oldboy6.txt??oldboy8.txt

oldboy1.txt???oldboy3.txt??oldboy5.txt??oldboy7.txt??oldboy9.txt

[root@oldboyedu?/data]#?find?/data?-type?f

/data/oldboy1.txt

/data/oldboy2.txt

/data/oldboy3.txt

/data/oldboy4.txt

/data/oldboy5.txt

/data/oldboy6.txt

/data/oldboy7.txt

/data/oldboy8.txt

/data/oldboy9.txt

/data/oldboy10.txt

[root@oldboyedu?/data]#?find?/data?!?-type?f

/data

[root@oldboyedu?/data]#?mkdir?{a..d}

[root@oldboyedu?/data]#?find?/data?!?-type?f

/data

/data/a

/data/b

/data/c

/data/d



[if !supportLists]2.8.3 [endif]-exec 對(duì)查找的結(jié)果再處理

[if !vml]

[endif]

\轉(zhuǎn)義,;必須要有的

[if !vml]

[endif]


[if !vml]

[endif]

[if !supportLists]2.8.4 [endif]按修改時(shí)間查找??-mtime?

-mtime +3 三天以前修改的文件????=3? 第三天修改的文件????-3前三天修改的文件

[if !vml]

[endif]

[if !supportLists]2.9[endif]?Xargs?? 分組

-n?? n代表幾個(gè)一組

-I?? 前面找到的內(nèi)容然后放到{}里面,{}代表前面所得數(shù)據(jù)

-d 指定分隔符,如果不指定,默認(rèn)空格

[if !supportLists]第3章 [endif]特殊字符

[if !supportLists]3.1[endif]???.??? 當(dāng)前目錄

[if !supportLists]3.2[endif]???..? 上一級(jí)目錄

[if !supportLists]3.3[endif]???-??? 上一次所在目錄

[if !supportLists]3.4[endif]???~??? 家目錄

[if !supportLists]3.5[endif]???\???? 轉(zhuǎn)義字符

[if !supportLists]3.6[endif]???*??? 所有字符

[if !supportLists]3.7[endif]??!??? 取反

[if !supportLists]3.8[endif]???|?? 管道

[if !supportLists]3.8.1 [endif]把前面的命令的處理結(jié)果通過(guò)管道送到后面這個(gè)命令進(jìn)行再處理

[if !vml]

[endif]

(能不用管道就不用管道)

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

a.b.c.d

[root@oldboyedu?/data]#?echo?"Oldboy"?>test.txt

[root@oldboyedu?/data]#?echo?"Oldgirl"?>>test.txt

[root@oldboyedu?/data]#?echo?"Oldboedu"?>>test.txt

[root@oldboyedu?/data]#?echo?"Oldboyedu"?>>test.txt

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

Oldboy

Oldgirl

Oldboedu

Oldboyedu

[root@oldboyedu?/data]#?cat?test.txt|grep?"boy"

Oldboy

Oldboyedu

[root@oldboyedu?/data]#?grep?"boy"?test.txt

Oldboy

Oldboyedu



對(duì)比??管道和exec

[root@oldboyedu?/data]#?find?/data?-type?f?-name?"oldboy*"?-mtime?-7?-exec?ls?-l?{}?\;

-rw-r--r--.?1?root?root?0?Mar?14?10:39?/data/oldboy1.txt

-rw-r--r--.?1?root?root?0?Mar?14?10:39?/data/oldboy2.txt

-rw-r--r--.?1?root?root?0?Mar?14?10:39?/data/oldboy3.txt

-rw-r--r--.?1?root?root?0?Mar?14?10:39?/data/oldboy4.txt

-rw-r--r--.?1?root?root?0?Mar?14?10:39?/data/oldboy5.txt

-rw-r--r--.?1?root?root?0?Mar?14?10:39?/data/oldboy6.txt

-rw-r--r--.?1?root?root?0?Mar?14?10:39?/data/oldboy7.txt

-rw-r--r--.?1?root?root?0?Mar?14?10:39?/data/oldboy8.txt

-rw-r--r--.?1?root?root?0?Mar?14?10:39?/data/oldboy9.txt

-rw-r--r--.?1?root?root?0?Mar?14?10:39?/data/oldboy10.txt

[root@oldboyedu?/data]#?find?/data?-type?f?-name?"oldboy*"?-mtime?-7|xargs?ls?-l

-rw-r--r--.?1?root?root?0?Mar?14?10:39?/data/oldboy10.txt

-rw-r--r--.?1?root?root?0?Mar?14?10:39?/data/oldboy1.txt

-rw-r--r--.?1?root?root?0?Mar?14?10:39?/data/oldboy2.txt

-rw-r--r--.?1?root?root?0?Mar?14?10:39?/data/oldboy3.txt


本質(zhì)區(qū)別:

find?/data?-type?f?-exec?rm?-f?{}?\;

相當(dāng)于

rm?-f?oldboy1.txt

rm?-f?oldboy2.txt

rm?-f?oldboy3.txt

效率低。

find?/data?-type?f|xargs?rm?-f

只是一條命令

rm?-f?oldboy1.txt?oldboy2.txt?oldboy3.txt

[root@oldboyedu?/data]#?find?/data?-type?f|xargs?-i?cp?{}?/opt

[root@oldboyedu?/data]#?ls?/opt/

oldboy1.txt??oldboy2.txt??oldboy3.txt??oldboy4.txt??oldboy5.txt


[if !supportLists]3.9 [endif]Date??? 顯示系統(tǒng)時(shí)間和日期

[if !vml]

[endif]



[root@oldboyedu?/data]#?date?-s?"2020/10/1?00:00:00"

Thu?Oct??1?00:00:00?CST?2020

[root@oldboyedu?/data]#?date

Thu?Oct??1?00:00:03?CST?2020

[root@oldboyedu?/data]#?clock?-w

[root@oldboyedu?/data]#?date?+%F

2020-10-01

[root@oldboyedu?/data]#?date?+%Y???#year

2020

[root@oldboyedu?/data]#?date?+%y???#year

20

[root@oldboyedu?/data]#?date?+%m???#month

10

[root@oldboyedu?/data]#?date?+%d???#day

01

[root@oldboyedu?/data]#?date?+%H???#hour

時(shí)

00

[root@oldboyedu?/data]#?date?+%M#minute

02

[root@oldboyedu?/data]#?date?+%S???#second

46

[root@oldboyedu?/data]#?date?+%Y-%m-%d

2020-10-01

[root@oldboyedu?/data]#?date?+%F

2020-10-01

[root@oldboyedu?/data]#?date?+%H:%M:%S

00:04:29

[root@oldboyedu?/data]#?date

Thu?Oct??1?00:04:38?CST?2020

[root@oldboyedu?/data]#?date?+%F?-d?"-1day"

2020-09-30

[root@oldboyedu?/data]#?date?+%F?-d?"+1day"

2020-10-02

[root@oldboyedu?/data]#?date?+%F?-d?"+1month"

2020-11-01

[root@oldboyedu?/data]#?date?+%F?-d?"+1Y"

date:?invalid?date?‘+1Y’

[root@oldboyedu?/data]#?date?+%F?-d?"+1year"

2021-10-01

-

過(guò)去

+

未來(lái)

[root@oldboyedu?/data]#?date?+"%Y-%m-%d?%H:%M:%S"

2020-10-01?00:09:36

[root@oldboyedu?/data]#?date?+"%F?%T"

2020-10-01?00:09:39



[if !supportLists]3.10[endif]????? Tar? 打包壓縮

文件壓縮,大小會(huì)降低

Tar?

打包

語(yǔ)法tar

參數(shù):?框?蘋果

-z? 壓縮

-c? 創(chuàng)建

-v?輸出打包過(guò)程

-f?? 文件的打包

-h?? 跟隨軟鏈接

-t???不解壓查看內(nèi)容

-x? 解壓

Data.tar.gz?tar標(biāo)識(shí)打包,gz是gzip的標(biāo)識(shí)

Tar -zcvf data,.tar.gz ./data

Tar -tf 加打包名,查看打包內(nèi)容

指定目錄解壓

Zcvf打包

[root@zyl666?20:25:17?? /]# tar zcvf/opt/date.tar.gz ./date???? *****打包,zcf極簡(jiǎn)打包

./date/

./date/1.txt

./date/2.txt

./date/3.txt

./date/4.txt

./date/5.txt

[root@zyl666?20:26:14?? /]# tar -tf/opt/date.tar.gz??? *******不解壓查看打包內(nèi)容

./date/

./date/1.txt

./date/2.txt

./date/3.txt

./date/4.txt

./date/5.txt

Zxvf解壓?極簡(jiǎn)解壓xf

[root@zyl666?20:35:07?? /opt]# tar xfdate.tar.gz -C /tmp/???? ***極簡(jiǎn)解壓,也可以用zxvf

[root@zyl666?20:36:07?? /opt]# ls /tmp/

1.txt? vmware-root??????????????????vmware-root_6509-1681265529?vmware-root_6751-3887503186

2.txt?vmware-root_23985-4155303761?vmware-root_6521-1723667692?vmware-root_6753-3887503219

3.txt?vmware-root_6072-701138450???vmware-root_6656-3091807477?vmware-root_6759-3887372148

4.txt?vmware-root_6112-968930924???vmware-root_6699-4113932447?vmware-root_6765-3845624056

a?????vmware-root_6167-1949639613??vmware-root_6729-3854340421?vmware-root_6766-2856389284

b?????vmware-root_6375-1983194421??vmware-root_6735-3854471490? 小澤瑪利亞

c?????vmware-root_6468-701206161???vmware-root_6741-3845492958

d?????vmware-root_6471-1723667661??vmware-root_6743-3853816156

date??vmware-root_6506-734234784???vmware-root_6747-3879048919

zchf 帶軟鏈接的打包···

[if !vml]

[endif]

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

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