Linux文件管理——文件查找、打包及壓縮【CentOS】

文件指令
which :命令查找
find: 文件查找,針對文件名
locate:文件查找,依賴數據庫數據庫

which ls	  查找ls 命令的位置

locate hosts  locate查找文件hosts文件
updatedb      更新locate數據庫

find [path...] [options]  [expression] [action]
命令  路徑       選項          表達式       動做

find /etc -name     "hosts"    按照文件名查找hosts    區分大小寫
find /etc -iname     "hosts"   按照文件名查找hosts     不區分大小寫(-i忽略大小寫)
find /etc -iname      "hos*"   按照文件名查找hos開頭文件     不區分大小寫

find /etc -size        +5M     查找>5M文件   【-5M <5M文件】【5M =5M文件】


find / -maxdepth 4 -a -name  "ifcfg*"     查找名字叫「ficfg」開頭的文件,在4級目錄下

find /home -user              jack     屬主是jack的文件
find /home -group              hr      屬組是hr組的文件

find /tmp -type   f      查找/tmp下文件類型爲f的文件
f        普通文件
b        塊設備文件
d        目錄
p        管道
l        鏈接

find . -perm 644 -ls                    查找文件權限644的文件,並精確顯示權限
find . -perm  715  -print               -print表明打印出來,不加的時候默認顯示  
find . -perm  715  -ls                  - ls 表明精準權限      

find /etc -name "775*" -delete                         找到後刪除
find /etc  -name   "ifcfg*" -ok  cp -rvf {} /tmp \;    找到互複製/tmp 複製到路徑


  • 文件打包及壓縮

tar 選項 壓縮包名稱 源文件 壓縮express

tar   -cf     etc.tar   /etc                        打包
tar   -xf     etc.tar    /etc                       解壓
tar   -czvf     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* 觀察文件ide

-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
觀察大小和速度,壓縮的速度和壓縮體積成反比。ip

tar -tf  etc.tar     查看是否壓縮
tar xf etc.tar       直接解壓文件
tar -xvf etc-bzip.tar.bz -C /tmp     -C重定向解壓到/tmp目錄