Linux系统—第08章—文件查找

一文件查找

1.简介

which :命令查找

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

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

2.命令文件查找

查找ls 命令的位置
# which ls    //从PATH环境变量


或者
# whereis vim

3.任意文件

find

==语法==

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

==按文件名==

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

  

 

  

    -i忽略大小写
 结果输出
    /etc/hosts
    文件查找成功

==按文件大小==

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

   

        文件>5M
        文件=5M
        文件<5M

==指定查找的目录深度==
    可查找范围   / 下四级目录里查找

 [root@localhost ~]# find / -maxdepth 4 -a -name "ifcfg-en*"

    

    查询是成功的
    不可查找范围

 [root@localhost ~]# find / -maxdepth 3 -a -name "ifcfg-en*"

  

        查询是失败的

==按文件属主、属组找==
    请同学们注意,查找的用户和组要提前创建好。

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

     

==按文件类型==
    [root@localhost ~]# find   /tmp   -type  f
    [root@localhost ~]# find   /dev   -type  b
        f普通文件
        b块设备文件
        d目录
        p管道
        l连接

==按文件权限==
    [root@localhost ~]# find . -perm 644 -ls
        -ls   是find的动作之一,精确权限

==找到后处理的动作 ACTIONS==
    找到后默认是显示文件

 [root@localhost ~]# find . -perm  715  -print     短格式(只显示文件)

 [root@localhost ~]# find . -perm  715  -ls   长格式(显示文件的属性)

 [root@localhost ~]# find  /etc   -name   "775*"  -delete      找到后删除

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

 

二文件打包及压缩

1.简介

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

2.打包,压缩

==语法==

 tar  选项  压缩包名称  源文件

==打包压缩==

tar   -cf     etc.tar     /etc
解压
tar   -xf  etc.tar

 tar   -czvf    etc-gzip.tar.gz    /etc/
z是gzip

tar   -cjf       etc-bzip.tar.bz        /etc/
j是bzip

tar   -cJf         etc-xzip.tar.xz        /etc/
J是xzip

 他们的差别就是体积和时间的差别

==观察三个包的体积

    ll -h etc*
    -rw-r--r--. 1 root root  11M 10月 14 10:07 etc-gzip.tar.gz
    -rw-r--r--. 1 root root 8.9M 10月 14 10:08 etc-bzip.tar.bz
    -rw-r--r--. 1 root root 7.6M 10月 14 10:08 etc-xzip.tar.xz
    压缩速度和压缩体积成反比。

3.解压,解包

==查看==

# tar -tf       etc.tar     

//t查看f文件名

==解压缩==

# tar xf etc3.tar.xz

     //简单粗暴

tar -xvf etc2.tar.bz2 -C /tmp

-C重定向到//tmp目录

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值