Support >
  About cybersecurity >
  Create a compressed file and extract it to a specified file in Linux
Create a compressed file and extract it to a specified file in Linux
Time : 2024-12-17 14:39:34
Edit : Jtti

In Linux, you can extract/extract.zip archive files to a specific or different directory. Zip is a simple cross-platform file packaging and compression utility for Unix-like operating systems, including Linux and Windows. The Zip format is a common archive file format used on Windows PCS and allows users to specify compression levels 1-9. Create a Zip archive file in Linux, package or compress the file with zip-r, and read the file directory structure recursively:

$ zip -r tecmint_files.zip tecmint_files

To extract the tecmint_files.zip archive file you just created, run the unzip command as follows.

$ unzip tecmint_files.zip

The above command unzips the file to the current working directory. To send the extracted files to a specific or different directory, use the dunzip command. Extract the contents of the.zip file into the /tmp directory:

$ mkdir -p /tmp/unziped

$ unzip tecmint_files.zip -d /tmp/unziped

$ ls -l /tmp/unziped/

RAR file is also a common compressed file format in Linux, which is widely used to efficiently store and share large amounts of data, and Linux itself also supports various compression formats. RAR is a common tool for creating and decompressing compressed file files, such as the need to use RAR tool to decompress files when downloading files in the network. RAR is available for free under Windows operating systems, but RAR tools are not pre-installed on Linux systems. To handle RAR files in Linux, you need to install RAR and UNRAR first, on Debian and Ubuntu-based distributions, you can easily install rar and unrar packages using apt-get or apt programs.

$ sudo apt-get install rar unrar

Or

$ sudo apt install rar unrar

With a RHEL-based distribution, you can install it using the dnf command or the yum command.

------------ On Fedora Linux ------------ 

$ sudo dnf install rar unrar        

------------ On RHEL-based Linux ------------

$ sudo yum install epel-release

$ sudo yum install rar unrar

On other popular Linux distributions, you can install using the default package manager.

$sudo emerge -a rar unrar [on Gentoo Linux]

$sudo apk add rar unrar [on Alpine Linux]

$sudo pacman -S rar unrar [on Arch Linux]

$sudo zypper install rar unrar [on OpenSUSE]

If your distribution does not provide rar and unrar packages, you will need to download the latest unrar/rar file and install it using the following commands.

--------------- --------------- on 64-bit

# cd /tmp

#

wget https://www.rarlab.com/rar/rarlinux-x64-700b2.tar.gz

# tar -zxvf rarlinux-x64-700b2.tar.gz

# cd rar

Cp # sudo -v rar unrar/usr/local/bin / -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- on the 32 bit -- -- -- -- -- -- -- -- -- -- # CD/TMP

# wget https://www.rarlab.com/rar/rarlinux-x32-700b2.tar.gz

# tar -zxvf rarlinux-x32-700b2.tar.gz

# cd rar

# sudo cp -v rar unrar /usr/local/bin/

To create RAR archive files in Linux, run the following commands and options, which will create archive files for the tecminta directory:

$ rar a tecmint.rar tecmint

With unrar installed in Linux, you can easily open or extract the current RAR directory contents:

$ unrar e tecmint.rar

To open/extract RARe files in a specific path or destination directory, use this option, which will extract all files in the specified destination directory.

$ unrar e tecmint.rar /home/tecmint/rarfiles

To open/extract a RAR file with its original directory structure, simply issue the following command with an x option, which will extract according to its folder structure.

$ unrar x tecmint.rar

To list the contents of a RAR file in Linux, you can use the unrar l command, which will display the list of files with their size, date, time, and permissions.

$ unrar l tecmint.rar

To check the integrity of RAR archive files, you can use the unrar t command, which will perform a full integrity check on each file to find errors and display the status of the file.

$ unrar t tecmint.rar

The unrar command only extracts, lists, or tests archive files. It does not have the option to create RAR files under Linux. So, here we need to install the RAR command line utility to create the archive file.

The rar d command is used to delete files from an existing RAR archive in Linux. The d option directly modifies the existing RAR archive by deleting the specified file.

$ rar d howtoing.rar randfile001 randfile002

In the above command, the randfile001 and randfile002 files will be deleted from the tecmint.rar RAR archive.

JTTI-Defl
JTTI-COCO
JTTI-Selina
JTTI-Ellis
JTTI-Eom