Linux unzip Complete Guide: From Extraction to Fixing Korean Character Encoding Issues

Overview

This guide introduces the basic usage and essential practical options of the unzip command, frequently used for extracting ZIP archives in Linux environments. Step-by-step instructions cover everything from previewing archive contents and extracting to specific directories to fixing broken character encodings for files created in Windows.

Installing the unzip Package and Preparing a Test Archive

To compress and extract archives in an Ubuntu environment, install the necessary packages using the sudo apt-get update -qq && sudo apt-get install -y unzip zip command.

sudo apt-get update -qq && sudo apt-get install -y unzip zip

Create a dedicated practice workspace and navigate into it using the mkdir -p ~/unzip-demo && cd ~/unzip-demo command.

mkdir -p ~/unzip-demo && cd ~/unzip-demo

Generate sample text and configuration files for testing with the echo 'Hello Linux' > file1.txt && echo 'Config Content' > config.cfg command.

echo ‘Hello Linux’ > file1.txt && echo ‘Config Content’ > config.cfg

Bundle the sample files into a single archive by running the zip -r sample.zip file1.txt config.cfg command.

zip -r sample.zip file1.txt config.cfg

Previewing Contents Without Extracting (unzip -l)

Navigate to the working directory where the test files are located using the cd ~/unzip-demo command.

cd ~/unzip-demo

The unzip -l sample.zip command allows you to inspect the list of files, sizes, and modification dates inside the archive without actually decompressing it.
This is particularly useful for safely reviewing the internal structure and estimating disk space requirements before extracting large archives.

unzip -l sample.zip

Extracting to a Specific Directory and Overwrite Control (unzip -d, -o)

Navigate to the working directory where the archive is located using the cd ~/unzip-demo command.

cd ~/unzip-demo

Create a target destination directory to store the extracted files using the mkdir -p ./extracted command.

mkdir -p ./extracted

The unzip sample.zip -d ./extracted command extracts the contents of the archive file into the ./extracted directory specified by the -d option.
This keeps your current working directory clean and organized by placing files exactly where intended.

unzip sample.zip -d ./extracted

The unzip -o sample.zip -d ./extracted command extracts files while forcibly overwriting existing files without prompting for confirmation.
This is commonly used in shell scripts or automated deployment environments to prevent execution hangs caused by interactive overwrite prompts.

unzip -o sample.zip -d ./extracted

Verify the file list and detailed attributes to confirm that extraction completed successfully using the ls -la ./extracted command.

ls -la ./extracted

Extracting Specific Files Selectively

Navigate to the working directory where the archive is located using the cd ~/unzip-demo command.

cd ~/unzip-demo

Create a destination directory to store the selectively extracted files using the mkdir -p ./selective command.

mkdir -p ./selective

The unzip sample.zip file1.txt -d ./selective command extracts only the specified file1.txt file instead of decompressing the entire archive.
This is extremely useful when you only need to retrieve a specific configuration file or log file from a large archive quickly.

unzip sample.zip file1.txt -d ./selective

Check the file list and detailed attributes in the destination directory using the ls -la ./selective command to verify that only the targeted file was extracted.

ls -la ./selective

Preventing Broken Korean Filename Encodings from Windows Archives (unzip -O CP949)

Navigate to the working directory containing the archive using the cd ~/unzip-demo command.

cd ~/unzip-demo

Create a destination directory to safely store the extracted files using the mkdir -p ./korean-test command.

mkdir -p ./korean-test

The unzip -O CP949 sample.zip -d ./korean-test command specifies CP949 (EUC-KR), the default Windows character encoding, extracting the archive into ./korean-test without filename corruption.
This cleanly resolves the mojibake / broken filename issues that arise from character set differences between Windows and Linux systems.

unzip -O CP949 sample.zip -d ./korean-test

Confirm that the files have been properly extracted in the target directory by running the ls -la ./korean-test command.

ls -la ./korean-test

We have covered essential tips for the unzip command in Linux, from basic extraction to handling non-UTF-8 encoding issues.
Make good use of these options to efficiently handle archives in the terminal without encoding headaches.