Linux打包 | 压缩
2023-02-18 16:38:33 时间
文章目录
find(文件/目录查找命令)
根据预设的条件递归查找文件或目录所在位置
根据查找条件查找 | |
---|---|
-type | f 文件 d 目录 l 链接文件 |
-name “file name” | |
[root@cocalhost ~]# find /var/log/ -type f
[root@cocalhost ~]# find /var/log/ -type d
[root@cocalhost ~]# find /etc/ -type l
[root@cocalhost ~]# find /etc/ -name passwd
/etc/pam.d/passwd
/etc/passwd
[root@cocalhost ~]# find /etc/ -name passwd -type f
/etc/pam.d/passwd
/etc/passwd
[root@cocalhost ~]# find /etc/ -name '*tab' -type f #以任意开头,但以tab结尾
/etc/fstab
/etc/crypttab
/etc/anacrontab
/etc/crontab
/etc/inittab
/etc/rwtab
/etc/statetab
[root@cocalhost ~]#
[root@cocalhost ~]# find /etc/ -name 'pass*' -type f3
[root@cocalhost etc]# find . -name '*.conf' -type f
#查找当前路径下,任意开头,但以.conf结尾的,文件
-iname按文件名查找忽略大小写 | |
---|---|
-size | 文件大小(K,M,G + 大于 - 小于) |
-a | 两个条件同时满足 |
-o | 两个条件同时满足任意一个即可 |
-user | 用户名 |
-mtime | 按日期查找( + 代表多少天之前 - 代表多少天之内 0代表24小时之内) |
[root@cocalhost etc]# find /etc/ -iname FSTAB -type f
/etc/fstab
#ls只在一层目录查找
[root@cocalhost etc]# ls /etc '*.conf' -type f
#find查找包含所有子目录
[root@cocalhost etc]# find /etc '*.conf' -type f
[root@cocalhost etc]# find /var/log/ -size +10k -type f #查看大于10K文件
[root@cocalhost etc]# du -h /var/log/messages
1.4M /var/log/messages
[root@cocalhost etc]# find /var/log/ -size -10k -type f
[root@cocalhost tmp]# find /var/log/ -size +10k -a -size -20k -type f #必须
[root@cocalhost tmp]# du -h /var/log/cron-20220328
12K /var/log/cron-20220328
[root@cocalhost tmp]# find /var/log/ -size +10k -o -size -100k -type f #或者
[root@cocalhost tmp]# find /root -user root
#查找所有root用户的文件或目录
[root@cocalhost tmp]# find /home -user user01 -type f
#查找所有user01用户的文件
[root@cocalhost tmp]# find /var/log -mtime +10 -type f
[root@cocalhost tmp]# ll /var/log/spooler-20220323
-rw-------. 1 root root 0 3月 15 18:10 /var/log/spooler-20220323
-exec 处理命令 {} ; | |
---|---|
{} | 代表find查找到的内容被放置{}中 |
; | 代表额外处理命令结束 |
[root@cocalhost tmp]# find /var/log -mtime -30 -type f -exec cp {} /tmp \;
[root@cocalhost tmp]# find /var/log -mtime +30 -type f -exec rm -rf {} \;
压缩与解压缩(压缩单文件)
(源文件消失)
Linux独有压缩格式以及命令工具 |
---|
gzip —> .gz |
不解压查看压缩文件内容:zcat [option] [file name] |
bzip2 —> .bz2 |
---|
不解压查看压缩文件内容:bzcat [option] [file name] |
xz —> .xz |
---|
不解压查看压缩文件内容:xzcat [option] [file name] |
压缩命令格式 | |
---|---|
gzip [option] [file name] | |
-d | 解压缩 |
#gzip(速度快,内存大)
[root@cocalhost tmp]# gzip services
[root@cocalhost tmp]# ll -h
total 136K
-rw-r--r--. 1 root root 133K 3月 29 18:47 services.gz
[root@cocalhost tmp]# gzip -d services.gz
[root@cocalhost tmp]# zcat services.gz
#bzip2(速度中等,内存中等)
[root@cocalhost tmp]# bzip2 services
[root@cocalhost tmp]# bzcat services.bz2
[root@cocalhost tmp]# bzip2 -d services.bz2
#xz(速度慢,内存小)
[root@cocalhost tmp]# xz services
[root@cocalhost tmp]# xzcat services.xz
[root@cocalhost tmp]# xz -d services.xz
tar(打包目录/文件)
(源文件不消失)
[root@cocalhost tmp]# tar [option] 被压缩文件 压缩包名字
-c | 创建打包文件 |
---|---|
-f | 指定打包后的文件名称 |
-z | -z 调用gzip压缩工具 -J 调用xz压缩工具 -j 调用bzip2压缩工具 |
-t | 列出打包文档内容 |
-x | 释放打包文件 |
-C | 指定施压路径 |
-v | 显示详细信息 |
[root@cocalhost tmp]# tar -czf xxx.tar.gz /etc/passwd /etc/fstab /home/
tar: Removing leading `/' from member names
[root@cocalhost tmp]# ls
services xxx.tar.gz
[root@cocalhost tmp]# tar -tf xxx.tar.gz #列出打包文档内容
[root@cocalhost tmp]# tar -xf xxx.tar.gz -C /media #解压缩到指定路径
[root@cocalhost tmp]# tar -cJf xxx.tar.xz /etc/hostname /etc/services /home/
[root@cocalhost tmp]# tar -vxf xxx.tar.xz -C /tmp #解压显示详细信息
du统计文件/目录大小
统计磁盘目录或文件大小
-h | 以人类易读方式 |
---|---|
-s | 只统计每个参数的总数 |
[root@cocalhost ~]# du -h /etc/services
656K /etc/services
[root@cocalhost ~]# du -s /etc/services
656 /etc/services
[root@cocalhost ~]# ls -lhd /etc/services
-rw-r--r--. 1 root root 655K 6月 7 2013 /etc/services
相关文章
- Google Chrome不仅仅是浏览器
- C#11 file关键字
- Linux 命令(219)—— nstat 命令
- Linux 命令(220)—— ipcalc 命令
- Linux 命令(221)—— poweroff 命令
- Linux 命令(222)—— halt 命令
- Linux 命令(223)—— reboot 命令
- Linux 命令(224)—— ctrlaltdel 命令
- Linux 命令(225)—— printf 命令
- Linux 命令(226)—— exec 命令(builtin)
- Linux 命令(227)—— history 命令(builtin)
- 嵌入式:堆栈寻址、相对寻址与ARM指令总结
- C++中你不知道的namespace和using的用法
- Golang数据结构之Interface
- 我开源了一个Go学习仓库|笔记预览
- Go语言知识查漏补缺|基本数据类型
- Go 源码解读|如何用好 errors 库的 errors.Is() 与 errors.As() 方法
- 使用 Go HTTP 框架 Hertz 进行 JWT 认证
- 玩转 Go 生态|Hertz WebSocket 扩展简析
- trzsz ( trz / tsz ) 是兼容 tmux 的 rz / sz,js 和 go 版发布 1.0 正式版。