雲計算Linux檔案查詢和壓縮乾貨

2021-10-03 05:43:43 字數 1765 閱讀 2532

雲計算乾貨

linux系統配置及服務管理檔案查詢

#檔案查詢 ## 簡介

which :命令查詢

find: 檔案查詢,針對檔名

locate:檔案查詢,依賴資料庫

##一、命令檔案查詢

##一、查詢ls 命令的位置

# which ls //從path環境變數

或者# whereis vim

##二、任意檔案

find

語法find [path…] [options] [expression] [action]

命令 路徑 選項 表示式 動作

1按檔名:

[root@qianfeng ~]# find /etc -name 「hosts」

[root@qianfeng ~]# find /etc -iname 「hosts」 find /etc -iname 「hosts」 -i忽略大小寫 i可以忽略大小寫來查詢

[root@qianfeng ~]# find /etc -iname 「hos*」 心中有愛(i),什麼都找得到

結果輸出 /etc/hosts 檔案查詢成功

2按檔案大小:

[root@qianfeng ~]# find /etc -size +5m 檔案》5m 這裡「size」是大小意思

[root@qianfeng ~]# find /etc -size 5m 檔案=5m

[root@qianfeng ~]# find /etc -size -5m 檔案<5m

7找到後處理的動作 actions:

找到後刪除

# find /etc -name 「qwer.txt」 -delete

找到後複製

# find /etc -name 「ifcfg*」 -ok cp -rvf {} /tmp ; cp -rvf {} /tmp 對比cp /etc/passwd /tmp/etc1

找到的檔案 連線符 前面找到的檔案 結束符

檔案打包及壓縮

tar命令是unix/linux系統中備份檔案的可靠方法,

幾乎可以工作於任何環境中,它的使用許可權是所有使用者。

建議針對目錄

打包,壓縮

語法:tar 選項 壓縮包名稱 原始檔

打包,壓縮

# tar -cf etc.tar /etc

# tar -czf etc-gzip.tar.gz /etc/ //z是gzip

# tar -cjf etc-bzip.tar.bz /etc/ //j是bzip

# tar -cjf etc-xzip.tar.xz /etc/ //j是xzip

觀察三個包的體積。

# ll -h etc*

-rw-r–r--. 1 root root 11m 10月 14 10:07 etc-gzip.tar.gz

-rw-r–r--. 1 root root 8.9m 10月 14 10:08 etc-bzip.tar.bz

-rw-r–r--. 1 root root 7.6m 10月 14 10:08 etc-xzip.tar.xz

壓縮速度和壓縮體積成反比。

解壓,解包

檢視,並沒有解壓

# tar -tf etc.tar //t檢視f檔名

解壓縮# tar xf etc3.tar.xz

# tar -xvf etc2.tar.bz2 -c /tmp //-c重定向到//tmp目錄

檔案查詢和壓縮

1 查詢 var目錄下屬主為root,且屬組為mail的所有檔案 2 查詢 var目錄下不屬於root lp gdm的所有檔案 3 查詢 var目錄下最近一周內其內容修改過,同時屬主不為root,也不是postfix的檔案 4 查詢當前系統上沒有屬主或屬組,且最近乙個週內曾被訪問過的檔案 5 查詢 ...

檔案查詢和壓縮 壓縮 解壓 歸檔

歸檔打包 root centos7 root2018 07 31 tar cpvf data.tar data tar removing leading from member names data data root2018 07 26 root centos7 root2018 07 31 ta...

linux 檔案管理 9 檔案查詢和壓縮

locate sh locate i sh 不區分大小寫 locate n sh 顯示前幾個 locate r sh 正則 只搜尋data目錄本身 find data maxdepth 1 find data depth 先處理檔案再處理目錄 find data name test find dat...