一.文件查找简介
1.命令文件查找:which 想要查找的命令 示例:查找ls命令的位置
2.任意文件查找:find 针对文件名
语法:find [path…] [options] [expression] [action]
命令 路径 选项 表达式 动作
按文件名示例:按文件大小示例:文件>5M 文件=5M 文件<5M
指定查找目录深度:在可查找范围查询成功,不可查找范围内失败
按文件属主、属组找:
请同学们注意,查找的用户和组要提前创建
按文件类型:
在这里插入代码片f普通文件 b块设备文件 d目录
按文件权限
找到后默认权限显示文件和属性find . -perm 715 -print 文件名
find . -perm 715 -ls 属性
找到后删除 find /etc -name “775*” -delete
找到后复制find /etc -name “ifcfg*” -ok cp -rvf {} /tmp ;
二.文件打包及压缩
1.简介:tar命令是Unix/Linux系统中备份文件的可靠方法,几乎可以工作于任何环境中,它的使用权限是所有用户。建议针对目录
2.打包,压缩。
语法:tar 选项 压缩包名称 源文件
[root@localhost ~]# tar -cf etc.tar /etc
tar: 从成员名中删除开头的“/”
[root@localhost ~]# tar -xf etc.tar
[root@localhost ~]# ll
总用量 65496
-rw-------. 1 root root 1718 7月 24 18:40 anaconda-ks.cfg
-rw-r--r--. 1 root root 0 8月 4 15:19 CentOS-Base.repo
drwxr-xr-x. 2 root root 6 8月 1 17:54 dir1
drwxr-xr-x. 2 root root 6 8月 1 18:00 dir2
drwxr-xr-x. 140 root root 8192 8月 4 17:37 etc
-rw-r--r--. 1 root root 34375680 8月 4 19:51 etc.tar
-rw-r--r--. 1 jack hr 28 8月 1 19:07 file1
-rw-r--r--. 1 root root 0 8月 3 11:09 file1.txt
-rw-r--r--. 1 root root 0 8月 3 20:12 file22
-rw-r--r--. 1 root root 0 8月 4 13:10 file3
-rw-r--r--. 1 root root 0 8月 3 20:34 file33
-rw-r--r--. 1 root root 1766 7月 24 19:15 initial-setup-ks.cfg
drwxr-xr-x. 2 root root 6 8月 2 01:27 公共
drwxr-xr-x. 2 root root 6 8月 2 01:27 模板
drwxr-xr-x. 2 root root 6 8月 2 01:27 视频
drwxr-xr-x. 2 root root 6 8月 2 01:27 图片
drwxr-xr-x. 2 root root 6 8月 2 01:27 文档
drwxr-xr-x. 2 root root 6 8月 2 01:27 下载
drwxr-xr-x. 2 root root 6 8月 2 01:27 音乐
drwxr-xr-x. 2 root root 6 8月 2 01:27 桌面
[root@localhost ~]# ls
anaconda-ks.cfg dir2 file1 file3 公共 图片 音乐
CentOS-Base.repo etc file1.txt file33 模板 文档 桌面
dir1 etc.tar file22 initial-setup-ks.cfg 视频 下载
```powershell
root@localhost ~]# tar -czvf etc-gzip.tar.gz /etc/ | tail -3
tar: 从成员名中删除开头的“/”
/etc/sudo-ldap.conf
/etc/sudo.conf
/etc/sudoers.d/
[root@localhost ~]# tar -xf etc-gzip.tar.gz
[root@localhost ~]# ls
anaconda-ks.cfg etc file1.txt initial-setup-ks.cfg 图片 桌面
CentOS-Base.repo etc-gzip.tar.gz file22 公共 文档
dir1 etc.tar file3 模板 下载
dir2 file1 file33 视频 音乐
[root@localhost ~]# ll -h etc*
-rw-r--r--. 1 root root 11M 8月 4 19:56 etc-gzip.tar.gz
-rw-r--r--. 1 root root 33M 8月 4 19:51 etc.tar
```powershell
[root@localhost ~]# tar -cjf etc-bzip.tar.bz /etc/
tar: 从成员名中删除开头的“/”
[root@localhost ~]# tar -cJf etc-xzip.tar.xz /etc/
tar: 从成员名中删除开头的“/”
[root@localhost ~]# ll -h etc*
-rw-r--r--. 1 root root 9.4M 8月 4 20:03 etc-bzip.tar.bz
-rw-r--r--. 1 root root 11M 8月 4 19:56 etc-gzip.tar.gz
-rw-r--r--. 1 root root 33M 8月 4 19:51 etc.tar
-rw-r--r--. 1 root root 7.6M 8月 4 20:03 etc-xzip.tar.xz
压缩速度和压缩体积成反比
3.解压,解包
查看并没有解压:`[root@localhost ~]# tar -tf etc.tar `
解压:[root@localhost ~]# tar xf etc.tar
[root@localhost ~]# ls
anaconda-ks.cfg etc-bzip.tar.bz file1.txt 公共 下载
CentOS-Base.repo etc-gzip.tar.gz file22 模板 音乐
dir1 etc.tar file3 视频 桌面
dir2 etc-xzip.tar.xz file33 图片
etc file1 initial-setup-ks.cfg 文档
[root@localhost ~]#
解压后的文件重定向到/tmp目录
```powershell
[root@localhost ~]# tar -xvf etc-gzip.tar.gz -C /tmp