linux查找打包.doc_第1页
linux查找打包.doc_第2页
linux查找打包.doc_第3页
linux查找打包.doc_第4页
linux查找打包.doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

查找什么是查找?为什么使用查找?因为我们常常需要知道那个文件放在哪里,才能够对该文件进行一些修改或维护等动作-which 查找对象为 PATH 指定路径下的可执行的 shell 命令或可执行脚本。 # echo $PATH# which ifconfig# su tom$ echo $PATH$ which ifconfigwhereis 查找一个命令的二进制文件位置,源代码位置,man 页的位置 #whereis passwd locate 基于数据库查找,速度快。 依赖于数据库,更新数据库命令为 updatedb #touch /root/rootfile #locate rootfile #updatedb #locate rootfile find 全盘扫描find 要查找的位置 选项 参数 要查找的内容 参数: -name 按照文件名查找 -iname 名字不区分大小写 #cd /tmp #touch redhat #REDHAT #find . -name redhat #find . -iname redhat -user 用户名 按照用户查找文件 -group 组名 按照组查找文件 -nouser 没有所有者 孤儿文件 -nogroup 没有所属组 #cd /tmp #su - candan $cd /tmp $touch candanfile $exit #su - uplooking $cd /tmp $touch uplookingfile $exit #cd /tmp #find . -user candan #find -group uplooking #userdel uplooking #find . -nouser #find . -nogroup -size 文件大小 c byte k +.k (大于) -.k(小于) k(等于) M +M -M .M #cd /tmp #dd if=/dev/zero of=1Mfile bs=1M count=1 #dd if=/dev/zero of=3Mfile bs=1M count=3 # dd if=/dev/zero of=8Mfile bs=1M count=8 #find . -size +1M #find .-size -8M #find . -size +1M -and -size -8M #find . -size 3M -type 文件类型 f:普通文件 d:目录文件 b:块设备文件 l:链接文件 p:管道文件 s:socket 文件 c:字符设备文件:打印机 -perm 权限 0000 7777 +: 只要满足条件就输出 -: 只有满足条件才输出 : 绝对匹配 rootx1 test1# ll 总计 12308 -rw-r-r- 1 root root 1048576 07-29 14:01 1Mfile -rw-r-r- 1 root root 3145728 07-29 14:03 3Mfile -rw-r-r- 1 root root 8388608 07-29 14:05 8Mfile -rwxr-r- 1 root root 0 07-29 14:06 a -rwxrwxrwx 1 root root 0 07-29 14:06 b rootx1 test1# find -perm +111 . ./b ./a rootx1 test1# find -perm -111 . ./b rootx1 test1# find -perm 744 ./a rootwww # ls l find /sbin -perm +7000 rootx1 test1# -atime n 天(24 小时, 从当前时间开始) -ctime n -mtime n -anewer filename -cnewer filename -mnewer (-newer)filename 查找以后直接处理找到的文件 -exec 非交互 -ok 交互 # find . -perm 744 -exec rm -f ; # find . -perm 744 -ok rm -f ; 查找/etc/目录下所有.conf 的文件,将这些文件拷贝到/backup 目录内 # find /etc -name *.conf -exec cp /backup ; 逻辑关系运算 -o:或者 #find /etc -name passwd -o -name shadow -and: 与 (-a) # find . -type f -and -size 3M -not: 非(!) # find . -type f -not -name 3Mfile 练习:尝试用 find 找出目前 linux 系统中,所有具有 SUID 的文件有哪些? # find / -perm +4000 -print 找出 /etc 底下,文件大小介於 50K 到 60K 之间的文件,并且将权限完整的列出。# find /etc -size +50k -a -size -60k -exec ls -l ;找出 /etc 底下,文件容量大於 50K 且文件所有者不是 root 的文件,且将权限完整的列出。 # find /etc -size +50k -a ! -user root -exec ls -ld ;# find /etc -size +50k -a ! -user root -type f -exec ls -l ;找出 /etc 底下,容量大於 1500K 以及容量等於 0 的文件: # find /etc -size +1500k -o -size 0*压缩,解压缩节省硬盘空间、备份、网络传输1、gzip gunzip gzip是一个GNU自由软件的文件压缩程序。 gunzip用于解开被gzip压缩过的文件,文件的扩展名为.gz。gzip压缩的命令# echo hello a /生成一个文件,内容为hello# gzip a /把a文件压缩# ls /查看生成的 a.gz gunzip解压缩的命令# gunzip a.gz /解压缩a.gz 文件zcat *.gz 查看压缩文件的内容# zcat a.gz 2、bzip2 bunzip2bzip2 能够进行高质量的数据压缩,能够把普通的数据文件压缩10%至15%,压缩的速度和解压的效率都非常高。bzip2压缩的命令# echo hello b /生成一个文件,内容为hello# bzip2 b /把b文件压缩# ls /查看生成的 b.bz2 bunzip2 解压缩的命令# bunzip2 b.bz2 /解压缩b.bz2 文件注意:bzip2无法压缩目录!bzcat *.bz2 /查看压缩文件的内容# bzcat b.bz2 查看压缩文件的内容3、zip unzip # touch c# zip c.zip c# unzip c.zip-file 验证文件类型。# gzip a# lsa.gz # mv a.gz afile# file afileafile: gzip compressed data, was a, from Unix, last modified: Wed May 23 16:45:30 2012-tar 打包、压缩选项:c 创建一个 tarball x 解开一个 tarball v 显示打包或者解包的过程 f 指定 tarball 的名字 t 查看 tarball 的压缩文件列表 r 将文件添加到一个已经存在的 tarball 之内 u 更新一个 tarball 中的文件 z 将 tarball 压缩成为.gz 的格式 j 将 tarball 压缩成为.bz2 的格式 C 解包的时候,指定存放压缩文件的路径 #tar cvf backupground.tar b1.jpg b2.jpg b3.jpg #tar cvf bg.tar /usr/shared/backgrounds #tar zcvf bg1.tar.gz /usr/shared/backgrounds #tar jcvf bg2.tar.bz2 /usr/shared/backgrounds 举例: * 加载 vmware tools 光盘,挂载到/mnt/cdrom 上 #mkdir /mnt/cdrom #mount /dev/cdrom /mnt/cdrom * 将该光盘内的 VMware.tar.gz 拷贝到/tmp 目录 #cd /mnt/cdrom #cp VMware* /tmp * 解压该软件包,并运行 vmware-install.pl #cd /tmp #tar zxvf VMware #cd vmware #./vmware-isntall.pl 打包 rootx1 tmp# tar cvf file.tar a b c 查看 rootx1 tmp# tar tf file.tar 追加 rootx1 tmp# tar rf file.tar d 查看 rootx1 tmp# tar tf file.tar a b c d 更新 rootx1 tmp#echo hello brootx1 tmp# tar uf file.tar b将压缩包解压到特定的目录内 rootx1 # tar zxvf VMwareTools-8.1.4-227600.tar.gz -C /tmp 删除 tarball 内的指定文件 rootx1 tmp# tar tf file.tar a b c d rootx1 tmp# tar -delete -f file.tar d rootx1 tmp# tar tf file.tar a b c 练习 * 在/etc 的两层目录之内查找 *.conf 文件,将这些文件打包为 etc2conf.tar tar cvf etc2conf.tar find /etc maxdepth 2 name *.conf * 在确认 etc2conf.tar 内的文件准确无误后,将该文件压缩为 gz 格式 tar zcvf etc2conf.tar.gz etc2conf.targrep:global regular expression print 搜索某些关键字,输出结果包含该关键字的行。以行为单位。基本格式:grep 选项 搜索关键字要搜索的文件名列表#grep root /etc/passwd -i 忽略大小写#ifconfig | grep -i bcast -n #grep -n root /etc/passwd -v 反向显示#cat /etc/vsftpd/vsftpd.conf | grep -v # | grep -v $-r directory:对某个路径下面的所有文件进行搜索#grep -r root /etc -l 只显示包含该关键字文件的文件名#grep -rl root /etc -c 统计,显示一共有多少行包含该关键字# grep -c root

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论