四劍客第三關

liu4356發表於2024-03-14

四劍客第三關

1 find使用方法:
根據檔案大小查詢 命令:
根據檔案許可權查詢資料 :

find /etc/passwd -type f -size +10M


find /etc/passwd -perm 755



[root@master ~]# find /etc/passwd -type f -size +10M
[root@master ~]# find /etc/passwd -perm 755


2 把 abc壓縮成格式如 2020-09-29.abc.tar.gz

tar -zcf "$(date +%Y-%m-%d).abc.tar.gz" abc




[root@master ~]# cat abc
dshjfgsd
sdkfhksdf
sdkfgsdf
flksehfhes
sakhjfasjghdfas
fjnksdfsdjf



sdfjkhsdjfse
sajkefhjsegf

wenrjeshfukse
wejnrkhefghwe
rasejghfujiwebf
'fsebjfhse
ejkrgsefhe
sekfbegfe
askefseuifbwejfsekjtg
wjkerusegufhbse
sejnkrghsehjfge
tnwejfhwejfbwe
asnjefghesjkf
se'e,k



ejkrgseuiuhe


enrjsehfwe

awejkfjiwehf


sejkhrsehfw
'arnweh


serheuishfuihwe




[root@master ~]# tar -zcf "$(date +%Y-%m-%d).abc.tar.gz" abc
[root@master ~]# ls
10.txt  14.txt  18.txt                 20.txt  3.txt  7.txt  anaconda-ks.cfg        nwq1.6.sh
11.txt  15.txt  19.txt                 21.txt  4.txt  8.txt  CentOS6-Base-163.repo  profile
12.txt  16.txt  1.txt                  22.txt  5.txt  9.txt  hosts
13.txt  17.txt  2024-03-14.abc.tar.gz  2.txt   6.txt  abc    motd


3 解壓如上檔案

tar -xzf "2020=09-29.abc.tar.gz"

 tar -xzf "2024-03-14.abc.tar.gz"  -C /test  解壓到目錄


[root@master ~]# tar -xzf "2024-03-14.abc.tar.gz"  -C /test
[root@master ~]# cd /test
[root@master test]# ls
abc
[root@master test]# cat abc
dshjfgsd
sdkfhksdf
sdkfgsdf
flksehfhes
sakhjfasjghdfas
fjnksdfsdjf



sdfjkhsdjfse
sajkefhjsegf

wenrjeshfukse
wejnrkhefghwe
rasejghfujiwebf
'fsebjfhse
ejkrgsefhe
sekfbegfe
askefseuifbwejfsekjtg
wjkerusegufhbse
sejnkrghsehjfge
tnwejfhwejfbwe
asnjefghesjkf
se'e,k



ejkrgseuiuhe


enrjsehfwe

awejkfjiwehf


sejkhrsehfw
'arnweh


serheuishfuihwe






4 美元符號:$ 表達什麼:
!作用:
| 作用:
xargs作用:

$ 引用變數或命令替換
!   執行歷史記錄或邏輯非操作  通常與[]結合使用
|  前一個命令的輸出作為後一個命令的輸入

5 查詢指定資料資訊進行復制 查詢出.txt檔案,批次複製到/tmp目錄

find . -name "*.txt" |xargs cp -t /tmp
或者
find . -name "*.txt" -exec cp {} /tmp \;





[root@master ~]# touch {1..22}.txt
[root@master ~]# ls
10.txt  13.txt  16.txt  19.txt  21.txt  3.txt  6.txt  9.txt                  hosts      profile
11.txt  14.txt  17.txt  1.txt   22.txt  4.txt  7.txt  anaconda-ks.cfg        motd
12.txt  15.txt  18.txt  20.txt  2.txt   5.txt  8.txt  CentOS6-Base-163.repo  nwq1.6.sh
[root@master ~]# find . -name "*.txt" -exec cp {} /tmp \;
[root@master ~]# ls
10.txt  13.txt  16.txt  19.txt  21.txt  3.txt  6.txt  9.txt                  hosts      profile
11.txt  14.txt  17.txt  1.txt   22.txt  4.txt  7.txt  anaconda-ks.cfg        motd
12.txt  15.txt  18.txt  20.txt  2.txt   5.txt  8.txt  CentOS6-Base-163.repo  nwq1.6.sh
[root@master ~]# cd /tmp
[root@master tmp]# ls
10.txt  14.txt  18.txt  21.txt  4.txt  8.txt       yum_save_tx.2024-03-09.20-43.MjeG_P.yumtx
11.txt  15.txt  19.txt  22.txt  5.txt  9.txt
12.txt  16.txt  1.txt   2.txt   6.txt  test01.txt
13.txt  17.txt  20.txt  3.txt   7.txt  test.txt

