打包、压缩与解压缩

gzip压缩文件特点:
1.后缀名为gz
2.可以通过gzip -9 file1.tar 命令调节压缩比
3.压缩文件后,原来的文件消失。
4.解压缩:gzip -d file1.tar.gz
切记不是背出来的 而是通过man命令查出来的。
tar打包命令
-f, --file=ARCHIVEuse archive file or device ARCHIVE
-r, --appendappend files to the end of an archive1.tar -cf archive.tar foo bar 打包
2.tar -tvf archive.tar 详细查看
或者粗略查看
[dennis@localhost ~]$ tar -tf file.tar
file2.txt
file2.txt
file1.txt
file2.txt3.tar -xf archive.tar 解包
或者 tar -xf archive.tar ./dir 解包之后放到固定的目录下。
4.tar -Af archive.tar file.tar 将archive.tar的内容合并到file.tar
或者:tar -f archive.tar -A file.tar
或者:tar -f archive.tar -r file1.txt 将file1.txt加入到archive.tar中
5.tar -f archive.tar --delete file.txt 将archive.tar中的file.txt删除掉观察一个现象,复制同一个文件不可以,但打包文件下加入一个相同的文件为什么就可以呢?
[dennis@localhost ~]$ tar -f file.tar -r file1.txt
[dennis@localhost ~]$ tar -tvf file.tar
-rw-rw-r-- dennis/dennis     0 2020-05-01 20:19 file2.txt
-rw-rw-r-- dennis/dennis     0 2020-05-01 20:19 file2.txt
-rw-rw-r-- dennis/dennis    12 2020-05-04 09:39 file1.txt
-rw-rw-r-- dennis/dennis     0 2020-05-01 20:19 file2.txt
-rw-rw-r-- dennis/dennis    12 2020-05-04 09:39 file1.txt[dennis@localhost ~]$ cp file2.txt ./
cp: ‘file2.txt’ and ‘./file2.txt’ are the same file

cat命令

concatenate连接
连接几个文件
从键盘创建文件
查看文件

1.cat /etc/passwd
只能显示一屏的内容,一屏40行。2.cat -n /var/log/messages
显示行号(替换nl命令:显示行号)3.[root@localhost ~]# cat -A /etc/issue
下面是输入命令后的效果:
\S$
Kernel \r on an \m$
$
显示所有。这就包含特殊的字符 比如换行符$4.tac /etc/issue
从最后一行显示5.-n与-b的区别:
[root@localhost ~]# cat -n a.txt1  白日依山尽2  黄河入海流3  4   更上一层楼
[root@localhost ~]# cat -b a.txt1  白日依山尽2  黄河入海流3  更上一层楼6.这种格式被称作为nonprinting
[root@localhost ~]# cat -v a.txt
M-gM-^YM-=M-fM-^WM-%M-dM->M-^]M-eM-1M-1M-eM-0M-=
M-iM-;M-^DM-fM-2M-3M-eM-^EM-%M-fM-5M-7M-fM-5M-^AM-fM-^[M-4M-dM-8M-^JM-dM-8M-^@M-eM-1M-^BM-fM-%M-<
nonprinting是什么?
they are characters that take up space or have a formatting function but do not appear on the printed page: spaces, tab characters, paragraph breaks, and the like.

less与more

more命令查看有百分数显示(本人更亲赖于这个命令)
more /var/log/messages |grep Dennis
回车:一行一行看
空格:一页一页看
b:back 一行一行向上看
ctrl+b:一页一页向上看
:f显示行数
/string 找固定的词语
使用管道筛选特定用户信息 查询的信息作为grep输入。
Linux grep 命令用于查找文件里符合条件的字符串。less命令查看无百分数显示
适合查看比较多的文件。
up down健向上向下进行翻行
page up 与 page down健进行上下翻页
n跳转到下一个关键字处 N跳转到上一个关键字处
q离开

head 与 tail命令 查看日志文件


head默认显示头10行
[root@localhost ~]# head -3 /var/log/messages
Apr 28 21:30:01 localhost systemd: Started Session 9 of user root.
Apr 28 21:38:32 localhost systemd: Got automount request for /proc/sys/fs/binfmt_misc, triggered by 4997 (find)
Apr 28 21:38:32 localhost systemd: Mounting Arbitrary Executable File Formats File System...
[root@localhost ~]# tail -3 /var/log/messages
Apr 29 14:00:01 localhost systemd: Started Session 5 of user root.
Apr 29 14:01:01 localhost systemd: Started Session 6 of user root.
Apr 29 14:10:01 localhost systemd: Started Session 7 of user root.
查看 /etc/man_db.conf 11到20行
[root@localhost ~]# cat -n /etc/man_db.conf |head -n 20 |tail -n 10

文件查找

which查看可执行文件

which cd
用于查找固定的命令
which -a cd
列出所有命令路径 不单单是第一个
type与history均为内置命令,在内存中,没有文件,所以用which找不到。
[root@localhost ~]# type type
type is a shell builtin
所以查不到,但为什么这里可以查到cd这个内置命令?
内置命令不一定没有文件,像cd,外部命令一定有文件。需要的时候加载进来。
以下命令是查看cp这个命令的位置及显示别名信息,这更加印证了为什么直接用cp带提示的原因了。
[root@localhost ~]# which cp
alias cp='cp -i'/usr/bin/cp

whereis

比which要广一些:

查看二进制格式文件(-b) 说明文件下的文件(-m)源文件(-s)及其它特殊文件(-u)

[root@localhost ~]# whereis -l
bin: /usr/bin
bin: /usr/sbin
bin: /usr/lib
bin: /usr/lib64
bin: /etc
bin: /usr/etc
bin: /usr/games
bin: /usr/local/bin
bin: /usr/local/sbin
bin: /usr/local/etc
bin: /usr/local/lib
bin: /usr/local/games
bin: /usr/include
bin: /usr/local
bin: /usr/libexec
bin: /usr/share
man: /usr/share/man/man0p
man: /usr/share/man/man1
man: /usr/share/man/man1p
man: /usr/share/man/man1x
man: /usr/share/man/man2
查看可以查找的范围。
whereis -b ifconfig

locate

搜索要快一些,从locatedb中搜索。但是每天只更新一次,所以查不到的时候使用updatedb进行更新。

使用updatedb命令之后查找到了我刚创建的a.txt
[root@localhost ~]# updatedb
[root@localhost ~]# locate a.txt
/root/a.txt
查看数据库情况:
[root@localhost ~]# locate -S
Database /var/lib/mlocate/mlocate.db:9,400 directories130,149 files6,240,046 bytes in file names2,911,672 bytes used to store database
查找最近用的六个文件:
[root@localhost ~]# locate -l 6 passwd
/etc/passwd
/etc/passwd-
/etc/pam.d/passwd
/etc/security/opasswd
/usr/bin/gpasswd
/usr/bin/grub2-mkpasswd-pbkdf2查找 固定目录下的以a开头的文件
[root@localhost ~]# locate /root/a
/root/a.txt
/root/anaconda-ks.cfg
不能使用./相对路径
locate /a 具有什么含义?为什么通过这个命令查找出了不以a开头的文件?
locate a
为我所用:
此命令在查找以某个字母开头的文件和准确查找某个文件上比较出色。而且速度很快,但切记不能使用相对路径查找,效果不好。比如:locate ./a 但可以使用locate Desktop/a.txt这样的相对命令进行查找,这里不解。

find

使用find a.txt
只能查找到当前目录的文件,如果a.txt在下级目录,它是查不到的。所以默认是当前目录
find . a.txt
在当前目录及当前目录的子目录查找a.txt

加入其它属性
mtime
ctime
atime
以上三组是带time关键字,说明的是几天前。
mtime:modified,文件内容的修改。包括创建。
ctime:changed,文件状态被修改,比如权限。
atime:accessed 文件被访问。

1单选(1分)
如何在/tmp目录中查找过去24小时产生的,大小大于5k的普通文件并以不带提示的方式删除。
A.
find /tmp \(–type f -a -ctime -1 -a -size +5k \) -exec rm {} \;
B.
find /tmp \(–type f -a -mtime -1 -a -size +5k \) -exec rm {} \;
C.
find /tmp \(–type f -a -mtime -1 -a -size +5k \) -exec rm -f {} \;
D.
find /tmp \(–type f -a -ctime -1 -a -size -5k \) -exec rm -r {} \;

这道题比较综合,过去24h为一天,所以用time,且创建的这个文件,所以用m。而查找的文件类型为普通文件,所以选项-type为f,中间用-a逻辑符连接,最后运行rm命令,-f代表不带提示进行删除。never prompt。

[root@localhost ~]# find /home -mtime -2[root@localhost ~]# find . -perm 755
[root@localhost ~]# find / -type b
[root@localhost ~]# find . -type f -size 5k
[root@localhost ~]# find . -name 'a.txt'
./Desktop/a.txt
./a.txt
配合动作表达式:
find . -name '*.tmp' -exec rm{} \;

通配符

四种通配符:

  • ? [] {}
*  任意长度的字符
? 任意单个字符  如??sh
[] 中括号通配符内要求的是按照一定顺序且连续的字母或数字
[dennis@localhost ~]$ cp /tmp/file/file[1-3].txt .
中括号通配符的第二种形式:
[dennis@localhost ~]$ ls file[1,2,3].txt
大括号通配符内为字符串
[dennis@localhost ~]$ ls {file1,file2}.txt
file1.txt  file2.txt
!
[dennis@localhost ~]$ ls file[!1-2].txt
file3.txt

打包、压缩、文件查找、通配符相关推荐

  1. linux 打包压缩文件夹命令/压缩文件

    一.打包压缩 例子:把www.xx.com文件夹打包压缩xx.zip文件,并指定放到/www/wwwroot/www.xx.com/中 zip -r /www/wwwroot/www.xx.com/x ...

  2. nodejs tar 打包脚本,打包压缩文件文件夹

    用nodejs打包压缩文件 准备工作: nodejs npm i tar 安装 tar 包,用于打包压缩,命令类似 linux 下的 tar const fs = require('fs') cons ...

  3. 【Linux】Linux 如何打包压缩文件夹

    Linux打包压缩文件夹与我们平常用的Windows有点不一样,平常我们在Window下直接右击文件夹 - 添加到压缩文件就OK了. 我想说一下打包文件并不是压缩文件,什么是打包,就是将零散的东西放在 ...

  4. Linux 打包压缩-文件打包-打包工具【tar】命令使用简介

    tar 将许多文件一起保存至一个单独的磁带或磁盘归档,并能从归档中单独还原所需文件. 补充说明 tar命令 可以为linux的文件和目录创建档案.利用tar,可以为某一特定文件创建档案(备份文件),也 ...

  5. linux打包压缩文件并命名,linux下如何将文件打包、压缩并分割成制定大小

    将大文件或目录打包.压缩并分割成制定大小的文件,这在将数据备份到容量有限的移动储存设备时是必须的,在Linux下可以通过组合使用tar,bzip2(或者gzip),split命令来实现. 假设要将下面 ...

  6. 工作目录切换命令、打包压缩文件命令

    pwd命令显示当前工作目录,格式:"pwd[选项]" 参数                         作用 -p                              显 ...

  7. Linux基础命令-tar打包压缩文件

    Linux基础命令-echo输出信息_Linux学习中的博客-CSDN博客 Linux三剑客-grep命令_Linux学习中的博客-CSDN博客 Linux文件管理命令(3)-mv改动文件_Linux ...

  8. Linux 打包压缩-文件压缩-压缩工具【unzip】解压使用基本介绍

    unzip 用于解压缩由zip命令压缩的压缩包 补充说明 unzip命令 用于解压缩由zip命令压缩的".zip"压缩包. 语法 unzip(选项)(参数) 选项 -c:将解压缩的 ...

  9. python怎么打包压缩文件_Python打包文件夹的方法小结(zip,tar,tar.gz等)

    本文实例讲述了Python打包文件夹的方法.分享给大家供大家参考,具体如下: 一.zip import os, zipfile #打包目录为zip文件(未压缩) def make_zip(source ...

  10. python压缩文件夹为zip_python打包压缩文件夹zip+组装文件夹

    无意间想到的一个需求,然后就顺手写了写,留下来,方便以后用 列表版:(基本没用,仅提供思路,字典版稍微改动可以直接用) 大体需求: 把重复的文件名进行改名,达到浏览器下载相同文件的效果 下载完成后再把 ...

最新文章

  1. sys.stdout.write与sys.sterr.write(二)
  2. python语言依赖平台吗_在大型项目上,Python 是个烂语言吗?
  3. 关于Latex一个简单例子
  4. 人工智能与机器学习有哪些不同
  5. struts-execl.xml
  6. 信息流媒体变现_抖音信息流投放优势,为什么选择抖音信息流广告投放呢?
  7. 16个超牛逼的HTML5和JavaScript特效
  8. 华为软件测试工程职责,【什么是软件测试】华为2021年软件测试岗位职责-看准网...
  9. 华为软件测试笔试真题之变态逻辑推理题【二】华为爆火面试题
  10. 打印参数量GFLOPs等的参考链接暂存+pycocotools安装
  11. ADS,AXD基本使用说明
  12. 教你添加百度分享按钮
  13. windows操作系统32位与64位的含义
  14. Redhat克隆及其配置
  15. 微信连WiFi关注公众号流程更新 解决ios微信扫描二维码不关注就能上网的问题
  16. prometheus 配置服务器监控、服务监控、容器中服务监控与告警
  17. 清华最新发布的毕业生去向,太卷了吧!
  18. 数据分析师的就业前景如何?
  19. 人力资源管理中的大数据应用之道
  20. 2016{太原UI设计师}郭文军讲解UI设计版式

热门文章

  1. 优化:梯度下降法、牛顿法、共轭梯度法
  2. 手工接口测试考虑的点
  3. redis 之 sds (二) char []
  4. Technavio:大数据即服务将迎快速增长期
  5. Win10系列:UWP界面布局进阶1
  6. 解决 ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running?
  7. mysql 控制函数库_数据库开发——MySQL——函数与流程控制
  8. java 倾斜校正_简述Java图像倾斜方法及实例
  9. 带你3分钟学Python变量和数据类型
  10. 教你实现Vscode的Markdown预览