歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> linux下查找及壓縮命令

linux下查找及壓縮命令

日期:2017/3/1 17:15:41   编辑:關於Linux

linux下查找及壓縮命令 一、which 查找的是命令,比如: jerry@why :/$ which ls /bin/ls jerry@why :/$ www.2cto.com 二、whereis 跟which差不多,比which多一點,會顯示命令幫助在哪裡: jerry@why :/$ whereis ls ls: /bin/ls /usr/share/man/man1/ls.1.gz jerry@why :/$ 三、locate 查找所有的文件夾的文件,效率特別高 updatedb linux下的計劃任務:/etc/cron.daily/ 四、find find / -name a.txt find / -name "*newfile*" 對應locate:locate -r ".*newfile.*"用的是正則表達式,.*代表任意多個任意字符。 效率低,功能最強,一個例子: jerry@why:/$ find /etc -name "*network*" find: `/etc/cups/ssl': 權限不夠 /etc/init.d/network-interface-security /etc/init.d/network-interface-container /etc/init.d/network-interface /etc/init.d/network-manager /etc/init.d/networking /etc/rc0.d/S35networking /etc/rc6.d/S35networking /etc/apparmor/init/network-interface-security find: `/etc/ssl/private': 權限不夠 /etc/network www.2cto.com /etc/bluetooth/network.conf /etc/networks /etc/init/network-manager.conf /etc/init/networking.conf /etc/init/network-interface.conf /etc/init/network-interface-container.conf /etc/init/network-interface-security.conf /etc/modprobe.d/blacklist-rare-network.conf /etc/sysctl.d/10-network-security.conf jerry@why:/$ 查找完後面還可以跟命令: root@why:~# find /home "*txt*" -ok rm file {} /; 可是我在unbuntu下為什麼提示: find: 缺少“-ok”參數(知道什麼原因了,看著裡: jerry@why:~/linux-jerryz$ find /home/jerry/ -name history.txt -exec cat {} \; 打錯了slush; ) 另一個例子: www.2cto.com root@why:~# find /home/jerry/下載/ -user jerry -a -group jerry -ls 1177359 4 drwxr-xr-x 2 jerry jerry 4096 7月 26 01:53 /home/jerry/\344\270\213\350\275\275/ root@why:~# 其中-a為and(-o為or);-user是查找擁有者為jerry,-group是查找擁有組為jerry; find / -perm -777 -type d -ls ———————————————————————————————————————————— 五、grep 搜索包含指定內容的文件! (這是我一直想找的命令!) e.g.: grep -R jerry /etc(在/etc下所有目錄查找,內容含有jerry的文件(參數-R代表所有文件)) 如果只想列出文件名: www.2cto.com grep -R -l jerry /etc(-l只列出文件名) 01 root@why:~# grep -R -l jerry /etc 02 /etc/passwd 03 /etc/shadow- 04 grep: /etc/alternatives/ghostscript-current/Resource/CMap/Hojo-EUC-H: 沒有那個文件或目錄 05 grep: /etc/alternatives/ghostscript-current/Resource/CMap/UniHojo-UTF16-H: 沒有那個文件或目錄 06 grep: /etc/alternatives/ghostscript-current/Resource/CMap/Hojo-H: 沒有那個文件或目錄 07 grep: /etc/alternatives/ghostscript-current/Resource/CMap/Adobe-Japan2-0: 沒有那個文件或目錄 08 grep: /etc/alternatives/ghostscript-current/Resource/CMap/UniHojo-UTF8-V: 沒有那個文件或目錄 09 grep: /etc/alternatives/ghostscript-current/Resource/CMap/UniHojo-UCS2-V: 沒有那個文件或目錄 10 grep: /etc/alternatives/ghostscript-current/Resource/CMap/UniHojo-UCS2-H: 沒有那個文件或目錄 11 grep: /etc/alternatives/ghostscript-current/Resource/CMap/UniHojo-UTF32-V: 沒有那個文件或目錄 12 grep: /etc/alternatives/ghostscript-current/Resource/CMap/Hojo-V: 沒有那個文件或目錄 13 grep: /etc/alternatives/ghostscript-current/Resource/CMap/UniHojo-UTF32-H: 沒有那個文件或目錄 14 www.2cto.com grep: /etc/alternatives/ghostscript-current/Resource/CMap/UniHojo-UTF16-V: 沒有那個文件或目錄 15 grep: /etc/alternatives/ghostscript-current/Resource/CMap/UniHojo-UTF8-H: 沒有那個文件或目錄 16 grep: /etc/alternatives/ghostscript-current/Resource/CMap/Hojo-EUC-V: 沒有那個文件或目錄 17 /etc/alternatives/ghostscript-current/lib/ps2ascii.ps 18 /etc/gshadow- 19 /etc/group 20 /etc/shadow 21 /etc/mtab 22 grep: /etc/blkid.tab: 沒有那個文件或目錄 23 /etc/passwd- 24 /etc/group- 25 /etc/gshadow 26 root@why:~# 27 _________________________________________________________________________________________________ 28 ############################################################################################ 29 ############################################################################################ 30 www.2cto.com 下面我們看打包與壓縮命令: 31 打包與壓縮是不同的操作,不要收windows思想的左右。 32 一、打包 33 tar cvf /tmp/root.tar /home/jerry/ /etc/passwd /etc/shadow 34 (c參數表示打包,v是過程可見,f是後面跟的文件) 35 tar rvf /tmp/root.tar /home/jerry/a.txt 36 (r參數是追加文件,吧a.txt追加到root.tar包裡) 37 tar xvf /tmp/root.tar -C . 38 (x參數是解開打包 -C參數是指定解壓的位置) 39 tar tvf /tmp/root.rar 40 (t參數是查看包裡的內容,解開之前有所了解) 41 二、打包並壓縮 42 tar cvfz /tmp/root.tar.gz /etc/passwd 43 (z表示gzip壓縮方式) 44 tar cvfj /tmp/root.tar.bz2 /etc/passwd 45 (j表示bzip2的壓縮方式,壓縮率比gzip要高) 46 www.2cto.com 三、壓縮 47 (1)gzip壓縮工具 48 gunzip解壓 49 (2)bzip2壓縮工具 50 bunzip2解壓(壓縮率高於gzip) 作者 Jerryz
Copyright © Linux教程網 All Rights Reserved