Click to share! ⬇️

Linux is an open-source operating system for computers, servers, mainframes, mobile devices, and embedded devices. Linux is among the most widely supported operating systems, as it is available on almost every major computer platform, including x86, ARM, and SPARC.

Several Linux OS versions are available: each version manages hardware resources, launches and handles applications, and provides some user interface. Linux has been used for web servers, network operations, specific computing tasks, running databases, endpoint computing, and running mobile devices with OS versions like Android.

Intro to Linux

Linux is an open-source operating system (OS). An operating system is Software that directly manages hardware and resources, like CPU, memory, and storage. The OS sits between applications and hardware and connects all of your Software and the physical resources that do the work.

Linux Is Open-Source

Because Linux is released under an open source license, which prevents restrictions on the use of the Software, anyone can run, study, modify, and redistribute the source code or even sell copies of their modified code, as long as they do so under the same license.

The Linux Kernel

The Linux kernel is the main component of a Linux operating system (OS) and is the core interface between a computer’s hardware and its processes. It communicates between the 2, managing resources as efficiently as possible.

The Linux Shell

The shell is the Linux command line interpreter. It provides an interface between the user and the kernel and executes programs called commands. For example, if a user enters ls, then the shell executes the ls command.

What Is A Linux Distribution

A Linux distribution — often shortened to “Linux distro” — is a version of the open-source Linux operating system that is packaged with other components, such as installation programs, management tools, and additional Software such as the KVM hypervisor.

Ubuntu Linux

Ubuntu is a Linux distro based on Debian. It is suitable for cloud computing, servers, desktops, and internet of things (IoT) devices. The main difference between Linux and Ubuntu is that the former is an operating system family based on Unix, while Ubuntu is a Linux distribution.

Main Functions of a Computer

Taking data and instructions from a user, processing the data as per instructions, and displaying or storing the processed data, are the four primary functions of a computer. These are also the input, process, output, and storage functions.

The Operating System

An operating system (OS) is a program that, after being initially loaded into the computer by a boot program, manages all of the other application programs in a computer. The application programs use the operating system to make requests for services through a defined application program interface (API).

Ubuntu Linux vs. Other OS

Ubuntu is a Linux-based Operating System and belongs to the Debian family of Linux. As it is Linux based, it is freely available for use and is open source. It was developed by a team called Canonical and led by Mark Shuttleworth.

Pre-Installed Ubuntu Apps

Ubuntu has a rich set of applications involved by default. Some of these include: aisleriot, apport-gtk, apturl-common, at-spi2-core, baobab, cheese, deja-dup, eog, evince, evolution-data-server, file-roller, firefox, gcr, gdm3, gedit, geoclue-2.0, gkbd-capplet, gnome-bluetooth, gnome-calculator, gnome-calendar, gnome-characters, gnome-control-center, gnome-disk-utility, gnome-font-viewer, gnome-initial-setup, gnome-keyring, gnome-logs, gnome-mahjongg, gnome-mines, gnome-power-manager, gnome-screenshot, gnome-session-canberra, gnome-settings-daemon, gnome-shell, gnome-startup-applications, gnome-sudoku, gnome-system-monitor, gnome-terminal, gnome-todo, gnome-todo-common, ibus, ibus-table, im-config, info, language-selector-gnome, libatk-adaptoramd64:, libcanberra-gtk3-moduleamd64:, libreoffice-calc, libreoffice-common, libreoffice-draw, libreoffice-impress, libreoffice-math, libreoffice-writer, mutter, nautilus, network-manager-gnome, orca, printer-driver-foo2zjs-common, pulseaudio, python3.8, remmina, rhythmbox, rygel, seahorse, shotwell, simple-scan, snapd, software-properties-gtk, speech-dispatcher, spice-vdagent, system-config-printer, thunderbird, totem, tracker, tracker-extract, tracker-miner-fs, transmission-gtk, ubuntu-report, ubuntu-session, ubuntu-settings, update-manager, update-notifier, usb-creator-gtk, vim-common, vino, xbrlapi, xdg-desktop-portal-gtk, xdg-user-dirs, xdg-user-dirs-gtk, and yelp.

How To Install Apps To Ubuntu

