文件查找,打包,压缩
一、文件查找
which,find,locate
1.命令文件查找
which ls #从PATH环境变量
或者
whereis vim
2.任意文件
(1) locate
使用locate前先更新数据库
updatedb
实例
locate “*.txt”
(2) find
语法:
find [path…] [options] [expression] [action]
命令 路径 选项 表达式 动作
按文件名
find / -name "hosts"
-i 忽略大小写
按文件大小
find /etc -size +2M #文件大于2M
find /etc -size 2M #文件等于2M
find /etc -size -2M #文件小于2M
指定查找的目录深度
find / -maxdepth 4 -a -name "ifcfg-en*" #-a代表把两个选项连接qilai
按文件的属主、属组找
find /opt -user zhubajie #属主是猪八戒的文件
find /opt -group fozu
按文件类型
f 普通文件 b 块设备文件 d 目录 p 管道 l链接
find /opt -type f
find /dev -type b
按文件权限
find /root -perm 644 -ls #-ls 是find的动作之一
找到后处理的动作
-exec
找到后删除
find /root -name "*.txt" -exec rm -rf {} \;
找到后复制
find /etc -name "ifcfg*" -exec cp -rf {} /tmp \;
二、文件打包及压缩
1.打包,压缩
语法
tar 选项 压缩包名称 源文件
实例
tar -czvf etc-gzip.tar.gz /etc/
2.解压,解包
tar -xf etc3.tar.xz #简单粗暴
tar -xvf etc2.tar.bz2 -C /tmp #-C 重定向到/tmp目录