Tips-And-Tricks/Computer/Linux/Shell-Commands
Linux is a growing and popular operating system, especially for us citizen mycologists, and unknown to a lot of first-time users, it has an extensive set of wonderful tools that can do things that are nearly black magic in Windows or even to the casual Macintosh user.
As a MacOS user, you too have access to most of these commands as well (surprisingly without having to pay an exhorberant fee to use them too!). Mac OS is based on an offshoot of the original AT&T Unix called BSD (Berkeley Software Distribution), and as such has most of the core shell commands at your disposal.
File Compression / Extraction
There are two main compression utilities out there that can take a directory and compress it all into a single file, allowing you to move it to another computer, either in your home or on the internet, and then extract it there. Depending on the source or destination computer may make the decision as to the best.
zip/unzip - Compatible with Micro$oft Windows since Windows XP tar - Compatible with Linux, or any Unix-compatible operating system, including macOS.
zip/unzip
Compression
The zip command packs files into a zip archive, which can be read on the host machine pretty much universally.
The general format is
zip [flags] destination[.zip] file list
Where the .zip extension is optional. To zip a list of files in the SAME directory, you can use
zip filename.zip file1 file2 file3 ...
To zip an entire directory structure you can use the "r" flag and it will descend through the whole structure adding everything found to the archive.
zip -r docs.zip Documents
Extraction
The unzip command does the opposite of zip and extracts files. It does have a set of flags you can use in special sitautions, but there is really only one important one in every day use
-l
The -l flag says to list the contents instead of actually extracting the files.
unzip -l zipfile.zip Will list all of the files in the archive
unzip zipfile.zip Will extract the files from the archive into the current directory
tar
The tar command basically operates the same as the zip command but can provide multiple types of compression. It stands for "Tape ARchive" and heralds from the early days when computers literally had reel-to-reel tapes.
tar [flags] archive [file1 file2 file3]
The most commonly used flags are:
cCreate the archivexExtract the archivevBe verbose (display the files extracted/added)f filenameFilename to create or extract fromzCompress using zlib (fast, decent compression)jCompress using bzip2 (medium speed, better compression)JCompress using xz (medium speed, good compression)
Please make sure to include a compression type when creating a tar archive. With no compression, it can take a huge amount of space with standard tar. Again, this is due to its origin in creating data for reel-to-reel tapes.
Working with a single file
Sometimes you may need to compress only a single file to reduce its size, like to transfer a video over the internet or something. There are several tools to do this with. As a general rule of thumb, the better the compression, the longer it takes to run. Although each command has uninque parameters that can be passed to it, in general the format is (tool) filename which will create filename.exstention .
| Name | Compression | Decompression | Speed | Compression Amount | Extension |
|---|---|---|---|---|---|
| GZip (Zlib) | gzip | gunzip | Fast | Medium/Low | .gz |
| Bzip2 | bzip2 | bunzip2 | Slow | High | .bz / .bz2 |
| Xz/LZW | xz | unxz | Medium/Slow | Exceptional | .xz |