Linux系统配置及服务管理第08章文件查找

目录

 

一.文件查找

1、命令文件查找

2、任意文件

二.文件打包及压缩

1.打包,压缩

2.解压,解包


一.文件查找

简介:which :命令查找

           find: 文件查找,针对文件名

            locate:文件查找,依赖数据库

1、命令文件查找

查找lvim命令的位置:[root@localhost ~]# which ivim  

2、任意文件

语法:find [path...] [options]  [expression] [action]
       命令 路径       选项             表达式        动作

1.按文件名:

[root@localhost ~]# find /etc/ -name "hosts"

[root@localhost ~]# find /etc/ -iname "hosts"

[root@localhost ~]# find /etc/ -iname "hos*"

-i忽略大小写

2.按文件大小

[root@localhost ~]# find /etc/ -size +5M    //文件>5M

[root@localhost ~]# find /etc/ -size 5M   //文件=5M

[root@localhost ~]# find /etc/ -size -5M    // 文件<5M  

3.指定查找的目录深度

可查找范围:[root@localhost ~]# find / -maxdepth 4 -a -name "ifcfg-en*"

不可查找范围: [root@localhost ~]# find / -maxdepth 3 -a -name "ifcfg-en*"

4.按文件属主、属组找:

请注意,查找的用户和组要提前创建好。

[root@localhost ~]# find /home -user jack   //属主

[root@localhost ~]# find /home -group hr   //属组是hr组的文件

5.按文件类型:

[root@localhost ~]# find /tmp -type f  //f普通文件

[root@localhost ~]# find /tmp -type b  //b块设备文件
[root@localhost ~]# find /tmp -type p   //p管道
[root@localhost ~]# find /tmp -type l   //ll连接文件
[root@localhost ~]# find /tmp -type d   //d目录

6.按文件权限:

[root@localhost ~]# find . -perm 644 -ls

  7.找到后处理的动作 ACTIONS:

找到后默认是显示文件

[root@localhost ~]# find . -perm 644 -print     //显示文件名

找到后删除

[root@localhost ~]# find /etc -name "775" -delete
找到后复制
[root@localhost ~]# find /etc -name "ifcfg*" -ok cp -rvf {} /tmp \;
 

二.文件打包及压缩

简介:tar命令是Unix/Linux系统中备份文件的可靠方法,
几乎可以工作于任何环境中,它的使用权限是所有用户。
建议针对目录

1.打包,压缩

语法:tar  选项  压缩包名称  源文件

打包,压缩

[root@localhost ~]# tar -cf etc.tar /etc   //压缩 /etc

解压  :[root@localhost ~]# tar -xf etc.tar

[root@localhost ~]# tar -czvf etc-gzip.tar.gz  /etc/       //z是gzip

[root@localhost ~]# tar -cjf etc-bzip.tar.bz /etc/        //j是bzip
[root@localhost ~]# tar -cjf etc-bzip.tar.xz /etc/      //J是xzip

观察三个包的体积

[root@localhost ~]# ll -h etc*

压缩速度和压缩体积成反比。

2.解压,解包

查看,并没有解压

# tar -tf       etc.tar      //t查看f文件名

解压缩

[root@localhost ~]# tar xf etc-bzip.tar.xz   //简单粗暴

tar -xvf etc-bzip.tar.bz -C /tmp      //-C重定向到//tmp目录

 

 

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值