LinuxCommandLibrary

unp

Unpack archives with automatic file type detection

TLDR

Extract an archive

$ unp [path/to/archive.zip]
copy

Extract multiple archives
$ unp [path/to/archive1.tar.gz] [path/to/archive2.rar]
copy

SYNOPSIS

unp [ -d | --nodir ] [ -f | --force ] [ -t | --test ] [ -v | --verbose ] [ -h | --help ] [ -V | --version ] ARCHIVE [ ARCHIVE ... ]

PARAMETERS

-d, --nodir
    Prevents unp from creating a new directory for the unpacked files. Files will be extracted directly into the current working directory.

-f, --force
    Forces the extraction, potentially overwriting existing files without prompting. The exact behavior depends on the underlying unpacker.

-t, --test
    Tests the integrity of the specified archive(s) without actually extracting their contents. Useful for verifying downloads.

-v, --verbose
    Increases the verbosity of the output, showing more details about the unpacking process, including which underlying command is being invoked.

-h, --help
    Displays a brief help message with command usage and available options.

-V, --version
    Shows the version information for the unp script.

DESCRIPTION

The unp command is a highly convenient shell script designed to simplify the process of unpacking various archive file formats. Instead of requiring users to remember and manually invoke different utilities like tar, unzip, 7z, or rar based on the archive's type, unp intelligently detects the format and calls the appropriate underlying unpacker. This makes it a powerful wrapper, streamlining file extraction.

unp supports a wide range of common archive types including, but not limited to, .zip, .tar, .tar.gz, .tar.bz2, .tar.xz, .7z, .rar, .deb, .rpm, .iso, and many more. By default, it creates a new directory named after the archive (excluding the extension) and extracts all contents into it, maintaining a clean filesystem. This automatic directory creation helps prevent clutter in the current working directory, especially when extracting archives that contain multiple files or subdirectories directly in their root. It's an indispensable tool for users who frequently deal with diverse compressed files.

CAVEATS

unp relies heavily on the presence and proper functioning of various underlying unpacking utilities (e.g., unzip, tar, 7z, rar). If a specific unpacker required for an archive type is not installed on the system, unp will fail to extract that archive.

While convenient, it offers less control than directly using the native unpacking tools; for very specific or advanced extraction needs (e.g., extracting only certain files, password-protected archives without prompts, or specific compression levels), it is often more robust to use the dedicated utility. Its error handling is generally dependent on the underlying utility's output.

DEFAULT EXTRACTION BEHAVIOR

By default, unp creates a new directory in the current working directory, named after the archive file (without its extension), and extracts all contents into this newly created directory. This behavior helps maintain a clean filesystem by preventing extracted files from cluttering the directory where the archive was located.

ARCHIVE TYPE DETECTION

unp intelligently attempts to determine the type of the archive file. It primarily relies on the file's extension (e.g., .zip, .tar.gz, .7z) but may also inspect the file's 'magic number' (initial bytes) to correctly identify the format and invoke the corresponding unpacking utility.

HISTORY

The unp command emerged as a part of the debian-goodies package, primarily developed for Debian-based Linux distributions. Its inception was driven by the common user frustration of having to remember and use a multitude of different commands to unpack various archive formats.

As a shell script wrapper, it was designed to abstract away the complexity of file decompression, providing a single, unified interface for a wide array of archive types. Its development reflects a focus on user convenience and accessibility, making file management simpler for casual and advanced users alike by intelligently delegating tasks to the appropriate backend utilities.

SEE ALSO

tar(1), unzip(1), 7z(1), unar(1), gzip(1), bzip2(1), xz(1), cpio(1), rar(1)

Copied to clipboard