An application is Software that has a graphical user interface (GUI). The Ubuntu development team has chosen a default set of applications that we think makes Ubuntu very useful for most day-to-day tasks. However, you will certainly want to install more applications to make Ubuntu more useful to you. To install an application, you can use Ubuntu Software.

Applications are available in two formats: snap packages and Debian packages. An application known as a snap package is now called a snap. Some applications are available in both formats. In such a case in Ubuntu Software, Ubuntu will list the snap first.

  • Click the Ubuntu Software icon in the Dock, or search for Software in the Activities search bar.
  • When Ubuntu Software launches, search for an application, or select a category and find an application from the list.
  • Select the application that you want to install and click Install.

You will be asked to authenticate by entering your password. Once you have done that, the installation will begin. The installation usually finishes quickly but could take a while if you have a slow Internet connection.

Ubuntu Linux Server Applications

Ubuntu is a server platform that anyone can use for the following and much more:

  • Websites. You can run any website by setting up a LEMP Stack.
  • FTP. Set up your file-sharing server by installing FTP software on your Ubuntu Server.
  • Email server. You can use Postfix as your email server for a small or medium-sized company.
  • File and print server. Another everyday use of Samba is configuring it to share printers installed, either locally or over the network, on an Ubuntu server.
  • Development platform. Ubuntu provides a common platform for development, testing, and production environments.
  • Container deployment. Containers run best on Ubuntu because it has more modern Linux kernels and the latest tooling for the fast-moving Docker, K8s, and LXD communities.
  • Cloud services. Ubuntu makes an excellent platform for custom SaaS cloud service offerings.
  • Database server. Ubuntu is designed to run MySQL, a fast, multi-threaded, multi-user, and robust SQL database server. It is intended for mission-critical, heavy-load production systems.

Linux Documentation Resources

The man command in Linux displays the user manual of any command we can run on the terminal. In addition, you can use popular search engines to find anything you need to know about Linux.

Linux Compression Utilities

The compression of a file reduces its size. Linux Bash provides many utilities to compress and decompress files, including gzip, bzip2, and xz. Files compressed with these commands have the extensions .gz, .bz2, and .xz, respectively.

To compress, run <compression_utility> <file_name>.
To decompress, include the -d option: <compression_utility> -d <compressed_file_name>.

Gzip also supports the -r option to compress all files in a directory.

Compress all `.mp3` files in current directory using `gzip`.
```
gzip *.mp3
```

Compress all files in the `music` directory using `gzip`.
```
gzip -r music/
```

Decompress a compressed file using `bzip2`
```
bzip2 -d wallpaper.png.bz2
```

How To Archive With Linux

Archiving consolidates multiple files together into one file for more accessible storage and portability. Linux Bash has two commands for archiving and extracting files: zip and tar.
zip tar
Archive zip <archive_name>.zip <file1> <file2>.. tar -cf <archive_name>.tar <files or directory>
Extract unzip <archive_name>.zip tar -xf <archive_name>.tar

In Linux environments, tar is preferred as a file extension because a tarball can retain important metadata like file permissions.

Archiving the directory `aws_docs` using `zip`
```
zip aws_docs.zip -r aws_docs/
```

Archiving files using `tar`
```
tar -cf tutorials.tar python.txt php.txt
```

Compressing Archive Files

The zip bash command automatically compresses archived files, while tar can be combined with compression utilities like gzip, bzip2, and xz. Administrators must use specific options for tar to match the compression command.

Here is the list of tar options:

-c : Creates an archive
-x : Extracts an archive
-f : Creates an archive with given filename
-z : Compress using gzip. Resulting file extension: .tar.gz.
-j : Compress using bzip2. Resulting file extension: .tar.bz2.
-J : Compress using xz. Resulting file extension: .tar.xz.

Linux Network Commands

The Linux shell has many commands to manage and communicate with networks.