6 查詢指定資料資訊進行移動 查詢出*.txt檔案,批次移動到/tmp目錄

find . -name "*.txt" -exec mv {} /tmp \;




[root@master ~]# touch {1..20}.txt
[root@master ~]# ls
10.txt  13.txt  16.txt  19.txt  2.txt  5.txt  8.txt            CentOS6-Base-163.repo  nwq1.6.sh   test.txt
11.txt  14.txt  17.txt  1.txt   3.txt  6.txt  9.txt            hosts                  profile
12.txt  15.txt  18.txt  20.txt  4.txt  7.txt  anaconda-ks.cfg  motd                   test01.txt
[root@master ~]# find . -name "*.txt"
./1.txt
./test.txt
./test01.txt
./2.txt
./3.txt
./4.txt
./5.txt
./6.txt
./7.txt
./8.txt
./9.txt
./10.txt
./11.txt
./12.txt
./13.txt
./14.txt
./15.txt
./16.txt
./17.txt
./18.txt
./19.txt
./20.txt
[root@master ~]# find . -name "*.txt" -exec mv {} /tmp \;

[root@master ~]# cd /tmp
[root@master tmp]# ls
10.txt  13.txt  16.txt  19.txt  2.txt  5.txt  8.txt       test.txt
11.txt  14.txt  17.txt  1.txt   3.txt  6.txt  9.txt       yum_save_tx.2024-03-09.20-43.MjeG_P.yumtx
12.txt  15.txt  18.txt  20.txt  4.txt  7.txt  test01.txt

7 將以abc開頭的行找出來?

語法  grep  "^abc"  檔名

grep "^abc" /etc/passwd



[root@master ~]# cat test01.txt 
sdjfgs
sdjkhfjksdhf


sdfjksdkfhshd
sdjfhjsgf
sdkfhksduise
jkshfhsdb
ashdfsdf
linux fsdhfsdfjsfhshdfslinux
sdjfjsdfs
askjdfasugfugsef
sensfhasgf
asekfsehf
eksheshb
abcehiehkheke
ejkrsehfuies
abcehiiegbwejthiehi


efjhehew

rjkthrkhgwe
eklrhteh

etwehut

ethkeht

ejkfekhre
ehrkefie
nrekwhwet
ekhke



ektheh



[root@master ~]# grep '^abc' test01.txt 
abcehiehkheke
abcehiiegbwejthiehi



8 將以linux結尾的行找出來?

grep 'linux$' 檔名


[root@master ~]# cat test01.txt 
sdjfgs
sdjkhfjksdhf


sdfjksdkfhshd
sdjfhjsgf
sdkfhksduise
jkshfhsdb
ashdfsdf
linux fsdhfsdfjsfhshdfslinux
sdjfjsdfs
askjdfasugfugsef
sensfhasgf
asekfsehf
eksheshb
abcehiehkheke
ejkrsehfuies
abcehiiegbwejthiehi


efjhehew

rjkthrkhgwe
eklrhteh

etwehut

ethkeht

ejkfekhre
ehrkefie
nrekwhwet
ekhke



ektheh



[root@master ~]# grep 'linux' test01.txt 
linux fsdhfsdfjsfhshdfslinux


9 將全部內容顯示,但不要顯示空行

grep -v '^$' 檔名




[root@master ~]# cat test01.txt 
sdjfgs
sdjkhfjksdhf


sdfjksdkfhshd
sdjfhjsgf
sdkfhksduise
jkshfhsdb
ashdfsdf
linux fsdhfsdfjsfhshdfslinux
sdjfjsdfs
askjdfasugfugsef
sensfhasgf
asekfsehf
eksheshb
abcehiehkheke
ejkrsehfuies
abcehiiegbwejthiehi


efjhehew

rjkthrkhgwe
eklrhteh

etwehut

ethkeht

ejkfekhre
ehrkefie
nrekwhwet
ekhke



ektheh



[root@master ~]# grep -v '^$' test01.txt 
sdjfgs
sdjkhfjksdhf
sdfjksdkfhshd
sdjfhjsgf
sdkfhksduise
jkshfhsdb
ashdfsdf
linux fsdhfsdfjsfhshdfslinux
sdjfjsdfs
askjdfasugfugsef
sensfhasgf
asekfsehf
eksheshb
abcehiehkheke
ejkrsehfuies
abcehiiegbwejthiehi
efjhehew
rjkthrkhgwe
eklrhteh
etwehut
ethkeht
ejkfekhre
ehrkefie
nrekwhwet
ekhke
ektheh

10 利用linux什麼命令真正統計目錄的大小?

du -sh /etc/passwd



[root@master ~]# du -sh /etc/passwd
8.0K	/etc/passwd


相關文章