Skip to content

Instantly share code, notes, and snippets.

@GeorgeTR1
GeorgeTR1 / tarex.sh
Created May 21, 2026 04:42
Safely extract tar files without polluting the current directory
#!/bin/sh
# usage: ./tarex.sh example.tar.gz
# will extract example.tar.gz, making sure it is always contained in a single
# directory in the current directory
# Keeps directory clean from "tar bombs" by creating a directory to extract the tar file into,
# and then only copying the results back to the current directory if there is only one file
# or directory, indicating that the results were contained in one directory