Linux系统配置及服务管理-08-文件查找、压缩解压缩

文件查找

which 和 whereis

从PATH环境变量中查找命令位置
which ls
在这里插入图片描述
where ls
在这里插入图片描述

find

文件查找,针对文件名

  • 语法
find [path...] [options]  [expression] [action]
命令  路径        选项            表达式     动作
  • 按文件名
find /etc -name "hosts"  # 精确查找
find /etc -iname "hosts"   # iname 忽略大小写
find /etc -iname "hos*"  # * 通配符
  • 按文件大小
find /etc -size +5M  # 文件>5M
find /etc -size 5M  # 文件=5M
find /etc -size -5M  # 文件<5M
  • 指定查找的目录深度
# 可查找范围
find / -maxdepth 4 -a -name "ifcfg-en*"
- 查询是成功的

# 不可查找范围
find / -maxdepth 3 -a -name "ifcfg-en*"
- 查询是失败的
  • 按文件属主、属组
# 查找的用户和组要提前创建好
find /home -user  jack   # 属主是jack的文件
find /home -group hr    # 属组是hr组的文件
  • 按文件类型
find /tmp -type f
find /dev -type b
# f 普通文件
# b 块设备文件
# d 目录
# p 管道
# l 链接
  • 按文件权限
find . -perm 644 -ls  # ls是find的动作之一,精确权限
  • 找到后处理的动作 ACTIONS

找到后默认是显示文件名,也就是print
find . -perm 644 -print # 文件名

find . -perm 715 -ls # 文件属性

找到后删除
find /etc -name "1*" -delete

找到后复制
find /etc -name "ifcfg*" -ok cp -rvf {} /tmp \;
会提示,需要输入y,否则不会复制

locate

文件查找,依赖数据库
1.安装
yum -y install mlocate

2.更新locate数据库
updatedb

3.locate查找文件hosts文件
locate hosts

文件打包及压缩

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 需要安装yum install -y bzip2
    tar -cJf etc-xzip.tar.xz /etc/ J是xzip

  • 观察三个包的体积。
    在这里插入图片描述

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

解压,解包

  • 查看,并没有解包

tar -tf etc-gzip.tar.gz t:查看,f:文件名

  • 解压缩

tar xf etc3.tar.xz 直接解压到当前目录

tar -xvf etc2.tar.bz2 -C /tmp -C:重定向到/tmp目录

猜你喜欢

转载自blog.csdn.net/HYESC/article/details/128054898