Introduction to Linux

Introduction to Linux

Introduction

Have you ever wondered what happens when you start your computer?

The computer executes the software in BIOS (Basic Input Output System) and initializes the process called POST (Power On Self Test) when the computer is turned on.

It checks if the system is working properly or not, checks and initializes the screen, keyboard, hardware and also tests the main memory, the hard-drive. Checks to see if the system is ready to launch the OS.

After checking, it loads the bootloader, this bootloader loads the operating system into the main memory of the computer, and it is responsible to start the OS.

This is the process that happens when you start your computer.

What is Operating system

An operating system is a software program required to manage and operate a computing device like smartphones, tablets, computers, supercomputers, web servers, cars, network towers, smartwatches, etc.

Operating system need a

  1. Kernel - Facilitates the interaction between the software and hardware.
  2. File system - Method or a Data structure that the operating system uses to store and retrieve data in the memory. Everything is a file in a sense in every operating system.
  3. Some sort of user interface, it can be command line based or graphical.
  4. Should be able to manipulate data based on commands.

Famous operating systems are

  • Windows
  • macOS
  • Linux

Why use Linux

The Linux operating system is very stable, reliable, and less prone to crashes than other operating systems. Even Microsoft chose Linux as the operating system to power their Azure Cloud Computing Services instead of their own Windows Server operating system.

  • Perfect for programmers as it supports almost all programming languages.
  • It is open source and free for everyone. Linux usually has an army of open-source developers who make improvements to the operating system, fix bugs and increase the security and stability of the operating system constantly.
  • Linux's package management system, repositories and other features makes it harder to compromise than other operating systems, hence, great security.
  • It offers a large range of tools which are developer friendly. Linux offers freedom, you can control every part of the operating system. You can pick and choose which features you need, which you don't even want to install, and which you want disabled.
  • Linux terminal is superior to command line and Linux runs on any hardware. The core Linux OS is very lightweight and makes efficient use of any system's resources.
  • It is easier to get things done on Linux, as it opens bash scripting.
  • Linux is heavily documented, having a large community of active developers who are willing to teach others what they have learned and help beginners with their Linux issues.
  • It gives you the ability to SSH to a remote server.

History of Linux

A team of developers of bell labs started a project to make a common software for all the computers and named it 'Unix' in 1969. It was simple and elegant, with parts of code recyclable. As it was recyclable, a part of its code now commonly called 'kernel' was used to develop the operating system and other functions and could be used on different systems.

In 1983, Richard Stallman developed GNU project with the goal to make it freely available Unix like operating system and to be used by everyone. It failed to gain popularity.

In 1991, Linus Torvalds, a student at the university of Helsinki, Finland, thought to have a freely available academic version of Unix. He did it on MINIX using GNU C Compiler. GNU C compiler is still the main choice to compile Linux code, but other compilers are also used, like Intel C compiler. In 1992, he released the kernel under GNU General Public License.

Linux today is used everywhere from supercomputers, smartphones, desktop, web servers, tablet, laptops and home appliances like washing machines, DVD players, routers, modems, cars, to even refrigerators.

Linux's distributions - Debian, Ubuntu, Fedora, Arch and others. There would be some differences but overall deep down they follow the same Linux kernel, they have the same functionalities. Know more about List of Linux Distributions

Basic commands of Linux

Starting a terminal

  • ctrl+alt+t starts a new terminal
  • Press the windows button, then type "Terminal"

Terminal is a text input and output environment, it is also called a console and its job is to launch a shell

Shell

Shell is a command line interpreter, as it executes each command, line by line. It is like a program that takes your command and gives it to the kernel to execute. Shell uses Bash programming language.

Shell format - username@hostname:~$

Commands

echo

echo command in Linux is used to display a line of text/string that are passed as an argument.

Syntax: echo [option] [string]

pwd

pwd stands for Print Working Directory. It prints the path of the working directory, starting from the root.

Syntax:

pwd -L: prints the symbolic path 
pwd -P: prints the actual path

ls

ls command is used to list files or directories in Linux and other Unix-based operating systems.

cd

