Linux / Unix

Updated: 2020-12-29

Unix Philosophy

Do one thing and do it well.

"Everything is a file"

Probably the most important and defining feature of Unix. A text file is of course a file, but a directory is also a file, and a hard drive is a file, a mouse is a file, a socket is a file ...

This is super helpful for learners because everything you encounter would be a file and can be examined by commands like ls.

Flavors / Distros

macOS is actually a Unix system, originally branched off BSD.

Linux is another big branch of Unix, some of the popular flavors / distros that you may have heard of:

  • Debian / Ubuntu

    • Ubuntu is derived from Debian
    • Ubuntu is a very popular Desktop Linux; there are other popular distros built on top of Ubuntu, like Linux Mint
    • Both use apt as package manager.
  • RedHat / CentOS / Fedora

    • RHEL (Red Hat Enterprise Linux) is for enterprise use
    • CentOS was the open source version; discontinued in 2020; CentOS Stream is NOT a replacement of CentOS, but will be a rolling preview of what's next in RHEL
    • Fedora is the community version.
    • All use yum as package manager.
  • Gentoo / ChromeOS

    • ChromeOS was originally based on Debian, but later moved to Gentoo. (if you run lsb_release -a in ChromeOS's terminal you will see Debian instead, that is because the terminal and other linux programs are actually running containers inside a VM on KVM)
  • Android: yes Android is also based on Linux; however Google's new OS, Fuchsia, is not based on Linux, but a microkernel called Zircon.

Monolithic Kernel vs Microkernel

  • Microkernel provides the most basic functionalities: low-level address space management, thread management, IPC, etc.
  • Device drivers, file systems, protocol stacks are included in Monolithic kernels, but are NOT in Microkernels, instead they run in user mode.

Examples:

  • Linux is Monolithic
  • Google's Fuchsia, is based on a microkernel named Zircon. Fuchsia is NOT Linux.

Different From Windows

  • Unix uses / in file path, while Windows uses \
  • there's only one root directory /, so you cannot find C:\ or D:\; however other filesystems can be mounted

    $ mount # lists all mounts
    ...
    C:\ on /mnt/c type drvfs
    D:\ on /mnt/d type drvfs
  • Unix (or more precisely, the file systems like ext4) is case sensitive, a.txt and A.txt are two different files.

Standards: SUS vs POSIX vs LSB

These are all standards for operating system interfaces.

  • POSIX: Portable Operating System Interface
  • SUS: Single UNIX Specification
  • LSB: Linux Standard Base

POSIX and SUS converged after 2001.

  • macOS is POSIX-certified.
  • Linux is mostly POSIX-compliant. The LSB is based on the POSIX / SUS, and several other open standards, but extends them in certain areas.

Invoking Bash with the --posix option or stating set -o posix in a script causes Bash to conform very closely to the POSIX

Backward Compatibility

The Linux kernel community promised that no upgrade will ever break anything that is currently working in a previous release.

Other Tools

  • sed(stream editor) is for programmatically editing files based on lines.
  • awk is for text processing, especially useful for table-like text files like csv.