SSH Command in Linux with examples

Archives and compression commands in Linux

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

#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