centos extract官方文档
Note: CentOS does not include an official extract command by default. The term “extract” typically refers to using standard command-line tools like tar, unzip, or 7z for decompressing files. Below is a consolidated guide to common extraction tasks in CentOS, based on official documentation and community best practices.
Common Extraction Tools in CentOS
CentOS relies on the following tools for handling compressed files:
tar: For.tar,.tar.gz,.tar.bz2,.tar.xz(and othertar-based formats).unzip: For.zipfiles.7z: For.7zfiles (requires installation viayumordnf).
1. Using tar for Tar-Based Archives
tar is the most versatile tool for extracting tar-based archives (common in CentOS repositories and software bundles).
Basic Syntax
tar -xvf <
archive_name>
.tar[.gz|.bz2|.xz] [-C <
target_directory>
]
-x: Extract files.-v: Verbose mode (shows extracted files).-f: Specifies the archive file name.-C: Optional; sets the target directory for extraction.
Examples
- Extract a
.tarfile (no compression):tar -xvf archive.tar - Extract a
.tar.gzfile (gzip-compressed):tar -xzvf archive.tar.gz - Extract a
.tar.bz2file (bzip2-compressed):tar -xjvf archive.tar.bz2 - Extract to a specific directory (e.g.,
/opt/myapp):tar -xzvf archive.tar.gz -C /opt/myapp
View Archive Contents Without Extracting
tar -tzvf archive.tar.gz # For .tar.gz files
tar -tjf archive.tar.bz2 # For .tar.bz2 files
2. Using unzip for ZIP Files
For .zip archives (common in cross-platform scenarios), install unzip first if not available:
sudo yum install unzip
Basic Syntax
unzip <
archive_name>
.zip [-d <
target_directory>
]
-d: Optional; sets the target directory.
Examples
- Extract a
.zipfile to the current directory:unzip archive.zip - Extract to a specific directory (e.g.,
~/downloads):unzip archive.zip -d ~/downloads
3. Using 7z for 7z Files
For .7z archives (high-compression format), install the p7zip package:
sudo yum install p7zip p7zip-plugins
Basic Syntax
7z x <
archive_name>
.7z [-o<
target_directory>
]
x: Extract with full paths.-o: Optional; sets the target directory (no space after-o).
Example
- Extract a
.7zfile to the current directory:7z x archive.7z - Extract to a specific directory (e.g.,
/tmp):7z x archive.7z -o/tmp
Key Notes
- Permissions: Use
sudofor extraction to system directories (e.g.,/usr/local) if you encounter permission errors. - Overwrite Protection: By default, tools like
tarandunzipwill prompt before overwriting existing files. Use-f(force) withtarto overwrite silently (e.g.,tar -xzf archive.tar.gz -C /opt/myapp --overwrite). - Excluding Files: With
tar, use--excludeto skip specific files/directories (e.g.,tar -xzvf archive.tar.gz --exclude='*.log').
For advanced use cases (e.g., extracting specific files from an archive), refer to the tool’s man pages:
man tar
man unzip
man 7z
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: centos extract官方文档
本文地址: https://pptw.com/jishu/734425.html
