Tips-And-Tricks/Computer/Linux/Shell-Commands: Difference between revisions

From Pikes Peak Myco Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 45: Line 45:
=== tar ===
=== tar ===


The <code>tar</code> 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.
The <code>tar</code> 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.


<code>tar [flags] archive [file1 file2 file3]</code>
<code>tar [flags] archive [file1 file2 file3]</code>
Line 52: Line 52:
* <code>c</code> Create the archive
* <code>c</code> Create the archive
* <code>x</code> Extract the archive
* <code>x</code> Extract the archive
* <code>v</code> Be verbose (display the files extracted / added)
* <code>v</code> Be verbose (display the files extracted/added)
* <code>f filename</code> Filename to create or extract from
* <code>f filename</code> Filename to create or extract from
* <code>z</code> Compress using zlib (fast, decent compression)
* <code>z</code> Compress using zlib (fast, decent compression)
* <code>j</code> Compress using bzip2 (medium speed, better compression)
* <code>j</code> Compress using bzip2 (medium speed, better compression)
* <code>J</code> Compress using xz (medium speed, good compression)
* <code>J</code> Compress 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 <code>(tool) filename</code> which will create filename.exstention .
{| class="wikitable"
|+ Common Compression Utilities
|-
! 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
|}

Revision as of 15:02, 28 February 2026

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:

  • c Create the archive
  • x Extract the archive
  • v Be verbose (display the files extracted/added)
  • f filename Filename to create or extract from
  • z Compress using zlib (fast, decent compression)
  • j Compress using bzip2 (medium speed, better compression)
  • J Compress 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 .

Common Compression Utilities
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