-
Notifications
You must be signed in to change notification settings - Fork 1
Tutorial 05
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 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.
Send a file from your local machine to a remote server:
$ scp file.txt username@to_host:/remote/directory/Download a file from a remote server to your local machine:
$ scp username@from_host:file.txt /local/directory/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 compresses individual files without losing any data.
Compress a file:
$ gzip filenameTo keep the original file while compressing, use:
$ gzip -k filenameBy convention, gzip-compressed files end with .gz or .z.
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.
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 dir3This results in a .tar.gz file — commonly used for backups or distributing software.
You’ve learned how to compress files — now let’s decompress them!
Uncompress .gz files:
$ gunzip filename.gz💡 Bonus:
vimcan open.gzfiles directly — no need to unzip first!
To extract .tar or .tar.gz files:
$ tar -xcvf file.tar.gzOptions:
-
x— extract the archive -
c— (used earlier for create; not needed here unless creating) -
v— verbose -
f— filename of archive
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!