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

相关内容

    暂无相关文章