0
点赞
收藏
分享

微信扫一扫

Linux系统基础知识(14)文件查找与解压缩

简介

  • which :命令查找
  • find: 文件查找,针对文件名
  • locate:文件查找,依赖数据库


一、命令文件查找

which

which ls  //从PATH环境变量

whereis

whereis vim

二、任意文件

locate

[root@localhost ~]# updatedb  //更新locate数据库
[root@localhost ~]# locate hosts

find

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

按文件名:

[root@localhost ~]# find /etc -name "hosts"
[root@localhost ~]# find /etc -iname "hosts" //-i忽略大小写

按文件大小:

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

指定查找的目录深度:

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

按文件属主、属组找:

[root@localhost ~]# find /home -user 用户名
[root@localhost ~]# find /home -group 组名

按文件类型:

[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 \;


文件打包及压缩

简介

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


打包,压缩

语法: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

三种包的体积不同

-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
压缩速度和压缩体积成反比


解压,解包

查看,并没有解压

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

解压缩

# tar xf etc3.tar.xz
# tar -xvf etc2.tar.bz2 -C /tmp 
//-C重定向到//tmp目录


举报

相关推荐

0 条评论