打包压缩与搜索命令

打包压缩与搜索命令

  • tar

    tar命令用于对文件进行打包压缩或解压,格式为:tar [选项] [文件]

    参数 作用
    -c 创建压缩文件
    -x 解开压缩文件
    -t 查看压缩包内有哪些文件
    -z 用Gzip压缩或解压
    -j 用bzip2压缩或解压
    -v 显示压缩或解压过程
    -f 目标问价名
    -p 保留原始的权限与属性
    -P 使用绝对路径来压缩
    -C 指定解压到的目录

    压缩过程:

    [root@zhufanyu ~]# tar -czvf linux_1.tar.gz linux_1.txt
    

    解压过程:

    [root@zhufanyu ~]# tar xzvf linux_1.tar.gz /etc
    
  • grep

    grep 命令用于在文本中执行关键词搜索,并显示匹配结果,格式为:grep [选项] [文件]

    参数 作用
    -b 将可执行文件(binary)当做文本文件(text)来搜索
    -c 仅显示找到的行数
    -i 忽略大小写
    -n 显示行号
    -v 反向选择--仅列出没有“关键词的行”
    [root@zhufanyu ~]# grep /sbin/nologin /etc/passwd
    bin:x:1:1:bin:/bin:/sbin/nologin
    daemon:x:2:2:daemon:/sbin:/sbin/nologin
    adm:x:3:4:adm:/var/adm:/sbin/nologin
    lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
    mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
    
    
  • find

    find 命令用于按照指定条件来查找文件,格式为:find [查找路径] 寻找条件 操作

    参数 作用
    -name 匹配名称
    -perm 匹配权限(mode为完全匹配,-mode为包含即可)
    -user 匹配所有者
    -group 匹配所有组
    -mtime -n +n 匹配修改内容的时间(-n指定n天以内, +n指n天以前)
    -atime -n +n 匹配访问文件的时间(-n指n天以内,+n指n天以前)
    -ctime -n +n 匹配修改文件权限的时间(-n指n天以内,+n指n天以前)
    -nouser 匹配无所有者的文件
    -nogroup 匹配无所有组的文件
    -newer f1 !f2 匹配比文件f1新但比f2旧的文件
    --type b/d/c/p/l/f 匹配文件的类型(后面的字母参数依次表示块设备、目录、字符设备、管道、连接文件、文本文件)
    -size 匹配文件的大小(+50KB为查找超过50KB的文件,而-50KB为查找小于50KB的文件)
    -prune 忽略某个目录
    -exec ······ {} ; 后面可跟用于进一步处理搜索结果的命令
    [root@zhufanyu ~]# find /etc -name "host*" -print
    /etc/host.conf
    /etc/hosts
    /etc/cloud/templates/hosts.redhat.tmpl
    /etc/cloud/templates/hosts.suse.tmpl
    /etc/cloud/templates/hosts.freebsd.tmpl
    /etc/cloud/templates/hosts.debian.tmpl
    /etc/hostname
    
    
    [root@zhufanyu ~]# find / -perm -4000 -print
    find: ‘/proc/17946/task/17946/fd/6’: No such file or directory
    find: ‘/proc/17946/task/17946/fdinfo/6’: No such file or directory
    find: ‘/proc/17946/fd/5’: No such file or directory
    find: ‘/proc/17946/fdinfo/5’: No such file or directory
    
原文地址:https://www.cnblogs.com/zhufanyu/p/14238417.html