Operating System Basics

Summary: Learning about CLI, BASH, ZSH, FISH, Obscure but useful commands, understanding Cron and Threads.


Command-Line Interfaces (CLI)

Piping in Unix or Linux

A pipe is a form of redirection (transfer of standard output to some other destination) that is used in Linux and other Unix-like operating systems to send the output of one command/program/process to another command/program/process for further processing. The Unix/Linux systems allow the stdout of a command to be connected to the stdin of another command. You can make it do so by using the pipe character ‘|’

List all files and directories and give them as input to `grep` command using piping in Linux

ls | grep file.txt

ref: https://www.geeksforgeeks.org/piping-in-unix-or-linux/

WP-CLI

WP-CLI is a command line interface for WordPress. The project’s goal is to offer a complete alternative to the WordPress admin; for any action you might want to perform in the WordPress admin, there should be an equivalent WP-CLI command.

$ wp plugin install akismet
$ wp plugin activate akismet
$ wp core download --path=wpclidemo.dev

ref: https://make.wordpress.org/cli/handbook/guides/quick-start/

Types of CLI

BASH

Bash (short for Bourne Again SHell) is a Unix shell, and a command language interpreter. A shell is simply a macro processor that executes commands. It’s the most widely used shell packaged by default for most Linux distributions, and a successor for the Korn shell (ksh) and the C shell (csh).

ref: https://www.freecodecamp.org/news/linux-command-line-bash-tutorial/

ZSH

zsh is a POSIX-compatible shell, and a popular alternative to the Bourne shell (sh) and bash.

Its key feature is a focus on a high level of customization by the user, which has led to an active community of developers creating extensions for zsh, including custom, more informative prompt status lines, often integrating with system services.

Many configurations with large sets of sensible defaults and useful extensions exist online, including the popular oh-my-zsh and prezto.

# Aliases
alias la="ls -a"

ref: https://riptutorial.com/zsh

FISH

Fish is a fully-equipped command line shell (like bash or zsh) that is smart and user-friendly. Fish supports powerful features like syntax highlighting, autosuggestions, and tab completions that just work, with nothing to learn or configure.

ref: https://fishshell.com/docs/current/tutorial.html

Obscure But Useful Commands

  • expr: perform arithmetic or boolean operations or evaluate regular expressions
  • m4: simple macro processor
  • yes: print a string a lot
  • cal: nice calendar
  • env: run a command (useful in scripts)
  • printenv: print out environment variables (useful in debugging and scripts)
  • look: find English words (or lines in a file) beginning with a string
  • cutpaste and join: data manipulation
  • fmt: format text paragraphs
  • pr: format text into pages/columns
  • fold: wrap lines of text
  • column: format text fields into aligned, fixed-width columns or tables
  • expand and unexpand: convert between tabs and spaces
  • nl: add line numbers
  • seq: print numbers
  • bc: calculator
  • factor: factor integers
  • gpg: encrypt and sign files
  • toe: table of terminfo entries

ref: https://github.com/jlevy/the-art-of-command-line

Cron

A cron job is a task created using cron, a tool for scheduling and automating future tasks on Unix-like operating systems.

# edit existing crontab file
crontab -e
# list cron tabs
crontab -l
# Perform a backup every Sunday at midnight.
0 0 * * 0 /root/backup.sh

ref: https://www.hostinger.com/tutorials/cron-job

Threads

A Thread also called lightweight process, is basic CPU utilization; it compromises a thread ID, a program counter, a register set, and a stack. A thread is an entity within a process that can be scheduled for execution.

If we want a process to be able to execute on multiple CPUs at a time, to take advantage of the multi-core systems, the process must have several execution-context called threads. A thread is an active entity which executes a part of a process. Multiple threads execute simultaneously with each other which results in the execution of a single whole process. 

Parallelization: In multi-processor architecturedifferent threads can execute different instructions at a time, which result in parallelization which speeds up the execution of the process.

Specialization: By specializing different threads to perform the different task, we can manage threads, for example, we can give higher priority to those threads which are executing the more important task. Also in multi-processor architecture specialization leads to the hotter cache which improves performance.

Efficient: Multi-threaded programs are more efficient as compared to multi-process programs in terms of resource requirement as threads share address space while process does not, so multi-process programs will require separate memory space allocation. Also, Multi-threaded programs incur lower overhead as inter-thread communication is less expensive.

ref: https://medium.com/@akhandmishra/operating-system-threads-and-concurrency-aec2036b90f8

«
»

Leave a Reply

Your email address will not be published. Required fields are marked *