Linux cd command is used to change the current working directory (in which the current user is working). "cd" stands for 'change directory'.

Syntax: cd <dirname>

flags (or OPTIONS)

Flags are used to modify the behavior of a command. For example, ls -a where, -a tells the ls executable to list all files in the directory, including hidden ones. Flags are also called OPTIONS.

Comments

Linux, like any other programming language, supports comments in its Bash Shell.

Syntax: #This is a comment

mkdir

mkdir command allows user to create directories (also called folders in other OS). This command can create multiple directories at once, as well as set permissions for the directories.

Syntax: mkdir [options...] [directories...]

touch and cat

touch command is used to create, change and modify timestamps of a file.

cat (short for "concatenate") is one of the most frequently used commands in Linux. It allows us to create single or multiple files, view content of a file, concatenate files and redirect output in terminal or files.

There are two different commands to create a file in the Linux systems which is as following:

  • cat command: It is used to create a file with content
  • touch command: It is used to create a file without any content. The file created using touch command is empty.

man

man command is used to display the user manual of any command that we can run on the terminal. It provides a detailed view of the command.

Syntax: man [OPTION]. . . [COMMAND NAME] . . .

whatis

whatis command is used to get a one-line manual page description. This command search for the manual pages names and show the manual page description of the specific filename or argument.

Syntax: whatis [-dlv?V] [-r|-w] [-s list] [-m system[, …]] [-M path] [-L locale] [-C file] name …

file

file command is used to determine the type of file. This command tests each argument in an attempt to categorize it.

It has three sets of tests as follows:

  • filesystem test: This test is based on the result which returns from a stat system call. The program verifies that if the file is empty, or if it’s some sort of special file. This test causes the file type to be printed.
  • magic test: These tests are used to check for files with data in particular fixed formats.
  • language test: This test search for particular strings which can appear anywhere in the first few blocks of a file.

Syntax: file [option] [filename]

clear

clear command is used to clear the screen. It works in most terminal emulators. You can also use ctrl+L a keyboard shortcut to clear the screen.

history

history command is used to view the previously executed command. Bash and Korn support this feature in which every command executed is treated as the event and is associated with an event number using which they can be recalled and changed if required. These commands are saved in a history file. In Bash shell history command shows the whole list of the command.

cp

cp stands for copy. This command is used to copy files or group of files or directory.

mv

mv stands for move. It is used to move one or more files or directories from one place to another in a file system.

tr

The tr command is a command line utility for translating or deleting characters. It supports a range of transformations including uppercase to lowercase, squeezing repeating characters, deleting specific characters and basic find and replace. tr stands for translate.

Syntax: tr [OPTION] SET1 [SET2]

rm

rm stands for remove. It is used to remove objects such as files, directories, symbolic links and so on from the file system. rm removes references to objects from the filesystem. You should be very careful while running rm command because once you delete the files then you are not able to recover the contents of files and directories.

df

df command is used to display the amount of disk space available on the file system containing each file name argument.

gedit

gedit is a powerful general purpose text editor in Linux. It is the default text editor of the GNOME desktop environment.

grep

grep filter searches a file for a particular pattern of characters, and displays all lines that contain that pattern. The pattern that is searched in the file is reffered to as rhe regular expression (grep stands for global search for regular expression and print out).

Syntax: grep [options] pattern [files]

Others

  • ctrl+c - It is used to kill a process with the signal SIGINT, and can be intercepted by a program so it can clean itself up before exiting, or not exit at all.
  • ctrl+z - It is used for suspending a process by sending it the signal SIGSTP, which cannot be intercepted by the program.

  • ctrl+r - Reverse-i-search, it searched backward through your history to find the command you are looking for.

  • tab key - to autocomplete, if you press tab two times it shows you the directories.

  • . - Current directory

  • .. - Parent directory of current directory.

  • -- Previous directory before the current directory.

Conclusion

Do not worry about learning all the command in one single go, you can use this as a reference guide. Go through the commands, understand them and use them when you are working on Linux. Working will help you understand and retain the information.

Resources

Did you find this article valuable?

Support Eshan Sharma by becoming a sponsor. Any amount is appreciated!