Skip to content

Tutorial 05

Lee Burton edited this page Jul 13, 2025 · 2 revisions

📤📥 Sending, Receiving & Compressing Files

This tutorial covers the basics of sending and receiving files using Linux.
The primary tool is scp for secure file transfer, and you'll also learn how to compress and decompress files to save space and speed up transfers.


🔐 SCP – Secure Copy

scp stands for Secure Copy. It's available by default on most Unix/Linux systems and allows you to transfer files between:

  • your local computer and a remote server
  • two remote servers

You'll need a valid username and password on the remote machine.


⬆️ Upload from Your Computer

Send a file from your local machine to a remote server:

$ scp file.txt username@to_host:/remote/directory/

⬇️ Download to Your Computer

Download a file from a remote server to your local machine:

$ scp username@from_host:file.txt /local/directory/

🗜️ File Compression

When working with large datasets or multiple files, it's common to compress them to save disk space and speed up transfer times.

Here are some commonly used compression tools:


📦 Gzip

gzip compresses individual files without losing any data.

Compress a file:

$ gzip filename

To keep the original file while compressing, use:

$ gzip -k filename

By convention, gzip-compressed files end with .gz or .z.


🎁 Tar – Archive Multiple Files

tar stands for tape archive. It's used to bundle multiple files or directories into a single archive.

Bundle a directory called EXAMPLE:

$ tar -cvf EXAMPLE.tar EXAMPLE/

Options:

  • c — create a new archive
  • v — verbose (print progress to screen)
  • f — specify filename

You can name the output .tar file whatever you like.


🧙‍♂️ Tar + Gzip = Tarball

Combine tar and gzip in one command to create a compressed archive (aka a tarball):

$ tar -zcvf file.tar.gz /path/to/file
$ tar -zcvf file.tar.gz /path/to/dir/
$ tar -zcvf file.tar.gz dir1 dir2 dir3

This results in a .tar.gz file — commonly used for backups or distributing software.


📂 File Decompression

You’ve learned how to compress files — now let’s decompress them!


💨 Gunzip

Uncompress .gz files:

$ gunzip filename.gz

💡 Bonus: vim can open .gz files directly — no need to unzip first!


📤 Untar – Extract Tarballs

To extract .tar or .tar.gz files:

$ tar -xcvf file.tar.gz

Options:

  • x — extract the archive
  • c — (used earlier for create; not needed here unless creating)
  • v — verbose
  • f — filename of archive

🎉 Congratulations!

You’ve now mastered file transfer with scp and learned how to compress and decompress files using gzip, tar, and gunzip! 🧠🗂️

➡️ Next up: Tutorial 6 – Keep going!

Clone this wiki locally