小白的python之路10/29 文件归档
一打包解包文件
[root@localhost ~]# cd /test/
[root@localhost test]# touch a.txt b.txt c.txt
[root@localhost test]# ls
a.txt b.txt c.txt
#1.打包过程
#c表示创建,v表示过程信息,f表示文件名, test.tar表示打包后的文件名,文件后缀无意义
[root@localhost test]# tar cvf test.tar a.txt b.txt c.txt
a.txt
b.txt
c.txt
[root@localhost test]# ls
a.txt b.txt c.txt test.tar
#2查看过程t表示查看,f指定哪个文件
[root@localhost test]# tar -tf test.tar
a.txt
b.txt
c.txt
[root@localhost test]# ls
a.txt b.txt c.txt test.tar
[root@localhost test]# rm -rf a.txt b.txt c.txt
[root@localhost test]# ls
test.tar
#3 x表示解包 f表示指定文件
[root@localhost test]# tar xvf test.tar
a.txt
b.txt
c.txt
[root@localhost test]# ls
a.txt b.txt c.txt test.tar
[root@localhost test]# mkdir /bak
[root@localhost test]# ls /bak
[root@localhost test]# ls
a.txt b.txt c.txt test.tar
#4 大c表示指定路径(绝对路径)
[root@localhost test]# tar xvf /test/test.tar -C /bak
a.txt
b.txt
c.txt
[root@localhost test]# ls /bak
a.txt b.txt c.txt
#二 压缩文件的压缩和解压
#vim写入信息
[root@localhost test]# vim a.txt
#查看文件信息 文件大小59
[root@localhost test]# ll a.txt
-rw-r--r-- 1 root root 10月 29 20:51 a.txt
#压缩文件gzip 文件大小39
[root@localhost test]# gzip a.txt
[root@localhost test]# ll
总用量 4
-rw-r--r-- 1 root root 10月 29 20:51 a.txt.gz
[root@localhost test]# ll a.txt.gz
-rw-r--r-- 1 root root 10月 29 20:51 a.txt.gz
#解压文件
[root@localhost test]# gunzip a.txt
[root@localhost test]# ls
a.txt
[root@localhost test]# touch b.txt c.txt d.txt
[root@localhost test]# ls
a.txt b.txt c.txt d.txt
#打包
[root@localhost test]# tar cvf test.tar a.txt b.txt c.txt d.txt
a.txt
b.txt
c.txt
d.txt
[root@localhost test]# ls
a.txt b.txt c.txt d.txt test.tar
#压缩
[root@localhost test]# gzip test.tar
[root@localhost test]# ls
a.txt b.txt c.txt d.txt test.tar.gz
#打包时压缩
[root@localhost test]# 10月 29 21:14 test1.tar.gz
[root@localhost test]# ll -l test.tar.gz
-rw-r--r-- 1 root root 10月 29 21:00 test.tar.gz
[root@localhost test]# ls
a.txt b.txt c.txt d.txt test1.tar.gz test.tar.gz
[root@localhost test]# touch e.txt
[root@localhost test]# bzip2 e.txt
[root@localhost test]# ls
a.txt b.txt c.txt d.txt e.txt.bz2 test1.tar.gz test.tar.gz
#压缩文件bz2
[root@localhost test]# tar cvjf test2.tar.bz2 a.txt b.txt c.txt
a.txt
b.txt
c.txt
#2种归档文件无论是bzip2还是gzip解压都一样
[root@localhost test]# mkdir /test1
[root@localhost test]# mkdir /test2
[root@localhost test]# tar xf test1.tar.gz -C /test1/
#解压后包中信息
[root@localhost test]# ls /test1/
a.txt b.txt c.txt d.txt
[root@localhost test]# tar xf test2.tar.bz2 -C /test2/
[root@localhost test]# ls /test2
a.txt b.txt c.txt
#bz2比gz压缩更小 但是bz2速度慢,过程久
eg:对目录/etc/下文件夹的压缩
[root@localhost test]# tar cvzf etc.tar.gz /etc/
[root@localhost test]# ls
a.txt c.txt etc.tar.gz test1.tar.gz test.tar.gz
b.txt d.txt e.txt.bz2 test2.tar.bz2
mkdir /conf_bak
打包目录,结果中有目录名存在 tar cvzf test.tar.gz /etc
cd /etc
tar cvzf test,tar,gz*
补充
>将左边输出到右面eg:cat /etc/passwd > /tmp/passswd.bak
less随意浏览文件less /tmp/passswd.bak
Ctrl+c强制中断进程 CTRL + D 保存退出
useradd 用户 -del mkdir 文件夹 rm
小白的python之路10/29 文件归档的更多相关文章
- 小白的python之路10/31&11/1文件操作系统
文件操作系统的介绍 ext4的superblock块是超级快,innode 块是专门存放文件信息的, block count将硬盘做成block块,对操作系统而言写在block块上就可了,eg:文件1 ...
- 小白的python之路10/30磁盘分区
总结:fdisk mkfs mount 1.磁盘分区 硬盘分区有三种,主磁盘分区.扩展磁盘分区.逻辑分区. 一个硬盘主分区至少有1个,最多4个,扩展分区可以没有,最多1个.且主分区+扩展分区总共 ...
- 小白的python之路10/30 vim编辑器
1.vim进入命令行之后的编辑过程
- 小白的python之路10/22 day1
一.操作系统 操作系统就是一个协调.管理和控制计算机硬件资源和软件资源的控制程序.操作系统所处的位置如下图
- 小白的Python之路 day1
Python之路,Day1 - Python基础1 本节内容 Python介绍 发展史 Python 2 or 3? 一. Python介绍 python的创始人为吉多·范罗苏姆(Guido van ...
- 小白学习Python之路---开发环境的搭建
本节内容 1.Python的介绍 2.发展史 3.安装Python 4.搭建开发环境 5.Hello World程序 一.Python的介绍 Python的创始人为荷兰人吉多·范罗苏姆(Guido v ...
- NO.3:自学python之路------集合、文件操作、函数
引言 本来计划每周完成一篇Python的自学博客,由于上一篇到这一篇遇到了过年.开学等杂事,导致托更到现在.现在又是一个新的学期,春天也越来越近了(冷到感冒).好了,闲话就说这么多.开始本周的自学Py ...
- 小白学 Python 数据分析(10):Pandas (九)数据运算
人生苦短,我用 Python 前文传送门: 小白学 Python 数据分析(1):数据分析基础 小白学 Python 数据分析(2):Pandas (一)概述 小白学 Python 数据分析(3):P ...
- 小白的Python之路 day1 变量
Python之路,Day1 - Python基础1 变量 变量用于存储在计算机程序中引用和操作的信息.它们还提供了一种用描述性名称标记数据的方法,这样我们的程序就能更清晰地被读者和我们自己理解.将变量 ...
随机推荐
- mybatis的collection查询问题以及使用原生解决方案的结果
之前在springboot+mybatis环境的坑和sql语句简化技巧的第2点提到,数据库的一对多查询可以一次查询多级数据,并且把拿到的数据按id聚合,使父级表和子级表都有数据. 但是这种查询,必然要 ...
- 02:安装 Kerberos
1.1 环境介绍 参考博客:https://www.cnblogs.com/xiaodf/p/5968178.html https://www.douban.com/note/701660289/ ...
- centos设置网卡开机自启动
1.进入目录/etc/sysconfig/network-scripts/2.修改ifcfg-enxxxxxxxx 文件 (即你的网卡标识命名的配置文件)3. 将ONBOOT=no改成yes4. ...
- Spring 学习——Spring AOP——AOP配置篇Advice(无参数传递)
声明通知Advice 配置方式(以前置通知为例子) 方式一 <aop:config> <aop:aspect id="ikAspectAop" ref=" ...
- Eclipse中Lombok的安装和注解说明
Lombok 可用来帮助开发人员消除 Java 的重复代码,尤其是对于简单的 Java 对象(POJO),比如说getter/setter/toString等方法的编写.它通过注解实现这一目的. 官网 ...
- 论文笔记:AdaScale: Towards real-time video object detection using adaptive scalingAdaScale
AdaScale: Towards real-time video object detection using adaptive scaling 2019-02-18 16:14:17 Paper: ...
- mybatis-ehcache整合中出现的异常 ibatis处理器异常(executor.ExecutorException)解决方法
今天学习mabatis时出现了,ibatis处理器处理器异常,显示原因是Executor was closed.则很有可能是ibatis的session被关闭了, 后面看了一下测试程序其实是把sqlS ...
- VBoxManage
虚拟机名称 centos6.9-1 centos6.9-2 centos6.9-3 使用命令开机 虚拟机 VBoxManage startvm 'centos6.9-1' 正常启动 VBoxManag ...
- 关于Struts2自动装配和访问Servlet API
自动装配 1.根据属性的getter和setter获取值 index.jsp <s:form action="hello" method="POST"& ...
- 实验八 <FBG> 基于原型的团队项目需求调研与分析
<FBG>团队项目原型设计:http://www.cnblogs.com/ymm3/p/9012534.html GitHub的链接地址:https://github.com/FBGfbg ...