linux-压缩解压缩-tar-gz-zip
tar文件
# 压缩某个位置文件夹为tar.gz文件
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file
# 解压缩到某个文件夹位置
tar -xf archive.tar.gz -C /home/linuxize/files
How to Extract (Unzip) Tar Gz File
https://linuxize.com/post/how-to-extract-unzip-tar-gz-file/
使用-C参数,指定解压到某个文件夹位置。
By default, tar will extract the archive contents in the current working directory . Use the --directory (-C) to extract archive files in a specific directory:
tar -xf archive.tar.gz -C /home/linuxize/files
How to Compress and Extract Files Using the tar Command on Linux
https://www.howtogeek.com/248780/how-to-compress-and-extract-files-using-the-tar-command-on-linux/
压缩tar.gz文件
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file
- -c: Create an archive.
- -z: Compress the archive with gzip.
- -v: Display progress in the terminal while creating the archive, also known as “verbose” mode. The v is always optional in these commands, but it’s helpful.
- -f: Allows you to specify the filename of the archive.
其他tar选项
https://www.howtogeek.com/248780/how-to-compress-and-extract-files-using-the-tar-command-on-linux/
- Compress Multiple Directories or Files at Once
tar -czvf archive.tar.gz /home/ubuntu/Downloads /usr/local/stuff /home/ubuntu/Documents/notes.txt
- Exclude Directories and Files
tar -czvf archive.tar.gz /home/ubuntu --exclude=/home/ubuntu/Downloads --exclude=/home/ubuntu/.cache
tar -czvf archive.tar.gz /home/ubuntu --exclude=*.mp4
- Compress Use bzip2 Compression Instead
tar -cjvf archive.tar.bz2 stuff
- Extract an Archive
解压缩
tar -xzvf archive.tar.gz -C /tmp
If the file is a bzip2-compressed file, replace the “z” in the above commands with a “j”.
gz文件
# 解压缩gz文件
gzip -d filename.gz
Unpacking or uncompressing gz files under Linux and UNIX systems
https://www.cyberciti.biz/faq/unpacking-or-uncompressing-gz-files/*
Decompressing gz files
The procedure is as follows for Linux, macOS and Unix users:
Open the terminal application. For remote systems use the ssh command for log in purposes To decompress .gz files, use:
gzip -d filename.gz
One can unzip and open gz file using:
gunzip archive.gz
For .tar.gz/.tgz file try the tar command:
tar -xvf archive.tar.gz
Run the ls command to list the files.
Keep the file when unpacking
You can keep input files during compression or decompression. In other words, don’t delete the file by passing the -k options to the gzip:
$ gzip -d -k file.gz
$ ls -l file*
zip文件
批量unzip 报错 caution: filename not matched
批量unzip需要使用引号, 不然直接执行unzip *.zip无法识别到批量的zip文件.
unzip '*.zip'
遇到的问题跟这个文章一模一样
https://www.cyberciti.biz/faq/linux-unix-shell-unzipping-many-zip-files/
tgz文件
# 解压缩tgz文件到某个文件夹
tar zxvf /path/to/archive.tgz -C /path/to/dest/dir1
unpacking and extracting .tgz files on Linux and Unix-like systems
https://www.cyberciti.biz/faq/unpack-tgz-linux-command-line/
## instead of short option
tar zxvf /path/to/archive.tgz
tar zxvf /path/to/archive.tgz -C /path/to/dest/dir1
## you can use long options ##
tar --gzip --extract --verbose --file=/path/to/archive.tgz
tar --gzip --extract --verbose --file=/path/to/archive.tgz --directory=/path/to/dest/dir1/
jar文件
jar xf xxx.jar
解压后,配置文件在这个位置vim BOOT-INF/classes/application.properties
解压jar包查看配置文件
[root@tdata-service-1 platform-service]# ls
log start_service.sh dodata-tdata-service.jar
[root@tdata-service-1 platform-service]# jar xf dodata-tdata-service.jar
Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/local/skywalking/agent/skywalking-agent.jar
DEBUG 2022-12-16 16:10:52:912 main AgentPackagePath : The beacon class location is jar:file:/usr/local/skywalking/agent/skywalking-agent.jar!/org/apache/skywalking/apm/agent/core/boot/AgentPackagePath.class.
INFO 2022-12-16 16:10:52:914 main SnifferConfigInitializer : Config file found in /usr/local/skywalking/agent/config/agent.config.
[root@tdata-service-1 platform-service]# ls
BOOT-INF META-INF log org start_service.sh dodata-tdata-service.jar
# 可以看到所有的依赖jar包
[root@tdata-service-1 platform-service]# ls BOOT-INF/lib/
HdrHistogram-2.1.12.jar druid-1.1.22.jar jetty-server-9.4.45.v20220203.jar simpleclient-0.12.0.jar
HikariCP-4.0.3.jar druid-spring-boot-starter-1.1.22.jar jetty-servlet-9.4.45.v20220203.jar simpleclient_common-0.12.0.jar
LatencyUtils-2.0.3.jar ehcache-2.10.9.2.jar jetty-servlets-9.4.45.v20220203.jar simpleclient_pushgateway-0.9.0.jar
# 可以看到所有的配置文件
[root@tdata-service-1 platform-service]# ls BOOT-INF/classes
application-exp.properties biz-default-params.properties com init_sql_2020_1215.sql init_sql_20210826_JC180.sql init_sql_20211022_JC191.sql init_sql_2022-12_05.sql log start_service.sh dodata_role_opt_demo.json
application.properties bootstrap.yml init_sql.sql init_sql_20210813_JC170.sql init_sql_20210917_JC190.sql init_sql_2021_0127.sql init_sql_20220126_JC0.sql log4j2.component.properties dodata_role_opt.json
# 可以发现打包的是exp配置文件, 而不是dev文件.
[root@tdata-service-1 platform-service]# cat BOOT-INF/classes/application-exp.properties
#DANGER! include production configs at the end!
Extracting the Contents of a JAR File
https://docs.oracle.com/javase/tutorial/deployment/jar/unpack.html
The basic command to use for extracting the contents of a JAR file is:
jar xf jar-file [archived-file(s)]
Let's look at the options and arguments in this command:
- The x option indicates that you want to extract files from the JAR archive.
- The f options indicates that the JAR file from which files are to be extracted is specified on the command line, rather than through stdin.
- The jar-file argument is the filename (or path and filename) of the JAR file from which to extract files.
- archived-file(s) is an optional argument consisting of a space-separated list of the files to be extracted from the archive. If this argument is not present, the Jar tool will extract all the files in the archive.
- As usual, the order in which the x and f options appear in the command doesn't matter, but there must not be a space between them.