ifconfig – Configure a network interface
ip – IP Routing, device configuration, policy routing, and tunnels
traceroute – Trace the route to a network host
tracepath – Trace the network path to a remote host
ping – Send ICMP ECHO_REQUEST packets to network hosts
netstat – Display network connections, routing tables, interface statistics, masquerade connections, and multicast memberships
ss – Utility to investigate sockets
dig – DNS lookup utility
nslookup – Query Internet name servers interactively
route – Display and manipulate the IP routing table
host – DNS lookup utility
arp – Manipulate the system ARP cache
iwconfig – Configure a wireless network interface
hostname – Set/show the hostname or domain name
curl or wget – Transfer a URL
mtr – combines the functionality of the ‘traceroute’ and ‘ping’ programs in a single network diagnostic tool
whois – Client for the whois directory service
ifplugstatus – Check if a network interface is plugged in
iftop – Display an interface’s bandwidth usage
tcpdump – Dump traffic on a network

How To Download a File in Linux

Two Linux terminal commands, curl and wget, can access, download a file from the internet, and even upload a file. Either of the following commands establishes a connection with a server and downloads either the HTML of a webpage or a file stored at the URL to the current working directory.

$ curl -O <URL>
$ wget <URL>

Bash Scripts

A Bash script is a plain text file that contains a series of commands. These commands are a mixture of commands we usually type on the command line. System admins can put anything you can typically run on the command line into a script, which will do the same thing. Similarly, anything you can put into a script can also run generally on the command line, which will do precisely the same.

Bash Script Variables

Arguments passed to a script are processed in the same order they’re sent. The indexing of the arguments starts at one, and the script can access the first argument inside the script using $1. Similarly, the second argument can be accessed using $2, and so on. The positional parameter refers to this representation of the arguments using their position.

#!/bin/bash

# bash example of variables and arguments

# variables
# $0 is the name of the script
# $1 is the first argument
# $2 is the second argument
# $3 is the third argument

echo "The name of the script is $0"
echo "$1 $2 $3"
% bash test.sh this is cool
The name of the script is test.sh
this is cool

read Keyword

Programmers can use the read command to prompt the user for input. It will continue to read user input until the Enter key is pressed.

Some prompt text can be specified using -p with the read command.

#!/bin/bash

echo "The script is now running."

read -p "Please enter your name: " name

echo "Hello $name, nice to meet you!"
% bash test.sh
The script is now running.
Please enter your name: Mr. Penguin
Hello Mr. Penguin, nice to meet you!

Bash Shebang

Bash scripts start with the #! Characters and the path to the Bash interpreter. This sequence of characters (#!) is called shebang and is used to tell the operating system which interpreter to use to parse the rest of the file.

The directive must be the first line in the script.
The directive must start with shebang #!
White space after the shebang characters is optional.
Interpreter is the full path to a binary file (ex: /bin/sh, /bin/bash).
Interpreter arguments are optional.

# Examples:
#!/bin/bash - Uses bash to parse the file.
#!/usr/bin/python Executes the file using the python binary.

Bash Aliases

Are you tired of typing the same long commands over and over? Bash aliases can make a world of difference. A Bash alias is a method of supplementing or overriding Bash commands with new ones. Bash aliases make it easy for users to customize their experience in a POSIX terminal. They are often defined in $HOME/.bashrc

# type cls to trigger 'clear' command
alias cls="clear"

# type du to run a django server
alias du="python3 manage.py runserver"

Bash Scripts

Reusable sets of bash terminal commands can be created using bash scripts. Bash scripts can run any command that programmers can run in a terminal.

Bash script comparison operators

  • -z string True if the length of the string is zero
  • -n string True if the length of the string is non-zero
  • string1 == string2 True if the strings are equal
  • string1 != string2 True if the strings are not equal
  • string1 < string2 True if string1 sorts before string2 lexicographically
  • string1 > string2 True if string1 sorts after string2 lexicographically

Bash Scripts Increase Productivity

Linux administrators can use bash scripts for various purposes, such as executing a shell command, running multiple commands together, customizing administrative tasks, performing task automation, etc. So knowledge of bash programming basics is essential for every Linux user. Bash scripts can increase productivity by automating repetitive tasks. A perfect use case for a script is a cron job, which is a script that executes a task on a schedule.

Bash Script Use Cases

A script, with proper set permissions and syntax, can execute commands in a fraction of the time a user would take. Bash scripting allows a user to elegantly sequence commands together and review commands to avoid potential havoc on data, files, and file structures.

Open-Source Bash Scripts

Click to share! ⬇️