linux文件查找及打包压缩解压缩

文件查找

which 只能查询命令

which rpm

whereis 可以查询命令和配置文件的位置

whereis rpm

whereis passwd

whatis

whatis rpm 和下面命令一样的效果,查询rpm命令都在哪章man有解释

man -f rpm

find 路径 条件 动作

按文件名:

find /etc -name "ifcfg-eth0"

find /etc -iname "ifcfg-eth0" 忽略大小写

find /etc -iname "ifcfg-eth"

find /etc -name "*1" 以1结尾的

按文件大小

find /etc -size +5M 大于5M

find /etc -size 5M

find /etc -size -5M

find /etc -size -ls ||-ls 找到的处理动作

     按时间找(atime,mtime,ctime):

[root@xingdian ~]# find /etc -mtime +5 //修改时间超过5天 [root@xingdian ~]# find /etc -mtime 5 //修改时间等于5天 [root@xingdian ~]# find /etc -mtime -5 //修改时间5天以内 按文件属主、属组找: [root@xingdian ~]# find /home -user jack //属主是jack的文件 [root@xingdian ~]# find /home -group hr //属组是hr组的文件 [root@xingdian ~]# find /home -user jack -group hr [root@xingdian ~]# find /home -user jack -a -group hr [root@xingdian ~]# find /home -user jack -o -group hr -o 是或者的意思 -a 是而且的意思 -not 是相反的意思 find /home -nouser find /home -nogroup find /home -nouser -o -nogroup 按文件类型: find /dev -type f //f普通 find /dev -type d //d目录 find /dev -type l //l链接 find /dev -type b //b块设备 find /dev -type c //c字符设备 find /dev -type s //s套接字 find /dev -type p //p管道文件 按权限: find -perm 644 -ls find -perm -644 -ls find -perm -600 -ls find -perm -222 -ls

按正则表达式

-regex pattern

[root@xingdian ~]# find /etc -regex '.ifcfg-eth[0-9]' . 任意多个字符 [0-9] 任意一个数字 + 前面字符一次或者多次 \ 转义符

找到后处理的动作 ACTIONS: (默认动作-print)

-print: 显示 -ls:类似ls -l的形式显示每一个文件的详细 -delete: 删除匹配到的行 -ok COMMAND {} \; 每一次操作都需要用户确认,{}表示引用找到的文件,是占位符 -exec COMMAND {} \; 每次操作无需确认

[root@xingdian ~]# find . -type f -name "*.txt" |xargs -i cp {} /tmp/

打包压缩解压缩

压缩----解压缩 tar 参数

压缩包格式

.tar.gz

.tar.bz2

.tar.xz

.zip

在linux系统中打包压缩

tar cvf 路径/压缩包文件名 文件名

在linux系统中解压缩

tar xf 压缩包的名字 -C(指定解压的路径 )

[root@xingdian opt]# tar xf file-1.tar.gz

如果看到.zip结尾的压缩包,使用unzip解压

[root@xingdian tmp]# unzip --help-bash: unzip: command not fqund[root@xingdian tmp]# yum -y install unzip

zip -d 指定压缩位置

.gz------gunzip 文件名

打包压缩结合文件查找

find ./ -name "file*" |xargs -i tar rf /tmp/file2.tar.gz {}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值