Skip to content

Instantly share code, notes, and snippets.

@anavdesign
Created January 19, 2019 20:06
Show Gist options
  • Save anavdesign/5686153535b286959efa6f8f9ffab0fc to your computer and use it in GitHub Desktop.
Save anavdesign/5686153535b286959efa6f8f9ffab0fc to your computer and use it in GitHub Desktop.
CLI: Compress/Uncompress

Compress/Decompress files via CLI

Resources

Flags create a new archive

-c, --create

verbosely list files processed

-v, --verbose

filter the archive through gzip

-z, --gzip

use archive file or device ARCHIVE

-f, --file=ARCHIVE

extract files from an archive

-x, --extract, --get

delete from the archive (not on mag tapes!)

--delete

Compress

# Tar files & folders
$ tar -cvzf NAME.tar.gz file1.ext file2.ext directory/

# Exclude Files & Folders
$ tar -czvf folder/NAME.tar.gz --exclude 'file/to/exclude.txt' --exclude 'folder/to-exclude' folder/to/tar

Uncompress

# Extract in current directory
$ tar -xvzf archive.tar.gz

# Extract in specified directory
$ tar -zxvf path/file.tar.gz -C /path/to/directory

# Choose directory name during untarring and remove first folder
$ tar -xvzf sql-dump/dev.tar.gz -C public_html/dev --strip-components 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment