SSH Command in Linux with examples

Archives and compression commands in Linux

Pack many files into one, and make big files small.

Watch: How to Zip, Unzip & Extract tar.gz Files in Linux (Beginner Guide)

Read the video transcript

Archives bundle many files into one, and compress them to save space. In this video, you'll learn tar, gzip and zip: how to create them, look inside them, and unpack them. All live, on a real Ubuntu server, with SSH Command. We're connected, with the Shell view open. tar creates an archive. -c means create, -z compresses it with gzip, and -f names the file. So tar -czf site.tar.gz site packs the whole site folder into one small file. To look inside without unpacking, use -t, for list. tar -tzf shows every file in the archive. To unpack, use -x, for extract. -C chooses the destination folder. Make a folder called restore, extract into it, and the whole site is back. gzip compresses a single file. -k keeps the original, otherwise gzip replaces it. Here numbers.txt shrinks to about a third of its size. gunzip reverses it. zip makes the files that Windows and macOS open directly. -r includes folders, and -q keeps the output quiet. unzip -l lists what's inside, and unzip on its own extracts. Use tar.gz on Linux servers, and zip when you share files with people on Windows or Mac. And in SSH Command, the search bar lists these commands with their options. Type tar, and copy one. That's archives: tar for bundling folders, gzip for single files, and zip for sharing with Windows and Mac. The full guide is at sshcommand.com, under archive commands. SSH Command is free for personal use. The link is in the description. Thanks for watching.

#tar

Pack and unpack archives

Syntaxtar [options] archive [files]
  • tar -czvf backup.tar.gz /var/www

    Create a compressed archive (c = create, z = gzip, v = show files, f = file name)

  • tar -xzvf backup.tar.gz

    Extract it (x = extract)

  • tar -xzvf backup.tar.gz -C /tmp/restore

    Extract into a chosen folder

  • tar -tzvf backup.tar.gz

    List the contents without extracting

  • tar -cJf logs.tar.xz logs/

    Smaller archive using xz

#gzip / gunzip

Compress one file

Syntaxgzip file
  • gzip big.log

    Replace it with big.log.gz

  • gunzip big.log.gz

    Restore it

  • gzip -k big.log

    Keep the original too

#zip / unzip

Windows-style zip files

Syntaxzip archive files | unzip archive
  • zip -r site.zip site/

    Zip a folder

  • unzip site.zip -d /tmp/site

    Extract into a folder

  • unzip -l site.zip

    List what is inside

#bzip2 / xz

Stronger compression

Syntaxxz file
  • xz -9 data.sql

    Very small, slower

  • unxz data.sql.xz

    Decompress

#zcat / zgrep

Read compressed files

Syntaxzcat file.gz
  • zcat access.log.2.gz | less

    Read a rotated log without unpacking

  • sudo zgrep "error" /var/log/syslog.*.gz

    Search inside compressed logs

Run these commands with SSH Command

SSH Command is a desktop app for Mac, Windows and Linux that puts a real terminal, SFTP file panes, a sudo switch and a searchable Linux command finder in one window. Type what you want to do, and send the command to your server with one click.

Download free Windows commands with examples SFTP & FTP client