转发:CentOS下tar压缩排除某个文件夹或文件及解压
2023-09-11 14:19:21 时间
一、压缩
一般直接用tar命令打包很简单,直接使用 tar -zcvf test.tar.gz test 即可。
在很多时候,我们要对某一个目录打包,而这个目录下有几十个子目录和子文件,我们需要在打包的时候排除其中1、2个目录或文件。
这时候我们在用tar命令打包的时候,增加参数 --exclude 就能达到目的。
例如:
我们以tomcat 为例,打包的时候我们要排除 tomcat/logs 目录,命令如下:
tar -zcvf tomcat.tar.gz --exclude=tomcat/logs tomcat
如果要排除多个目录,增加 --exclude 即可,如下命令排除logs和libs两个目录及文件xiaoshan.txt:
tar -zcvf tomcat.tar.gz --exclude=tomcat/logs --exclude=tomcat/libs --exclude=tomcat/xiaoshan.txt tomcat
这里要说一下注意事项:
大家都知道linux在使用tab键的时候会对目录名称自动补全,这很方便,大家也比较常用。
如我们输入 tomcat/lo 的时候按tab键,命令行会自动生成 tomcat/logs/ ,对于目录,最后会多一个 “/”
这里大家要注意的时候,在我们使用tar 的--exclude 命令排除打包的时候,不能加“/”,否则还是会把logs目录以及其下的文件打包进去。
错误写法:
tar -zcvf tomcat.tar.gz --exclude=tomcat/logs/--exclude=tomcat/libs/tomcat
正确写法:
tar -zcvf tomcat.tar.gz --exclude=tomcat/logs --exclude=tomcat/libs tomcat
![](https://img2018.cnblogs.com/blog/15385/201903/15385-20190315094050941-364592333.png)
二、解压:
解压到当前目录下
tar -zxvf shop.tar.gz
解压到指定目录myshop
tar -zxvf shop.tar.gz -C myshop
相关文章
- 在 CentOS 7 CPanel 服务器上安装 MariaDB 10
- CentOS 7 常用软件安装
- Centos 6.x 安装 docker
- CentOS 6 IPv6 关闭方法
- centos下如何开放某个端口?
- PXE+kickstart无人值守安装CentOS 7
- 第8章 CentOS包管理详解
- Centos安装Gitea
- CentOS配置本地yum源(使用镜像iso文件)
- Linux-026-Centos Nginx 配置 pid 文件路径解决 service nginx status 提示:Can't open PID file /var/run/nginx.pid (yet?) after start: No such file or directory
- Linux-019-Centos Shell 安装 Nginx 后启动时提示找不到Lua模块的libluajit-5.1.so.2文件,具体提示信息:./nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory
- 转发:centos彻底删除文件夹、文件命令(centos 新建、删除、移动、复制等命令)
- Centos 7 文件和目录管理
- CentOS 使用官方源yum安装最新nginx版本
- CentOS 6.5 搭建NFS文件服务器
- 由于CentOS的系统安装了epel-release-latest-7.noarch.rpm 导致在使用yum命令时出现Error: xz compression not available问题
- linux家族:debian和CentOS
- centos运行asp.netcore的正确姿势
- Centos安装rpm包
- CentOS 安装 docker-compose
- 虚拟机中的centos在nat模式下连不上外网
- 在centos下解决 “致命错误:curses.h:没有那个文件或目录”
- Linux CentOS 开机报错
- centos 日志文件