[go: up one dir, main page]

0% found this document useful (0 votes)
6 views916 pages

Open Source and Linux3

Uploaded by

sandhyadevit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views916 pages

Open Source and Linux3

Uploaded by

sandhyadevit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 916

Pros and Cons of Open Source Software

Despite the importance of open source, OSS is not without its share of challenges. Let us take an objective look at
the pros and cons of open source software to decide if it is right for you:
Pros of open source software
The benefits of open source software are:
1. Lower cost
Open source projects are typically developed and maintained by a community of volunteers who share their skills
and knowledge for free. This means anyone can access and use the software without paying hefty licensing fees or
upfront costs.
Moreover, since the source code is available to everyone, businesses can modify and customize the software
according to their specific needs, eliminating the need for expensive proprietary software as a service (SaaS)
solutions.
2. Ease of integration
Unlike closed source software, which often requires proprietary application programming interfaces (APIs) and
protocols, open source software promotes interoperability and compatibility with other systems. This means
developers can seamlessly integrate different components or modules from various sources without facing major
hurdles.
3. No vendor lock-in
With OSS, there is no vendor lock-in. This means users are not tied to a single provider or limited by proprietary
formats or protocols. Developers are free to modify and customize the software according to their specific needs
without any restrictions imposed by a single vendor.
Additionally, it ensures that users can easily switch between different vendors if they find one better suited to their
requirements or if they encounter any issues with the current provider. This flexibility ultimately leads to cost
savings and improved efficiency in the long run.
4. Greater flexibility
Developers have access to the underlying source code, giving them the freedom to make any necessary changes or
enhancements. This flexibility empowers organizations and individuals to tailor the software to meet their unique
requirements, whether adding new features or integrating with other systems. The ability to customize open
source software makes it a versatile solution for various applications across various industries.
This inherent flexibility in open source software ensures that businesses can build agile IT infrastructures that
evolve alongside their changing needs—a valuable advantage that closed source alternatives may not offer.
5. The power of community
Unlike closed source software, where development and improvement are limited to a specific team or company,
open source projects benefit from a global community of developers, users, and enthusiasts. The power of
community lies in its ability to harness the collective intelligence of passionate individuals who share a common
goal: creating high-quality software accessible to all.
Cons of open source software
Open source software, despite its many advantages, also has some drawbacks that users should be aware of:
1. No prompt support
Open source software often relies on community forums and user-driven discussions for troubleshooting and
problem-solving. While these forums can be helpful in many cases, they may not always provide immediate or
timely responses to users’ queries or issues. This can be frustrating for individuals or businesses requiring urgent
technical assistance.
It’s important to consider this aspect before choosing open source software, especially if your organization requires
a high level of technical support and quick resolution for any potential problems that may arise during usage.
2. Complexity and difficult learning curve
Unlike closed source software, which often comes with user-friendly interfaces and comprehensive documentation,
open source software might require some technical expertise to navigate effectively.
The sheer flexibility and customization options offered by open source software can lead to higher complexity.
Users may need to invest time in understanding the intricacies of the software’s framework and architecture,
configuration settings, and dependencies. This can be daunting for those unfamiliar with coding or with limited
technical knowledge.
3. Limited features
Open source software (OSS) offers numerous benefits, but it’s important to acknowledge that there can also be
limitations. One of these is the potential for limited features in certain OSS projects. This is because OSS
development relies on community contributions and volunteer efforts, which may result in prioritizing core
functionalities over additional features.
4. High maintenance needs
Since these projects rely on community contributions and updates, they require regular upkeep to ensure
compatibility and security. This includes regularly monitoring for updates, bug fixes, and security patches. Open
source applications can become vulnerable to security breaches or compatibility issues with other software
components without proper maintenance.
Additionally, because multiple contributors are involved in the development of open source projects, coordinating
updates can be more complex compared to closed source alternatives, where a single vendor oversees all aspects
of maintenance.
5. Less stable builds
The open nature of OSS means that anyone can modify and update the code, which can lead to unintended
consequences. As a result, users may experience occasional crashes or glitches while using open source
applications. However, passionate developers within the community work diligently to address these issues and
release patches and updates to improve stability over time.
Open Source Software Examples
There are numerous examples of open source software that have made a significant impact in the tech industry.
These include:
 VLC Media Player: VLC Media Player, developed by VideoLAN, is a highly popular open source media player that
supports a wide range of audio and video formats. With its humble beginnings in 1996 as an academic project at
École Centrale Paris, VLC has become one of today’s most widely used media players.
 GIMP: GIMP, short for GNU Image Manipulation Program, is a powerful open source image editing software. The
history of GIMP dates back to 1995 when Spencer Kimball and Peter Mattis developed the software as a class
project at the University of California, Berkeley. Over the years, it has evolved into a highly versatile tool used by
graphic designers, photographers, and artists worldwide.
 Mozilla Firefox: Mozilla Firefox is a popular web browser that has gained immense popularity among users
worldwide. It was created by the Mozilla Foundation and was initially released in 2004 as an open source project.
 Linux: Linux is a powerful open source operating system that has revolutionized the computing world. Developed
by Linus Torvalds in 1991, Linux was initially created as an alternative to proprietary operating systems like
Windows and macOS. It is based on the Unix operating system and is designed to run on a wide range of devices,
from servers to Raspberry Pi.
 Apache HTTP Server: The Apache HTTP Server, commonly known as Apache, was created by a group of developers
in 1995 to provide a robust and reliable platform for hosting websites. Since its inception, it has become one of the
most popular web servers globally, commanding over half of the market share.
Takeaway

An Introduction to Linux

Introduction
The Linux operating system is an extremely versatile Unix-like operating system, and has taken a clear lead in the
High Performance Computing (HPC) and scientific computing community. Linux is a multi-user, preemptive
multitasking operating system that provides a number of facilities including management of hardware resources,
directories, and file systems, as well as the loading and execution of programs. A vast number of utilities and
libraries have been developed (mostly free and open source as well) to accompany or extend Linux.
There are two major components of Linux, the kernel and the shell:
1. The kernel is the core of the Linux operating system that schedules processes and interfaces directly with the
hardware. It manages system and user I/O, processes, devices, files, and memory.
2. The shell is a text-only interface to the kernel. Users input commands through the shell, and the kernel receives the
tasks from the shell and performs them. The shell tends to do four jobs repeatedly: display a prompt, read a
command, process the given command, then execute the command. After which it starts the process all over again.
It is important to note that users of a Linux system typically do not interact with the kernel directly. Rather, most
user interaction is done through the shell or a desktop environment.

Unix
The Unix operating system got its start in 1969 at Bell Laboratories and was written in assembly language. In 1973,
Ken Thompson and Dennis Ritchie succeeded in rewriting Unix in their new language C. This was quite an audacious
move; at the time, system programming was done in assembly in order to extract maximum performance from the
hardware. The concept of a portable operating system was barely a gleam in anyone's eye.
The creation of a portable operating system was very significant in the computing industry, but then came the
problem of licensing each type of Unix. Richard Stallman, an American software freedom activist and programmer
recognized a need for open source solutions and launched the GNU project in 1983, later founding the Free
Software Foundation. His goal was to create a completely free and open source operating system that was Unix-
compatible or Unix-like.
Linux
In 1987, the source code to a minimalistic Unix-like operating system called MINIX was released by Andrew
Tanenbaum, a professor at Vrije Universiteit, for academic purposes. Linus Torvalds began developing a new
operating system based on MINIX while a student at the University of Helsinki in 1991. In September of 1991,
Torvalds released the first version (0.1) of the Linux kernel.
Torvalds greatly enhanced the open source community by releasing the Linux kernel under the GNU General Public
License so that everyone has access to the source code and can freely make modifications to it. Many components
from the GNU project, such as the GNU Core Utilities, were then integrated with the Linux kernel, thus completing
the first free and open source operating system.
Linux has been adapted to a variety of computer systems of many sizes and purposes. Furthermore, different
variants of Linux (called Linux distributions) have been developed over time to meet various needs. There are now
hundreds of different Linux distributions available, with a wide variety of features. The most popular operating
system in the world is actually Android, which is built on the Linux kernel.
Why Linux
Linux has been so heavily utilized in the HPC and scientific computing community that it has become the standard
in many areas of academic and scientific research, particularly those requiring HPC. There have been over 40 years
of development in Unix and Linux, with many academic, scientific, and system tools. In fact, as of November 2017,
all of the TOP500 supercomputers in the world run Linux!
Linux has four essential properties which make it an excellent operating system for the science community:
 Performance – Performance of the operating system can be optimized for specific tasks such as running small
portable devices or large supercomputers.
 Functionality – A number of community-driven scientific applications and libraries have been developed under
Linux such as molecular dynamics, linear algebra, and fast-Fourier transforms.
 Flexibility – The system is flexible enough to allow users to build applications with a wide array of support tools
such as compilers, scientific libraries, debuggers, and network monitors.
 Portability – The operating system, utilities, and libraries have been ported to a wide variety of devices including
desktops, clusters, supercomputers, mainframes, embedded systems, and smart phones.
Files and Processes
Everything in Linux is considered to be either a file or a process:
 A process is an executing program identified by a unique process identifier, called a PID. Processes may be short in
duration, such as a process that prints a file to the screen, or they may run indefinitely, such as a monitor program.
 A file is a collection of data, with a location in the file system called a path. Paths will typically be a series of words
(directory names) separated by forward slashes, /. Files are generally created by users via text editors, compilers, or
other means.
 A directory is a special type of file. Linux uses a directory to hold information about other files. You can think of a
directory as a container that holds other files or directories; it is equivalent to a folder in Windows or macOS.
A file is typically stored on physical storage media such as a disk (hard drive, flash disk, etc.). Every file must have a
name because the operating system identifies files by their name. File names may contain any characters, although
some special characters (such as spaces, quotes, and parenthesis) can make it difficult to access the file, so you
should avoid them in filenames. On most common Linux variants, file names can be as long as 255 characters, so it
is convenient to use descriptive names.
Files can hold any sequence of bytes; it is up to the user to choose the appropriate application to correctly interpret
the file contents. Files can be human readable text organized line by line, a structured sequence only readable by a
specific application, or a machine-readable byte sequence. Many programs interpret the contents of a file as having
some special structure, such as a pdf or postscript file. In scientific computing, binary files are often used for
efficiency storage and data access. Some other examples include scientific data formats like NetCDF or HDF which
have specific formats and provide application programming interfaces (APIs) for reading and writing.
The Linux kernel is responsible for organizing processes and interacting with files; it allocates time and memory to
each process and handles the file system and communications in response to system calls. The Linux system uses
files to represent everything in the system: devices, internals to the kernel, configurations, etc.
Shells
A variety of different shells are available for Linux and Unix, each with pros and cons. While bash (updated version
of sh) and tcsh (descended from C-shell/csh) are the most common shells, the choice of shell is entirely up to user
preference and availability on the system. In most Linux distributions, bash is the default shell.
The purpose of a shell is to interpret commands for the Operating System (OS) to execute. Since bash and other
shells are scripting languages, a shell can also be used for programming via scripts. The shell is an interactive and
customizable environment for the user.
All examples in this tutorial use the bash shell.
Text Editors
A text editor is a tool to assist the user with creating and editing files. There is no "best" text editor; it depends on
personal preferences. Regardless of your typical workflow, you will likely need to be proficient in using at least one
common text editor if you are using Linux for scientific computing or similar work. Two of the most widely used
command-line editors are Vim and Emacs, which are available via the vim and emacs commands, respectively, in
systems where they are installed.
Linux File System

A file system is a structured method of storing and managing data—including files, directories, and metadata—on
your machine. Think of it like a library. If thousands of books were scattered around, finding one would be hard. But
in an organized structure, like labeled shelves, locating a book becomes easy.
This article aims to simplify the complexities of Linux file systems, guiding beginners through their layers,
characteristics, and implementations. By shedding light on these nuances, we empower users to make informed
choices in navigating the dynamic landscape of Linux operating systems.
What is the Linux File System
A Linux file system is a set of processes that controls how, where, and when data is stored or retrieved from
storage devices. It manages data systematically on disk drives or partitions, and each partition in Linux has its own
file system because Linux treats everything as a file, including devices and applications.. Like Windows uses C: and
D: drives, Linux uses mount points, but everything appears under the root / directory. In Linux, everything is treated
as a file, including devices and applications.
Linux File System Structure
The architecture of a file system comprises three layers mentioned below.
1. Logical File System:
The Logical File System acts as the interface between the user applications and the file system itself. It facilitates
essential operations such as opening, reading, and closing files. Essentially, it serves as the user-friendly front-end,
ensuring that applications can interact with the file system in a way that aligns with user expectations.
2. Virtual File System:
The Virtual File System (VFS) is a crucial layer that enables the concurrent operation of multiple instances of
physical file systems. It provides a standardized interface, allowing different file systems to coexist and operate
simultaneously. This layer abstracts the underlying complexities, ensuring compatibility and cohesion between
various file system implementations.
3. Physical File System:
The Physical File System is responsible for the tangible management and storage of physical memory blocks on the
disk. It handles the low-level details of storing and retrieving data, interacting directly with the hardware
components. This layer ensures the efficient allocation and utilization of physical storage resources, contributing to
the overall performance and reliability of the file system.
Together, these layers form a cohesive architecture, orchestrating the organized and efficient handling of data in
the Linux operating system.

Architecture Of a File
System
Characteristics of a File System
A file system defines the rules and structures for how data is organized, stored, accessed, and managed on a
storage device.
 Space Management: How the data is stored on a storage device. Pertaining to the memory blocks and
fragmentation practices applied in it.
 Filename: A file system may have certain restrictions to file names such as the name length, the use of special
characters, and case sensitive-ness.
 Directory: The directories/folders may store files in a linear or hierarchical manner while maintaining an index table
of all the files contained in that directory or subdirectory.
 Metadata: For each file stored, the file system stores various information about that file's existence such as its data
length, its access permissions, device type, modified date-time, and other attributes. This is called metadata.
 Utilities: File systems provide features for initializing, deleting, renaming, moving, copying, backup, recovery, and
control access of files and folders.
 Design: Due to their implementations, file systems have limitations on the amount of data they can store.
Linux File Systems:
Here are some linux file systems:
Types of File System in Linux
1) ext (Extended File System):
Implemented in 1992, it is the first file system specifically designed for Linux. It is the first member of the ext family
of file systems.
2) ext2:
The second ext was developed in 1993. It is a non-journaling file system that became known for its efficient
handling of flash drives and SSDs. It solved the problems of separate timestamp for access, inode modification and
data modification. Due to not being journaled, it is slow to load at boot time.
3) Xiafs:
Also developed in 1993, Xiafs was developed as an alternative but lacked the power and functionality of ext2. Due
to limited features and scalability, it is no longer in use.
4) ext3:
Introduced in 1999, ext3 brought in journaling capabilities, offering improved reliability. Unlike ext2, it avoided
long boot-time checks after an improper shutdown. It also supported online file system growth and HTree
indexing, making it efficient for large directories.
5) JFS (Journaled File System):
First created by IBM in 1990, the original JFS was taken to open source to be implemented for Linux in 199 it is
Known for its ability to perform well under varied loads JFS performs well under different kinds of load but is not
commonly used anymore due to the release of ext4 in 2006 which gives better performance.
6) ReiserFS:
It is a journal file system developed in 2001. Despite its earlier issues, it has tail packing as a scheme to reduce
internal fragmentation. It uses a B+ Tree that gives less than linear time in directory lookups and updates. It was the
default file system in SUSE Linux till version 6.4, until switching to ext3 in 2006 for version 10.2.
7) XFS:
XFS is a 64-bit journaling file system and was ported to Linux in 2001. It now acts as the default file system for many
Linux distributions. It provides features like snapshots, online defragmentation, sparse files, variable block sizes,
and excellent capacity. It also excels at parallel I/O operations.
8) SquashFS:
Developed in 2002, this file system is read-only and is used only with embedded systems where low overhead is
needed.
9) Reiser4:
It is an incremental model to ReiserFS. It was developed in 2004. However, it is not widely adapted or supported on
many Linux distributions.
10) ext4:
The fourth ext developed in 2006, is a journaling file system. It has backward compatibility with ext3 and ext2 and it
provides several other features, some of which are persistent pre-allocation, unlimited number of subdirectories,
metadata checksumming and large file size. ext4 is the default file system for many Linux distributions and also has
compatibility with Windows and Macintosh.
11) btrfs (Better/Butter/B-tree FS):
It was developed in 2007. It provides many features such as snapshotting, drive pooling, data scrubbing, self-
healing and online defragmentation. It is the default file system for Fedora Workstation.
12) bcachefs:
This is a copy-on-write file system that was first announced in 2015 with the goal of performing better than btrfs
and ext4. Its features include full filesystem encryption, native compression, snapshots, and 64-bit check summing.
13) Others:
Linux also has support for file systems of operating systems such as NTFS and exFAT, but these do not support
standard Unix permission settings. They are mostly used for interoperability with other operating systems.
File Systems Comparison:
Please note that there are more criteria than the ones listed in the table. This table is supposed to give you an idea
of how file systems have evolved.

File Systems
Parameters
ext ext2 Xiafs ext3 JFS ReiserFS XFS Reiser4 ext4 btrfs
Max. 4032
filename 255
255 255 248 255 255 255 3976 255 255
length character
(bytes) s
Allowable
Any
characters
except except except except Unicode except except except except except
in directory
NUL NUL, / NUL NUL or / except NUL or / NUL NUL, / NUL, / NUL, /
entries
NUL
(Any byte)
Max.
Undefine Undefine Undefine Undefine Undefine Undefine Undefine Undefine Undefine
pathname Undefined
d d d d d d d d d
length
Max. file 16GB - 16GB - 8TB (on
2 GB 64MB 4PB 8TB 8EB 16GB - 16TB 16EB
size 2TB 2TB x86)
Max. 2TB - 2TB -
2 GB 2GB 32PB 16TB 8EB - 1EB 16EB
volume size 32TB 32TB
Max. no. of
- - - - - - - - 2^32 2^64
files
Metadata
only No No No Yes Yes Yes Yes No Yes No
journaling
Compressio
No No No No No No No Yes No Yes
n
Block sub-
No No No No Yes Yes No Yes No Yes
allocation
Online No No - Yes No Yes Yes Yes Yes Yes
File Systems
Parameters
ext ext2 Xiafs ext3 JFS ReiserFS XFS Reiser4 ext4 btrfs
grow
Yes
Encryption No No No No No No No Yes (experiment No
al)
Checksum No No No No No No Partial No Partial Yes
Observations:
We see that XFS, ext4 and btrfs perform the best of all the other file systems. In fact, btrfs looks as if it's almost the
best. Despite that, the ext family of file systems has been the default for most Linux distributions for a long time.
So, what is it that made the developers choose ext4 as the default rather than btrfs or XFS? Since ext4 is so
important for this discussion, let's describe it a bit more.
ext4 in Linux File System
Ext4 was designed to be backward compatible with ext3 and ext2, its previous generations. It's better than the
previous generations in the following ways:
 It provides a large file system as described in the table above.
 Utilizes extents that improve large file performance and reduces fragmentation.
 Provides persistent pre-allocation which guarantees space allocation and contiguous memory.
 Delayed allocation improves performance and reduces fragmentation by effectively allocating larger amounts of
data at a time.
 It uses HTree indices to allow unlimited number of subdirectories.
 Performs journal checksumming which allows the file system to realize that some of its entries are invalid or out of
order after a crash.
 Support for time-of-creation timestamps and improved timestamps to induce granularity.
 Transparent encryption.
 Allows cleaning of inode tables in background which in turn speeds initialization. The process is called lazy
initialization.
 Enables writing barriers by default. Which ensures that file system metadata is correctly written and ordered on
disk, even when write caches lose power.
There are still some features in the process of developing like metadata checksumming, first-class quota supports,
and large allocation blocks.
However, ext4 has some limitations. Ext4 does not guarantee the integrity of your data, if the data is corrupted
while already on disk then it has no way of detecting or repairing such corruption. The ext4 file system cannot
secure deletion of files, which is supposed to cause overwriting of files upon deletion. It results in sensitive data
ending up in the file-system journal.
XFS performs highly well for large filesystems and high degrees of concurrency. So XFS is stable, yet there's not a
solid borderline that would make you choose it over ext4 since both work about the same. Unless you want a file
system that directly solves a problem of ext4 like having capacity > 50TiB.
Btrfs on the other hand, despite offering features like multiple device management, per-block checksumming,
asynchronous replication and inline compression, does not perform the best in many common use cases as
compared to ext4 and XFS. Several of its features can be buggy and result in reduced performance and data loss.
Some Hands On Example on Linux File System
For example, if our use_case is to set up a server that will first store and serve large multimedia files (videos and
audios). In that case we have to prioritize efficient speed and use of storage space.
According to this requirement the XFS file system would be a better choice. Because we know that XFS is optimized
for large files and can work on high volumes of data transfer which in general makes it ideal for media servers.
Following steps to use it:
Step 1: Installing XFS utilities package on Linux system.
sudo apt-get install xfsprogs
Installing xfsprogs
Step 2: Create a partition to format as XFS.
For example: `/dev/sda1`
This can be done using tool like `fdisk`.
Step 3: Format the partition as XFS.
sudo mkfs.xfs /dev/sda1 -f
Format the partition
We have formatted partition using XFS filesystem. (Used -f for forcefully to avoid error or warning) .
Step 4: Mount the XFS partition to a directory we want.
sudo mount /dev/sda1 /mnt/jayesh_xfs_partition
mounting of XFS partition
We have mounted XFS partition to a directory `/mnt/jayesh_xfs_partition`, (you can create your own directory.)
Step 5: To verify the mount.
df -h
Successful mount
Linux File Hierarchy Structure
The Linux File Hierarchy Structure or the Filesystem Hierarchy Standard (FHS) defines the directory structure and
directory contents in Unix-like operating systems. It is maintained by the Linux Foundation.
 In the FHS, all files and directories appear under the root directory /, even if they are stored on different physical or
virtual devices.
 Some of these directories only exist on a particular system if certain subsystems, such as the X Window System, are
installed.
 Most of these directories exist in all UNIX operating systems and are generally used in much the same way;
however, the descriptions here are those used specifically for the FHS and are not considered authoritative for
platforms other than Linux.
linux-directory
1. / (Root):
At the top of every Linux file system is the root directory represented by a forward slash /. It’s the base point, and
no directory exists above it. If you look at the file system graphically, you’ll see all other directories branching from
this root directory.
 Every single file and directory start from the root directory.
 The only root user has the right to write under this directory.
 /root is the root user’s home directory, which is not the same as /
Only the root user has permission to modify contents inside this directory. Regular users cannot make changes
here. For example, if you attempt to create a file in / as a non-root user, you’ll encounter a "Permission Denied"
error.
root-linux-directory
2. /bin :
The /bin directory contains essential commands and binaries needed by all users, including cp, ls, ssh, and kill.
These commands are universally available across user types.
 Contains binary executables.
 Common linux commands you need to use in single-user modes are located under this directory.
 Commands used by all the users of the system are located here e.g. ps, ls, ping, grep, cp
bin-linux-directory
3. /boot :
This directory stores all files required for booting the system. It includes the GRUB bootloader configuration and
essential kernel files that are loaded during startup.
 Kernel initrd, vmlinux, grub files are located under /boot
 Example: initrd.img-2.6.32-24-generic, vmlinuz-2.6.32-24-generic
boot-linux-directory
4. /dev :
Device files in Linux are stored in the /dev directory. These are special files that act as interfaces between hardware
and software. Device files are of two types: block devices (e.g., hard drives) and character devices (e.g.,
microphones and speakers). Examples include /dev/sda1 for disk partitions.
 These include terminal devices, usb, or any device attached to the system.
 Example: /dev/tty1, /dev/usbmon0
dev-linux-directory

5. /etc :
Short for "Editable Text Configuration," /etc contains configuration files for system applications, users, services, and
tools or it contains the Host-specific system-wide configuration files. For example, user details like UID and local
addresses are defined here.
 This also contains startup and shutdown shell scripts used to start/stop individual programs.
 Example: /etc/resolv.conf, /etc/logrotate.conf.
etc-linux-directory
6. /home :
Every non-root user has a personal directory inside /home. For example, if your username is anshu, your personal
directory would be /home/anshu. Each user can create, delete, or modify files only in their own home directory and
cannot access others’ home directories.
 Home directories for all users to store their personal files, containing saved files, personal settings, etc..
 example: /home/kishlay, /home/kv
home-linux-directoryhome-linux-directory
7. /lib:
Applications require shared libraries to run, which are stored in /lib. These include dynamic libraries needed during
runtime. For example, Apache server libraries are available here.
 Library filenames are either ld* or lib*.so.*
 Example: ld-2.11.1.so, libncurses.so.5.7
lib-linux-directory
8. /media:
Devices like USBs, CDs, and pen drives are mounted under /media. For example, when a CD-ROM is inserted
(appeared in FHS-2.3), its details will appear here.
 Temporary mount directory for removable devices.
 Examples, /media/cdrom for CD-ROM; /media/floppy for floppy drives; /media/cdrecorder for CD writer
media-linux-directory

9. /mnt :
When external drives are connected, they are temporarily mounted in /mnt. This is where their contents become
accessible to the system.
 Temporary mount directory where sysadmins can mount filesystems.
mnt-linux-directory
10. /opt :
Third-party software and packages not part of the default system installation are stored in /opt. It includes their
configuration and data files.
 Contains add-on applications from individual vendors.
 Add-on applications should be installed under either /opt/ or /opt/ sub-directory.
opt-linux-directory.
11. /sbin :
Essential system binaries, e.g.,
This directory holds administrative binaries like iptables, firewall management tools, fsck, init, route etc. These
binaries are primarily for system administrators and typically require root privileges to execute.
 Just like /bin, /sbin also contains binary executables.
 The linux commands located under this directory are used typically by system administrators, for system
maintenance purposes.
 Example: iptables, reboot, fdisk, ifconfig, swapon
sbin-linux-directory
12. /srv :
Site- specific data served by this system, such as data and scripts for web servers, data offered by FTP servers, and
repositories for version control systems.
 srv stands for service.
 Contains server specific services related data.
 Example, /srv/cvs contains CVS related data.
srv-linux-directory
13. /tmp :
Programs create temporary files during execution, and these are stored in /tmp. These files are deleted
automatically after the program finishes or when the system is restarted.
 Directory that contains temporary files created by system and users.
 Files under this directory are deleted when the system is rebooted.
tmp-linux-directory
14. /usr :
Secondary hierarchy for read-only user data; contains the majority of (multi-)user utilities and applications.
 Contains binaries, libraries, documentation, and source-code for second level programs.
 / usr/bin contains binary files for user programs. If you can’t find a user binary under /bin, look under /usr/bin. For
example: at, awk, cc, less, scp
 /usr/sbin contains binary files for system administrators. If you can’t find a system binary under /sbin, look under
/usr/sbin. For example: atd, cron, sshd, useradd, userdel
 /usr/lib contains libraries for /usr/bin and /usr/sbin
 / usr/local contains user's programs that you install from source. For example, when you install apache from
source, it goes under /usr/local/apache2
 /usr/src holds the Linux kernel sources, header-files and documentation.
usr_bin-linux-directoryusr_sbin-linux-directoryusr_lib-linux-dirctoryusr_local-linux-directory

usr_src-linux-directory
15. /proc:
The /proc directory provides detailed information about system processes. Each process is assigned a unique ID and
represented as a directory inside /proc. For example, /proc/meminfo gives real-time data about memory usage
including total, free, buffer, and cache statistics.
 Contains information about system process.
 This is a pseudo filesystem that contains information about running processes. For example: /proc/{pid} directory
contains information about the process with that particular pid.
 This is a virtual filesystem with text information about system resources. For example: /proc/uptime
proc-linux-directory

proc-linux-directory
Linux Introduction
Overview of Linux and Why it is so popular?
Linux is an open-source operating system (OS) that runs on a computer and controls all of the other software and
hardware on the computer. Initially, Linux was built on the Unix operating system, which was created many
decades ago as a platform for scientific and academic computing. It is used on a wide range of devices, including
servers, desktop computers, laptops, cloud computing, and Mobile devices.
As Linux is open-source software so anyone can access its source code and make changes to it. Other than this
Linux is known for its Security features. It has a large community of users and developers who are constantly
working to identify and fix security vulnerabilities. Also, Linux is well known for its Customizability allowing users to
modify and configure it in order to meet their specific needs.
Linux Architecture Components
The main architectural components that work together to form a complete Linux OS include Kernel, System
Libraries, User Space, Shell, System Utilities, Daemons, and Configuration files.
 Kernel: The kernel is the central part of the Linux OS. It manages the computer's hardware resources and
communicates with the software to provide a stable and consistent interface for us.
 System Libraries: System libraries are collections of pre-written code that provides common functions for other
programs to use.
 User Space: User space mainly refers to the programs and applications that run on top of the operating system.
This includes a wide range of applications such as text editors, web browsers, games, etc.
 Shell: Shell is a command-line interface that allows users to interact with the Linux operating system.
 System Utilities: System utilities are small programs that perform specific tasks such as file management, process
management, network management, etc.
 Daemons: Daemons are the background processes that run continuously and perform specific tasks such as
network services, log management, etc.
 Configuration files: Configuration files are used to configure various aspects of the Linux operating system such as
the network settings, system settings, security settings, etc.

Linux Distributions
Linux distributions, also known as "distros," are different versions of the Linux operating system that are built and
packaged with specific versions of the architectural components, the package management system used, the
graphical user interface, and the tools and applications included in it.
Examples of Linux distros include Ubuntu, Fedora, Debian, CentOS, Mint, Red Hat Enterprise Linux (RHEL), etc.
Linux File Systems
The Linux file system is the way that the operating system organizes and stores files and directories on a
computer's hard drive or other storage devices. It consists of a hierarchical structure where files and directories are
arranged in a tree-like format starting from the root directory (represented by "/"). Each file and directory has a
unique location within the file system hierarchy, and these locations can be referred to using a path similar to how
file paths work in other operating systems.
There are several types of file systems available for use in Linux including below:
 Ext4: This is the most widely used file system in Linux and it is known for its high performance, reliability, and
scalability. It is a journaling file system meaning that it keeps track of changes made to the file system in a log that
helps to ensure that data is not lost in the event of a system failure.
 XFS: This is a high-performance file system that is optimized for large-scale data storage and is commonly used in
enterprise and high-performance computing environments. It supports large file sizes and high-bandwidth I/O
which makes it well-suited for use with high-speed storage devices such as solid-state drives.
 Btrfs: This is a newer file system that is designed to be flexible, scalable, and easy to manage. It offers advanced
features such as snapshots which allow administrators to easily backup and restore data and it also supports data
and metadata checksums which help to prevent data corruption.
 NTFS: This is a file system commonly used in Microsoft Windows and it is supported by most modern Linux
distributions. It is designed to be compatible with a wide range of devices including hard drives and removable
storage devices and it supports advanced features such as compression and encryption.
 FAT32: This is an older file system that is commonly used in older Microsoft Windows systems and is also widely
used for removable storage devices such as USB drives and has limitations such as a maximum file size of 4GB.
(Note: The machine from which the screenshot has been taken is having CentOS 8 Stream)

Organization of Linux File System


In Linux, the file system is organized into a hierarchical structure, with the root directory (/) at the top of the
hierarchy. The root directory contains several subdirectories, each with its own specific purpose that form the
foundation of the Linux file system hierarchy. The subdirectories include:
 /bin - contains essential command-line utilities that are required for the system to function
 /boot - contains files needed for booting the system including the Linux kernel and boot loader configuration files
 /dev - contains device files that represent various devices and hardware components on the system
 /etc - contains configuration files for the system and various applications
 /home - contains the home directories for individual users
 /lib - contains libraries needed by the utilities in /bin and /sbin
 /media - a mount point for removable media such as CDs, DVDs, and USB drives
 /mnt - a mount point for temporarily mounting file systems
 /opt - contains third-party software packages
 /proc - A virtual file system that contains information about the system's process and kernel
 /root - the home directory for the root user
 /sbin - contains system executables, similar to /bin
 /sys - A virtual file system that provides an interface to the kernel's device drivers
 /tmp - Contains temporary files that can be deleted by the system when space is needed
 /usr - contains user utilities and libraries as well as data shared by multiple users
 /var - contains variable data such as log files, mail spools, and database files
These subdirectories may vary between different Linux distributions but the basic structure will remain the same. It
is strongly recommended to explore each subdirectory separately to understand more about it.

Linux Commands
 whereis - Find the path of that executable file.
List operation
 ls - Shows list.
o -a - Hidden file.
o -l - Permission.
o -R - Show sub dir.
Changing dir operation
 cd <folder-name> - Change Dir.
 cd .. - Go one Directory back.
 cd - Go to home.
 cd ../<foldername> - Open a previous dir folder.
 cd <path> - Open a dir with the path.
File/Folder Ope.
 mkdir <new-dir-name> - Create a new folder.
 mkdir -p test/test1/test2 - Create a dir between two directories.
 touch <new-file-name> - create a blank file.
 pwd - Present working directory.
 cat <filename> - Display file content.
 cat > <new-file-name> - Create a file.
 dd if=/dev/zero of=bos_dosya bs=4G count=1- create empty file with zeros
 cat >> <filename> - Append the file
 cat <filename1> >> <filename2> - Append the content of the file filename1 at the end of the file
<filename2> .
 cat <filename> <filename2> - Display 2 files at a time.
 cat <filename> <filename2> > <newfile-name> - Merge both of file content in a single one.
 cat <file-name> | tr > <new-file-name> - Translate the file.
 cut -c 1-2 <filename> - cut the file column wise
 echo "Hello" >> <file-name>
 man <commad name> - Know about the command usages and options.
 man <commad name> - know about the command.
File/Folder operation
 cp <file-name> <new-fie-name> - Make a copy of a file in the current location.
 mv <file-name> <dir-path> - Move a file from one dir to another.
 mv <file-name> <new-fie-name> - Rename a file.
 mv -R <dir-name> <dir-path> - Move Dir
 rm <file-name> - Remove a file permanently.
 rm -R <file-name> - Delete a folder with dir included.
 head <file-name> - Will display first 10 lines of a file.
 tail <file-name> - Will display last 10 lines of a file. --n 2 - will display last 2 lines.
 diff <file-1> <file-2> - Show diff between the two files.
 locate <file> - To find out the file.
 find <file/folder-name> - Find a file/folder.
 find <dir-name> - Find files inside the dir
 find .-type d - Show only dir.
o .-type f - show only files.
o .-type f -name "*.txt" - Show only files with that specific name.
o .-type f -iname "*.txt" - Show only files with that specific name - not case sensitive (i)
o .-type f -mmin -20 - Show files which modify less than 20 min ago.
o .-type f -mmin +20 - show files which modify more than 20 min ago.
o .-type f -maxdepth 2 - Will only show 1 folder deep.
o .-size +1k - will only show file/folder with size of 1kb
System commands
 ps aux - processes which are running
 systemctl [option] [service] - interact with a process
o We can do 4 option with systemctl
 start
 stop
 enable
 disable
o Example, systemctl start apache2
 df - Check the capacity and storage details.
o m - In megabyte or
o hg - In gigabyte.
 du - Disk usages capcity
o -h (human readable)
 echo - Get a output of a string
 echo $PATH - Check the path variable
 sudo - Admin command
 sudo chown root text.txt - change owner
 !<command-name> - Run the previous command
 git add .; git commit -m "message" - Run multiple commands at a time
 sort <file-name>" - sort the file
 job - show the jobs
 wget <url> - download the file from the URL
 top - what processes are running
 kill <process-id> -stop that process
 Uname - show the system info
 zip <file-1> <file-2> - Zip Two or more files
 Unzip <file-name> - Unzip files
 useradd <name> - add a user
 passwd <name> - set a password for the user
 uname -<flag> -o -m -r
 lscpu - get cpu details
 free - free memory
 vmstat - virtual memory
 lsof - list all the open file
 xdg-open <file-fath> - open the folder (graphical window) of a file/folder with path.
 xdg-open . - open the folder of the current directory.
 vi ~/.bashrc - set your Alias
 echo -n 'username' | base64 - encode the username to base64
 echo -n 'encoded' | base64 -d - decode the username to base64
Networking
 nslookup google.com - To check the IP address of the domain.
 netstat - To check the network status.
 hostname - To check the hostname.
 whoami - To check the current user.
 ping google.com - To check the connectivity.
Permissions
 chmod u=rwx,g=rxw,o=rwx <file-name> READ, WRITE AND EXECUTE
 chmod 777 <file-name> - 4- Read, 2- Write, 1 - Execute
 find . -perm 777 - shows files with all permissions(rwx)
 grep <keyword> <file-name> - To search if the keyword is presnt in the file or not
 grep -w <keyword> <file-name> - To search if the keyword is present in the file or not (complete word)
 grep -i <keyword> <file-name> - To search if the keyword is present in the file or not (not case sens)
 grep -n <keyword> <file-name> - To search if the keyword is present in the file or not (Line number)
 grep -B <keyword> <file-name> - Show Line before that keyword
 grep -win <keyword> ./*.txt - To search if the keyword is present in the file in current dir
 grep -win -r <keyword> .*
 history | grep "ls -l" - Piping, we filter out the things
history
!<number-from-history>
Operators
 ping google.com & ping facebook.com - run both the commands at the same time
 echo "google.com" && echo "facebook.com" - second will only run if first is successful
 echo "google.com" && {echo "facebook.com"; eco "pradumnasaraf.co"}
 echo "google.com" || echo "pingfacebook.com" - second will only run if first is not successful
 rm -r !(file.txt) - delete all files except file.txt
 printevnv - to print all th env.

List of popular Linux distributions


Ubuntu
Ubuntu is a Linux distribution based on Debian. It is developed by Canonical and a community of developers. It has
3 official editions: Desktop, Server and Core, which can either run on a computer or on a VM. More than 34% of the
websites using Linux use Ubuntu, according to W3Techs data. Its growth since 2010 has been amazing. It is also a
popular distribution among cloud computing projects.
Ubuntu License: GPL and other licenses.
Ubuntu Latest major release with long-term support (LTS): Ubuntu 24.04 LTS (Noble Numbat).
Debian
Debian is an open source operating system. This distribution was first announced by Ian Murdock in 1993 as the
“Debian Linux Release”. The Debian Project is a community of developers and users that maintain the GNU OS
based on open source software. Currently, Debian systems use the Linux kernel or the FreeBSD kernel. However,
they are also working on providing Debian for other kernels. Primarily, GNU Hurd.
Debian License: BSD, GPL and other open licenses.
Debian Latest major release: Debian 12.7 (Bookworm).
CentOS Linux
CentOS Linux is a distribution based on the source code of the commercial distribution Red Hat Enterprise Linux
(RHEL). It was launched in 2004 and is backed up by a growing community. It is a safe bet for those looking for high-
quality code. But CentOS 8 will be its last version. In 2019, Red Hat announced that CentOS Linux would be replaced
by CentOS Stream — an upstream development platform for RHEL. New open source alternatives have appeared
due to this change of strategy. For instance, Rocky Linux, founded by Gregory Kurtzer, founder of the CentOS
project.
CentOS Linux License: GNU GPL.
CentOS Linux Latest major release: CentOS Linux 8.
CentOS Stream
CentOS Stream is an upstream development platform for Red Hat Enterprise Linux (RHEL). It is a midstream
between Fedora Linux and RHEL. This platform aims to take advantage of open-source innovation for shaping
upcoming stable RHEL releases.
CentOS Stream License: GNU GPL.
CentOS Stream Latest release: CentOS Stream 9.
Red Hat Enterprise Linux (RHEL)
Red Hat Enterprise Linux (RHEL) is a commercial Linux distribution developed by Red Hat. It has a server version
and a desktop version. As it uses open source software, published under a General Public License, they make their
code available to the public via CentOS. Red Hat has sponsored the CentOS project since 2014.
RHEL License: GPL.
RHEL Latest major release: RHEL 9.
Gentoo
Gentoo is a Linux distribution that features a rolling release model. Gentoo Linux was originally created by Daniel
Robbins. It was named after the fast-swimming “gentoo penguin”, to reflect its potential. It is an attractive choice
for Linux users looking for full control of the software. Gentoo users have great control over the services installed
and running on their computer. They can immensely customize and optimize their system.
Gentoo License: Free software.
Gentoo Releases: rolling release.
Fedora
Fedora is a Linux distribution developed by the Fedora Project — sponsored mainly by Red Hat, with support from
other companies. It is developed and maintained by the community and it is an upstream source of the commercial
RHEL distribution. Fedora usually has more modern software versions, considered as “non stable”, that are later
included in RHEL. There are different Fedora editions available: Workstation, Server, CoreOS, Silverblue and IoT.
Fedora Linux was launched in 2003.
Fedora License: GPL and other licenses.
Fedora Latest major release: Fedora 40.
OpenSUSE
OpenSUSE is a Linux distribution sponsored by SUSE Software Solutions Germany GmbH and other companies. It
was formerly known as SUSE Linux. OpenSUSE has a rolling release version, Tumbleweed, and a regular release
version, Leap.
OpenSUSE License: GNU GPL and other licenses.
OpenSUSE Latest release: OpenSUSE Leap 16.
Scientific Linux
Scientific Linux is another Linux distribution based on RHEL’s free and open source software. It is produced by
Fermilab, CERN, DESY and ETH Zurich. In April 2019, they announced its discontinuation. Nevertheless, its last
version, Scientific Linux 7, will have maintenance updates until June 2024.
Scientific Linux License: GNU GPL and other licenses.
Scientific Linux Latest release: Scientific Linux 7.
CloudLinux
CloudLinux is a Linux distribution developed by CloudLinux, Inc. It is based on CentOS and uses the OpenVZ kernel
and the RPM Package Manager. It is targeted to shared hosting providers and data centers. It stands out for
improving server stability, density and security. The first version of CloudLinux OS was released in 2010.
CloudLinux Latest release: CloudLinux 9.4.
Elementary OS
Elementary OS is a Linux distribution based on Ubuntu. The OS is developed and maintained by Elementary, Inc. It
aims to be a fast, open and privacy-respecting alternative to Windows and MacOS. It features a pay-what-you-want
(PWYW) model.
Elementary OS License: GNU GPL and other licenses.
Elementary OS Latest release: Elementary OS 7.1 (Horus).
Linux Mint
Linux Mint is a community-driven Linux distribution based on Ubuntu. This distribution started in 2006. The Linux
Mint project was initially created by Clément Lefèbvre. Linux Mint OS’ source code is available on GitHub. Most of
the OS development is done in Python.
Linux Mint License: GPL.
Linux Mint Latest release: Linux Mint 22.
Arch Linux
Arch Linux is a Linux distribution based on 5 principles: simplicity, modernity, pragmatism, user centrality and
versatility. It features a rolling release model.
Arch Linux License: GNU GPL and other licenses.
Arch Linux Release: rolling release.
Manjaro
Manjaro is a free Linux distribution based on Arch Linux. It is specially focused on accessibility and user-friendliness.
It features a rolling release model. Its simplicity, stability and performance makes it a suitable alternative OS to
MacOS and Windows. It offers multiple desktop environments.
Manjaro License: GPL and other open licenses.
Manjaro Latest release: Manjaro 24.1.1.
Oracle Linux
Oracle Linux (OL) is a Linux distribution packaged and distributed by Oracle; under GNU GPL since late 2006. It was
formerly known as Oracle Enterprise Linux (OEL). It is based on RHEL’s source code. Oracle Linux is available with
two Linux kernels: the Red Hat Compatible Kernel (RHCK) and the Unbreakable Enterprise Kernel (UEK).
Oracle Linux License: GNU GPL and other licenses.
Oracle Linux Latest major release: Oracle Linux 9.
Slackware
Slackware is one of the oldest Linux distributions, created by Patrick Volkerding in 1993. Many Linux distributions
have been based on Slackware; for instance, the first versions of the SUSE Linux distribution. It was originally based
on the Softlanding Linux System (SLS), one of the most popular original Linux distributions.
Slackware License: GNU GPL.
Slackware Latest major release: Slackware 15.0.
Mageia
Mageia is an open source, Unix-like operating system that started as a fork of Mandriva Linux back in 2010. It was
created by former employees of Mandriva S.A. and some members of the Mandriva community. It stands out for
being a secure, stable and sustainable OS. Besides, it provides a really large software repository. Its first version,
Mageia 1, was released in June 2011.
Mageia License: GPL and other licenses.
Mageia Latest major release: Mageia 9.
Clear Linux
Clear Linux is an open source Linux distribution created by Intel. It is updated following a rolling release model. The
OS is optimized for performance and security from the cloud to the Edge; as well as for Intel products. Clear Linux’s
main targets are IT, DevOps, Cloud and AI professionals; it is not designed as a general-purpose distribution. Its
source code is available on GitHub.
Clear Linux License: GPL and other licenses.
Clear Linux Releases: rolling release.
Rocky Linux
Rocky Linux is an open source Linux distribution, based on the source code of the commercial distribution RHEL.
This Linux distribution is led by Gregory Kurtzer — founder of CentOS, together with Rocky McGaugh. Rocky Linux
aims to fill the gap CentOS will leave as a community-supported, downstream of RHEL, after CentOS 8’s
discontinuation by December 2021. As explained on Rocky Linux’s Wiki, this distribution aims to be “a solid, stable
and transparent alternative for production environments, developed by the community for the community”.
Stackscale provides two of its public mirrors in Madrid and Amsterdam.
Rocky Linux License: BSD and other licenses.
Rocky Linux Latest release: Rocky Linux 9.4.
AlmaLinux
AlmaLinux is a free, open source Linux distribution; compatible with RHEL. It is focused on long-term stability and
governed by the community; with regular releases. AlmaLinux OS is sponsored by CloudLinux Inc. and supported by
other sponsors. It is also a good alternative for those who are currently using CentOS, after its discontinuation by
the end of 2021.
AlmaLinux License: GPLv2 and other licenses.
AlmaLinux Latest release: AlmaLinux 9.4.
Asahi Linux
Asahi Linux is a Linux distribution that intends to port Linux to Apple Silicon Mac computers. The goal is to make
Linux run on Apple Silicon Mac computers so as to be used as a daily OS. This distro is developed by a community of
free and open source software developers. Asahi Linux’s first Alpha version was released in March, 2022.
Asahi Linux License: General Public License v2 or MIT.
Asahi Linux Latest release: Asahi Linux Alpha Release.
Lubuntu
Lubuntu is a Linux distribution based on Ubuntu and developed by the Lubuntu community. It stands out for being
lightweight, fast and offering great compatibility with many formats and applications. Besides, it offers a Software
Center with a large number of free apps that can be safely downloaded.
Lubuntu License: GNU GPL and other licenses.
Lubuntu Latest release: Lubuntu 24.04.
SUSE Linux
SUSE Linux, also known as SUSE Linux Enterprise Server, is a Linux distribution, adaptable to any environment and
optimized for security, reliability and performance. Originally based on Slackware, its first version was released in
1994. As Slackware, SUSE Linux is one of the oldest Linux distributions.
SUSE Linux Latest release: SUSE Linux Enterprise Server 15 SP6.
Knoppix
Knoppix is a free, open source Linux distribution based on Debian, developed by Klaus Knopper. It was mainly
designed to be used as a Live CD, but it can also be installed on a hard disk like any other OS.
Knoppix License: free software licenses.
Knoppix Latest release: Knoppix 9.2.
VzLinux
VzLinux is a free and open source Linux distribution. It is a 1:1 clone of Red Hat Enterprise Linux and offers an easy
conversion from CentOS. It can also be used as a guest OS in different hypervisors.
VzLinux Latest release: VzLinux 9.
Peppermint OS
Peppermint OS is a lightweight Linux distribution based on Debian Stable. It changed from Ubuntu to Debian in
2022. This OS is a beginner-friendly distribution, intuitive and easy to use.
Peppermint License: free software licenses.
Peppermint Latest release: Peppermint OS 11.
Zorin OS
Zorin OS is a Linux distribution based on Ubuntu, designed as a powerful and secure alternative to Windows and
MacOS. Zorin OS is easy to use and its Appearance app allows users to change the desktop layout to the OS
environment appearance they are familiar with — Windows, MacOS or Linux.
Zorin OS License: free software.
Zorin OS Latest release: Zorin OS 17.2.
BlackArch Linux
BlackArch Linux is an open source Linux distribution based on Arch Linux. It is especially designed for penetration
testers and security researchers and it provides a lot of cybersecurity tools. The last version was released in
September, 2021.
BlackArch Linux License: several licenses.
SUSE Liberty Linux
SUSE Liberty Linux is an enterprise-grade Linux distribution born to be an alternative to CentOS Linux, which has
been replaced by a rolling release. It is focused on providing a secure distribution for mixed Linux environments.
This new distro is developed by SUSE, using its Open Build Service tool. Besides, it is based on the SUSE Linux
Enterprise Server kernel (SLES kernel).
SUSE Liberty Linux Latest release: SUSE Liberty Linux 9.
Navy Linux
Navy Linux is a minimalistic installation of the Linux OS, based on Red Hat Enterprise Linux. This open source
distribution was founded in January 2021 by UnixLab, as a replacement for CentOS Linux. It is focused on
minimizing hardware resources requirements to build a stable and secure Linux distro.
Navy Linux License: GNU GPL.
Navy Linux Latest release: Navy Linux 8.6.
Tizen
Tizen is an open-source, mobile operating system based on Linux. It was released in 2012 and it is developed by
Samsung and backed by the Linux Foundation. The Tizen OS is primarily used in Samsung’s smart devices — TVs,
smartwatches, etc. It is intended to provide seamless connectivity and user experience between connected devices.
Tizen License: GPLv2, LGPL, Apache License 2.0, BSD, Flora License and Freeware.
Tizen Latest release: Tizen 7.0.
List of popular Linux distributions
Here is the list of popular Linux distributions organized alphabetically:
Linux distribution License Last release (As of june 2023)
AlmaLinux GPLv2 and other licenses AlmaLinux 9.4
Arch Linux GNU GPL and other licenses Rolling release
Asahi Linux General Public License v2 or MIT Asahi Linux Alpha Release
BlackArch Linux Several licenses –
CentOS Linux GNU GPL CentOS Linux 8
CentOS Stream GNU GPL CentOS Stream 9
Clear Linux GPL and other licenses Rolling release
CloudLinux – CloudLinux 9.4
Debian BSD, GPL and other open licenses Debian 12 (Bookworm)
Elementary OS GNU GPL and other licenses Elementary OS 7 (Horus)
Fedora GPL and other licenses Fedora 40
Gentoo Free software Rolling release
Knoppix Free software licenses Knoppix 9.2
Linux Mint GPL Linux Mint 22.1
Lubuntu GNU GPL and other licenses Lubuntu 24.04
Mageia GPL and other licenses Mageia 8
Manjaro GPL and other open licenses Manjaro 22.1 (Talos)
Navy Linux GNU GPL Navy Linux 8.6
Oracle Linux GNU GPL and other licenses Oracle Linux 9
OpenSUSE GNU GPL and other licenses OpenSUSE Leap 15.5
Peppermint OS Free software licenses –
Red Hat Enterprise
GPL RHEL 9
Linux
Rocky Linux BSD and other licenses Rocky Linux 9.4
Scientific Linux GNU GPL and other licenses Scientific Linux 7
Slackware GNU GPL Slackware 15.0
SUSE Liberty Linux – SUSE Liberty Linux 9
SUSE Linux Enterprise Server 15
SUSE Linux –
SP6
GPLv2, LGPL, Apache License 2.0, BSD, Flora License and
Tizen Tizen 7.0
Freeware
Ubuntu GPL and other licenses Ubuntu 24.04 LTS
VzLinux – VzLinux 9
Zorin OS Free software Zorin OS 17.2
What is Linux?
Linux is the most popular and well-known open source operating system used to directly handle a system's
hardware and resources, such as the CPU, memory, and storage. Linux serves as an operating system (OS) between
software and hardware. It connects your applications to the hardware resources that do the task. Linux is widely
utilized in the operating systems of modern supercomputers, smart gadgets, and internet infrastructure
equipment. The most well-known of them is the operating system developed by Google, called Android.
What does Linux Include?
The Linux operating system consists of the following components:
 Bootloader: The software that controls the computer's launch procedure. For the majority of users, this is merely a
welcome screen that appears and disappears as the operating system loads.
 Kernel: The fundamental component of the operating system. Without it, the OS cannot function. The kernel is
responsible for managing system resources and communicating with hardware. It is responsible for managing
memory, processes, and files. The OS's lowest level is the kernel.
 Init system: This subsystem is responsible for controlling daemons and bootstrapping the user space. systemd,
which is one of the most popular init systems, is also one of the most controversial. The init system manages the
launch process after the bootloader (such as GRUB or GRand Unified Bootloader) has completed the initial booting.
 Applications: A variety of software that enables the completion of a mission. Apps range from desktop utilities and
programming languages to multi-user business suites. Most Linux distributions provide a central repository for
searching and downloading additional applications. Linux, like Windows and macOS, offers tens of thousands of
high-quality software titles that can be found and installed with relative ease. The vast majority of contemporary
Linux distributions include App Store-like utilities that centralize and facilitate application installation. For instance,
Ubuntu Linux includes the Ubuntu Software Center (a rebranding of GNOME Software), which enables you to
search and install thousands of applications from a central location.
 Daemons: These are secondary services (printing, sound, scheduling, etc.) that start up either during launch or after
logging into the desktop.
 Desktop environment: This is the portion with which consumers interact. There are numerous desktop
environments (GNOME, Cinnamon, Mate, Pantheon, Enlightenment, KDE, Xfce, etc.) to choose from. Each desktop
environment includes pre-installed applications (file managers, configuration tools, web browsers, and games, for
example).
 Graphical server: This is the subsystem that displays the graphics on your monitor. It is commonly known as the X
server or simply X.
History of Linux
At AT & T's Bell Labs in the United States, the Unix operating system was developed and put into use in 1969 by Ken
Thompson, Dennis Ritchie, Douglas McIlroy, and Joe Ossanna. As was customary at the time, Unix was fully in
assembly code when it was first published in 1971. Except for a few hardware and I/O routines, Dennis Ritchie
rewrote them in the C programming language in 1973, a very innovative move. The ability to develop Unix in a
high-level language made it simpler to adapt it to many computing platforms.
Due to an earlier antitrust case prohibiting it from joining the computer industry, AT & T licensed the operating
system's source code as a trade secret to anybody who inquired. As a result, Unix expanded swiftly and was widely
used by corporations and academic institutions. AT & T started selling Unix as a proprietary product in 1984 after
AT & T was freed from its requirement to refrain from entering the computer industry. However, users were not
permitted to change Unix under this private product model.
In 1980, Onyx Systems started selling early Unix workstations powered by microcomputers. Sun Microsystems later
started selling Unix-based desktop workstations in 1982 after being created as a spin-off of a Stanford University
student project. Sun workstations constituted the first successful commercial attempt at delivering a predominantly
single-user microcomputer that ran a Unix operating system, despite not using common PC hardware like Linux was
later created for.
Richard Stallman launched the GNU Project in 1983 with the intention of developing a "full Unix-compatible
software system" made up completely of free software. Work started in 1984. Stallman founded the Free Software
Foundation in 1985 and the GNU General Public License (GNU GPL) in 1989, respectively. Many of the operating
system programs (such as libraries, compilers, text editors, a command-line shell, and a windowing system) were
finished by the early 1990s, but low-level components like device drivers, daemons, and the kernel, known as GNU
Hurd, remained stuck and unfinished.
A simple Unix-like operating system called MINIX was developed by computer science professor Andrew S.
Tanenbaum and released in 1987 with the intention of teaching operating system fundamentals to students and
others. The licensing conditions kept MINIX from being free software until the licensing changed in April 2000,
despite the fact that the whole source code was freely accessible.
NetBSD, OpenBSD, and FreeBSD all came from 386BSD, which was made before Linux, even though it wasn't
released until 1992 because of legal issues.
Several times, Linus Torvalds, the main developer of the Linux kernel, has admitted that he probably would not
have developed Linux if the GNU kernel or 386BSD had been around in 1991.
In the fall of 1990, Torvalds enrolled in a Unix course as a student at the University of Helsinki. "Operating Systems:
Design and Implementation" by Andrew S. Tanenbaum was one of the required texts for the course, which made
use of a MicroVAX minicomputer running Ultrix. A copy of Tanenbaum's MINIX operating system was provided in
this textbook. Torvalds' introduction to Unix came through this course. He started working on his operating system
kernel, which ultimately became the Linux kernel, in 1991 after becoming frustrated with MINIX's license, which at
the time restricted it to educational use only.
Applications created for MINIX were also utilized on Linux when Torvalds started working on the Linux kernel.
Later, as Linux grew older, more Linux kernel development was done on Linux-based systems. Because it was
advantageous to use the freely accessible code from the GNU Project with the developing operating system, GNU
applications also replaced all MINIX components. Code covered by the GNU GPL can be reused in other software
applications as long as those programs are also released under the same or a similar license. The GNU GPL was
introduced at Torvalds' initiative as a replacement for his earlier license, which forbade commercial redistribution.
The Linux kernel and GNU components were combined by programmers to create a fully functional and open
operating system.
What is Linux used for?
Linux is utilized to manage multiple services, such as process scheduling, application scheduling, fundamental
peripheral devices, and file systems. Linux can run any type of program you're used to running on Windows or
macOS, from basic calculators to sophisticated graphics editing tools.
Kubernetes, Docker, and Open Daylight (used to accelerate the adoption of SDNs and Network Functions
Virtualization) are examples of Linux-based products that have had a significant impact on the IT industry and have
become indispensable to the tech stacks of a large number of organizations. In addition, cloud service providers
favor Linux-based operating systems due to their free and open-source nature.
Linux can be found in a variety of contexts and has the following use cases:
 Headless Systems: Linux is used for headless server systems that do not need a graphical user interface (GUI) or a
terminal and keyboard that are directly linked. Headless systems are often used for remotely operated network
servers and other devices.
 Network Devices: Linux is a common network operating system for routers, switches, DNS servers, home
networking devices, and more. Cisco, for instance, provides a version of the Cisco Internetwork Operating System
(IOS) that employs the Linux kernel.
 Embedded Devices: Linux is used as an embedded operating system for a range of applications, such as home
appliances, automobile entertainment systems, and network file system appliances with modest computing needs.
 Cloud: Linux is used as a cloud operating system for cloud instances. Major cloud computing service providers
provide Linux-powered cloud instances for cloud servers, desktops, and other services.
 Servers: Server operating system for web servers, database servers, file servers, email servers, and other types of
shared servers. Linux is well-suited for all sorts of server applications due to its capacity to run high-volume and
multithreading applications.
 Desktops: Operating system for desktop productivity computing. Linux is a free, open-source desktop environment
for those who prefer it over proprietary operating systems. Linux OS is used for the following purposes by end
users:
 Office Jobs: A full office suite, such as LibreOffice, Apache OpenOffice, or Calligra Suite, is generally included with
Linux. On Linux, Microsoft Office won't operate natively (although for the dedicated user, we do have some
workarounds). However, one of those alternatives will suffice for the majority of customers' office requirements.
The majority of them work without a hitch to open, edit, export, and save files. DOC, DOCX, XLSX, PDF, and other
extensions. Some even offer more sophisticated features like tracking changes and macros.
o Emailing: In addition to using webmail in a browser, there are several Linux email programs you can use to manage
your inbox. Thunderbird and Evolution are a couple of the well-liked options. They frequently provide you with an
interface that is more sleek and streamlined than Microsoft Outlook.
o Using a web browser: Web browsers are a necessary component of any modern PC and are always included in
Linux desktop packages. Most computers come pre-installed with Firefox or Chromium, but you can also get
ordinary Chrome, Microsoft Edge, or Brave.
o Gaming: Contrary to popular belief, Linux is compatible with gaming. How is that even doable? This is owing in part
to the Linux application Wine, also known as PlayOnLinux, which enables the running of Windows programs on
Linux. Even though it's true that many well-known games don't have native Linux versions, Wine enables you to
work around this issue.
o Audio and graphic editing: Most distributions will have at least one graphics editing program pre-installed.
Unfortunately, without the assistance of the aforementioned Wine tool, you won't be able to install the Adobe
Creative Suite on Linux. However, there are several available options, many of which are free, such as GIMP or
Inkscape. More sophisticated audio editors and mixers like Cecilia and Mixxx, as well as Audacity, are simple to
install on Linux. You can also choose from a wide variety of open-source and free video editors. For more dedicated
artists, Linux environments are even available.
o Multimedia Playback and Streaming: Like any other operating system, Linux is completely capable of playing your
favorite audio, video, and podcasts. Numerous additional Linux apps will stream music from other locations or play
local music, and Spotify provides a native desktop version for Linux. For video, Celluloid and VLC Player both
support this. With the file manager and picture viewer that your Linux distribution contains, you can also browse
and organize your photo library.
What are the Benefits of Linux OS?
Compared to other operating systems, Linux has the following advantages:
 Open Source: Software that is open-source allows anybody to contribute, edit, and improve the source code.
Additionally, it is free to download and use by users.
 Secure: Compared to Windows operating systems, Linux is more secure and less prone to attack. The administrator
must enter a password in order to authorize each program in the application. Linux reduces the likelihood that any
malware will be executed in this way.
 License expenses: Linux, unlike Microsoft Windows and Apple macOS, does not need explicit license costs. While
many Linux companies offer system support for a charge, the OS itself is free to copy and use. Some IT businesses
have boosted their savings by migrating from a commercial server operating system to Linux.
 Revive outdated computer systems: - Linux, which makes use of antiquated technologies like firewalls, backup
servers, low-end systems, etc., can resurrect old and out-of-date PCs.
 Reliability: Linux is regarded as a trustworthy operating system and is well-supported with security updates. Linux
is also regarded stable, indicating that it can function in the majority of situations. Linux also handles software-
related failures and unexpected input.
 Easy to update: Linux offers quicker and simpler software updates than Windows does.
 Lightweight: Linux is portable. Linux has far fewer system requirements than other operating systems. Linux has a
smaller memory footprint and storage space. In general, the majority of Linux distributions needed 128MB or less
of RAM and the equivalent amount of disk space.
 Easy to manage: With customization, users may quickly add or remove features as desired, as well as add icon sets
and wallpapers. Unlike Windows, no restart is required after installing and removing apps.
 Backward Compatibility: Linux and other open source software are routinely patched for security and functionality
while preserving their fundamental functionality. It is probable that configurations and shell scripts will continue to
function normally once software upgrades have been implemented. In contrast to commercial software companies
that release new versions of their operating systems along with new modes of operation, Linux and open source
programs often do not modify their modes of operation when releasing new versions.
 Easy to Install: The Linux installation procedure is quicker than that of Windows and other operating systems. In
addition, its installation procedure is much simpler since it involves less human input. It requires little additional
system settings and may be readily installed on older devices with little configuration.
 Rich Distribution Options: Linux comes in a variety of distributions, or distros, including Fedora, Ubuntu, Arch
Linux, Debian, Linux Mint, and others. These distributions give consumers more feature options.
 Community Assistance: Linux has huge community support. Linux users obtain help in a variety of places. There are
several online forums for customer assistance. Additionally, developers from other open-source communities are
willing to assist people.
 Ideal for Programming: Linux is widely used by programmers, so there is a wealth of online assistance for faults or
situations.
 Stability: Linux systems rarely experience performance issues or failures.
 Privacy: To protect user privacy, Linux does not gather a lot of information from users.
 Efficiency: Without sacrificing efficiency, many networks and workstations can operate concurrently.
 Executable File Types: Almost all file types are supported by Linux for execution.
 Multitasking: It is a multitasking operating system because it can execute numerous processes concurrently
without slowing down the system.
 Multiple Desktop Support: Linux system offers numerous desktop environment support for its increased usage.
During installation, the desktop environment option may be chosen. Both GNOME (GNU Network Object Model
Environment) and KDE (K Desktop Environment) have their own environment, therefore we may choose any
desktop environment.
 Networking: Linux enables networking with robust networking functionality. The client-server systems are readily
adaptable to Linux. It includes a variety of command-line utilities, including ssh, IP, mail, and telnet, for connecting
to other computers and servers. The backup of a network is much quicker than other tasks.
Figure 1. Benefits of Using Linux
What are the Disadvantages of Linux OS?
Compared to other operating systems, Linux has several disadvantages, some of which include problems with
system compatibility, a steep learning curve, difficulties with software interoperability, inadequate standardization,
a lack of commercial backing, and inadequate support for gaming. These Linux drawbacks are explained below.
 System Compatibility: Certain hardware devices receive limited or no support in Linux. This could be due to a
number of factors, including the device's lack of an open-source driver or the manufacturer's refusal to provide
Linux-compatible drivers.
To avoid hardware compatibility issues, it is essential to verify that your hardware devices are compatible with
Linux before installing the operating system. This may involve visiting the manufacturer's website to determine if
Linux drivers are available or browsing online for information regarding the compatibility of particular hardware
devices.
Although hardware compatibility can be an issue with Linux, taking the time to verify compatibility prior to
installing the operating system can help you avoid potential problems and ensure that your hardware devices
function as intended. This issue with hardware compatibility is one of Linux's disadvantages.
 A Steep Learning Curve: Linux has a harsher learning curve than other operating systems, such as Windows and
macOS, which is one of its primary disadvantages. Linux frequently requires command-line interfaces for certain
duties, such as software installation and system configuration. This may take some getting used to for users
accustomed to graphical user interfaces (GUIs).
Linux offers advanced customizability and flexibility, which means that users may need to learn how to configure
various aspects of the system in order to maximize its capabilities. This may require modifying configuration files or
using command-line tools, which some users may find intimidating.
In addition, Linux can have a steeper learning curve, but there are numerous user-friendly distributions that can
mitigate this issue. These distributions are ideal for beginners and typically include graphical user interfaces that
resemble those of other operating systems, as well as software that facilitates the completion of common duties.
 Software interoperability: A further potential disadvantage of Linux is that not all software and applications are
readily accessible. This is due to the fact that many software developers concentrate on creating applications for
Windows and macOS, which have larger user bases. However, users can circumvent this issue in a variety of
methods.
Many open-source and free software applications are available for Linux and can be used in lieu of proprietary
software. The LibreOffice suite, for instance, provides equivalent functionality to Microsoft Office, while GIMP can
be used as an alternative to Adobe Photoshop.
Users can utilize compatibility layers, such as Wine, to execute select Windows applications on Linux. Wine does
not support all Windows applications, but it can provide a solution for users who need to execute a specific
program.
 Unsufficient standardization: The lack of standardization in the Linux ecosystem is another drawback. Unlike
Windows and macOS, which have a centralized approach to software distribution and standardization, Linux has a
decentralized approach with numerous distributions and package formats.
This fragmentation may result in compatibility issues between different distributions. Some software applications,
for instance, may only be available in specific package formats that may not be compatible with all distributions.
This results in incompatibility issues when attempting to install software on various distributions, which is
extremely aggravating for users.
With the increasing prevalence of Linux and the community's efforts to standardize aspects of the ecosystem, this
concern may diminish in the near future.
 Lack of Commercial Support: Linux lacks the same level of commercial support as competing operating systems.
This can make it difficult for users to obtain assistance when operating system problems or issues arise. For
instance, a user may be unable to locate a commercial support team that can assist them with Linux
troubleshooting.
 Poor Gaming Support: Similarly to software, games do not support Linux natively. Because Linux is not a widely
adopted platform, gaming developers have little interest in it. You cannot therefore anticipate your beloved game
to function on Linux. In recent years, however, the number of games developed for Linux has increased. Even
though you can obtain any game using third-party software, the game will not function as efficiently as it does on a
native operating system.
The advantages and disadvantages of Linux are listed in the following table:
Advantages Disadvantages
Open Source System Compatibility
Secure & Reliable A Steep Learning Curve
License expenses Software interoperability
Backward Compatible Unsufficient standardization
Easy to install & update & manage Lack of Commercial Support
Lightweight Poor Gaming Support
Community Assistance
Rich Distribution Options
Ideal for Programming
Stability
Privacy
Efficiency
Multitasking
Multiple Desktop Support
Robust networking
Table 1. Advantages & Disadvantages of Linux
What Does "Linux Distribution" mean?
A "Linux distribution", often shortened to "distro", is an operating system made from a group of software that
includes the Linux kernel and, often, a package management system. Linux users often download one of the Linux
distributions, which are available for everything from powerful supercomputers (like OpenWrt) to embedded
devices (like Linux Mint) and personal computers (like Ubuntu Desktop).
A typical Linux distribution includes a Linux kernel, GNU tools and libraries, extra software, documentation, a
window manager, a desktop environment, and one or more window systems, most often the X Window System or,
more recently, Wayland.
Most of the software that is included is free and open source. The source code and generated binaries are
available, so the original program can be changed. Usually, Linux distributions have the option to include
proprietary software that may not be available in source code form, such as binary blobs needed for some device
drivers.
A Linux distribution is a set of tools and utilities, like different GNU tools and libraries, that are packaged with the
Linux kernel in a way that lets it meet the needs of many different users.
Most of the time, the people who take care of the distribution change the software for it before compiling it into
software packages. The software programs can be found online in repositories, which are storage spaces that are
often spread out all over the world. There are very few packages that are actually built by a distribution's
maintainers aside from "glue" components like the package management systems and installers (like Debian-
Installer and Anaconda).
There are almost a thousand Linux distributions.
Distributions come in a wide range of shapes and sizes because there is so much software out there. There are
distributions that can be used on desktops, servers, laptops, netbooks, mobile phones, tablets, and in the minimal
environments that are usually found in embedded devices. There are distributions like Fedora Linux (Red Hat),
openSUSE (SUSE), and Ubuntu (Canonical, Ltd.), which get money from companies, and distributions like Debian,
Slackware, and others, which only get money from the community. Most distributions are already compiled and
ready to use for a certain instruction set. However, some, like Gentoo, are mostly distributed as source code and
must be compiled locally in order to be installed.
Which are the most popular Linux distros?
With approximately 3-3.5 billion users worldwide, Linux is one of the most popular operating systems. Because it
can be changed and is open source, a lot of Linux distributions with strong features have been built on top of it.
These are the top Linux distributions:
1. Ubuntu: Ubuntu is a free and open-source Linux distribution that comes in three flavors: Desktop, Server, and Core
for IoT. Ubuntu is easy to use. It comes with free software like LibreOffice, Firefox, Thunderbird, and Transmission,
as well as games like Sudoku and chess. Aside from its ease of use, the operating system is known to be more
secure than Windows. It is not immune to viruses, but it has a much lower risk of exposure. It is easy to change, so
you can make your Ubuntu environment fit your needs. For example, you may quickly configure your Ubuntu
server as a router in your home or office network.
2. CentOS: Because its software is simple and light, CentOS runs faster than other Linux distributions. The operating
system has a longer upgrade cycle, lasting approximately five years. (Other distributions have shorter cycles.)
Because of the more frequent updates, those other distributions may be less reliable at times. As a result, CentOS is
regarded as a stable operating system. EOL for CentOS Linux 8 is December 31, 2021 and CentOS Project has
refocused its efforts from CentOS Linux to CentOS Stream, as declared in December 2020.
3. Fedora: Fedora is also known for being a stable and dependable operating system. Fedora has a lot of graphical
tools and useful software for office work, virus protection, system management, playing media, learning, and other
things. Because of its popularity, it is supported by a large community, which is an important consideration when
selecting open-source software.
4. Debian: Debian is a stable Linux distribution, but it also lets early adopters try out packages that aren't quite ready
yet. In comparison to the alternatives, Debian provides the most packages. The time it takes to upgrade Debian is
also long, which means you can keep using the same version for a long time. This keeps you from having to upgrade
software often and restart your server to make the changes take effect. People think it's a great Linux distribution
for running servers because its software is stable and it comes out less often.
5. Red Hat Enterprise Linux: Red Hat Enterprise Linux (RHEL), which calls itself the "world's leading enterprise Linux
platform," is used for a lot of different things, such as making software and running hardware. RHEL is well-known
for its stability and speed. It works well with third-party software and has a quick security patch cycle. Because this
distribution is run by Red Hat, a multinational software company, you will get great support.
6. Linux Mint: Mint has become one of the most popular Linux distributions since it first came out in beta in 2006. If
you use Windows, you will be familiar with its user interface. When switching to a new Linux distribution, there
may be a learning curve, but Mint's simple UI and ease of use can help to reduce that. Furthermore, it includes
many useful apps by default, such as Firefox, LibreOffice, and others. It has an effective app management tool. You
can search for and install software visually using an internal software manager that works like the App Store.
7. OpenSUSE: OpenSUSE gives its users a stable environment and works well with almost all of the best Linux desktop
apps. The distribution is simple in software management. You can search for tools on software.opensuse.org and
install them directly from there. OpenSUSE is a great choice for both home and business use because it has so many
benefits. If you don't want to, you don't have to keep updating your operating system after installing the distro. You
can just install it and use it.
8. Manjaro: Manjaro, which was released in 2011, has quickly become one of the most popular Linux distributions.
Manjaro has distinct advantages over other distributions. Manjaro, in particular, excels at hardware support. Some
Linux distributions require you to take extra steps to make your hardware work, such as manually installing drivers
and packages, which can be time-consuming. Manjaro, on the other hand, makes this process much easier. It scans
your hardware and installs the necessary drivers and packages automatically. Unlike other distros, you don't have
to deal with a broken Personal Package Archive (PPA) when you want to install software that isn't supported by the
repository.
9. Elementary: Elementary OS, which was released in 2011, distinguishes itself from other distributions by including
its own desktop environment called Pantheon. It has its own user interface and apps as well. Elementary OS has a
minimalist design that focuses on simplicity, making it simple to learn. This minimalist design allows users to focus
on what is important and increases productivity.
10. OS Zorin: For those new to Linux distributions, Zorin OS is a good place to start. Its user interface looks like
Windows, and in Zorin's premium editions of OS 9, you can change the user interface to look like Apple's Mac OS.
One of Zorin's strengths is its speed, and its operating system supports over 55 languages.
11. Kali Linux: Kali Linux is the best distribution for ethical hacking objectives. Frankly, no other distribution can
compete with Kali Linux. The release includes a variety of tools that may be used for ethical hacking. Device
categories include wireless assaults, stress testing, online applications, vulnerability analysis, and exploration
instruments, among others.
Because Kali Linux is derived from the Debian Testing branch, the majority of packages are imported from the
Debian repository. In prior versions, updates were not sent in an unreliable manner. In the most recent version,
however, it has worked with Offensive Security and Cloudflare to ensure that all upgrades are successfully
transmitted.
Kali Linux is installed on a variety of platforms, including Chromebook, Raspberry Pi, BeagleBone, and others. This is
one of its major features. In addition, with the introduction of Kali NeHunter, Android cellphones are now
supported. Regular rolling updates, tried-and-true hacking tools, vast learning materials, and a solid Debian
foundation are some of the advantages of adopting Kali Linux.
Kali Linux has always been available for free and in numerous languages. It is extremely configurable and comes
with over 600 penetration and security testing tools.
It is the most extensively used distribution for penetration testing on a global scale. The quantity of built-in
penetration tools makes ethical hackers' lives easier. In addition to providing a sophisticated platform for
penetration testing, it also provides learning opportunities for budding ethical hackers. Additionally, it has an active
community and adequate documentation.
12. IPFire: IPFire is a fortified open-source Linux distribution whose main role is as a firewall and router. A web-based
administrative interface is used for configuration. IPFire Linux Firewall is one of the finest and most effective open-
source firewalls for any individual or business network.
IPFire's primary objective is your safety. Simple to configure, the firewall engine and intrusion detection system
prevent attackers from accessing your network. In the default configuration, the network is split into different
zones with independent security rules, such as a LAN and a DMZ, in order to limit hazards inside the network and
provide customized configurations for the specific requirements of each network segment.
IPFire employs a Stateful Packet Inspection (SPI) firewall that is based on Netfilter, the Linux packet filtering
framework. It swiftly filters packets and has throughputs of tens of gigabits per second.
Pakfire, IPFire's proprietary package management system, may be used to install add-ons that enhance the
capabilities of the firewall. Administrators may utilize add-ons as command-line tools or to expand the capabilities
of the system.
IPFire's Intrusion Detection System (IDS) examines network traffic for exploits, data breaches, and other suspicious
activity. When an attacker is found, alerts are generated and the offender is immediately blocked.
What are the Basic Features of Linux?
The following are some of the most important features of the Linux operating system:
 Portable means that software can run on different types of hardware in the same way. The Linux kernel and
application programs can be installed on any hardware platform.
 The source code for Open Source Linux is freely available, and it is a community-based development project.
Multiple teams collaborate to improve the capability of the Linux operating system, which is constantly evolving.
 Linux is a multiuser system, which means that multiple users can access system resources such as
memory/ram/application programs at the same time.
 Linux is a multiprogramming system, which means that multiple applications can run at the same time.
 The Hierarchical File System (HLFS) provides a standard file structure for arranging system and user files.
 Linux Shell includes a special interpreter program that can be used to execute operating system commands. It can
be used to perform various operations, such as calling application programs.
 Linux provides user security through authentication features such as password protection, controlled access to
specific files, and data encryption.
Is Linux Open Source?
Yes. One of the most well-known instances of open-source, free software is Linux. As long as they follow the rules
of the licenses, like the GNU General Public License (GPL), anyone can use, change, and share the source code for
commercial or non-commercial purposes. For example, the Linux kernel is licensed under the GPLv2, but system
calls are an exception. Otherwise, any software that uses the kernel would be considered a derivative, and the GPL
would have to apply to that application.
Basic Terms you should know about Linux
A command in Linux is a program or utility that runs from the command line. A command line is an interface that
turns lines of text into instructions for the computer.
Any graphical user interface (GUI) is simply a graphical representation of command-line programs. For example,
when you close a window by clicking the "X," command is executed behind the scenes.
Moving from Windows to Linux is like entering a completely new world. When you cross the line, you have to learn
about new kinds of software, management tools, and security rules. Even the lingo is quite different from what a
Windows user is used to. The terminology factor only adds to what is already a fairly complex subject. By breaking
down this mini-glossary of basic terms, we hope to make some Linux terms easier to understand.
 The crontab command in Linux: Crontab is a command that allows editing of the cron table on Unix-like operating
systems. The list of jobs that are set up on the system to run at regular intervals is contained in the cron table.
Cron is the name of the daemon that reads the crontab and runs the commands at the appropriate times. It has the
name of the Greek deity of time, Kronos.
To edit your crontab you can run the following command:
crontab -e
To display ("list") the contents of your crontab run the next command:
crontab -l
 The grep command in Linux: A quick and straightforward approach to searching or filtering Linux files for
particular strings is to use the grep tool. This Linux program follows a standard syntax and accepts a wide range of
search criteria. Global regular expression printing is referred to as "grep". There is no need to install the program
because it is part of the Ubuntu essential package. To find strings and patterns, use the grep command. Thus, it
enables you to, for instance, filter out the data you're looking for from huge protocol files. However, keep in mind
that using grep on device files is never a good idea because it can cause issues. When used correctly, the Linux grep
command can assist you in searching through large files. There are numerous parameters you can use to narrow
down your search so that it only returns the characters or lines you require. These parameters are denoted by a
dash -. Here are some of the most useful grep examples:
 -c: Rather than returning each line, -c or -count will tell you how many lines the search term appears in. For
example, the grep command 'grep -c 'test' example.txt' will tell you how many lines contain the word 'test.'
 -l: Use the '-l' option to find out which files a specific search term was found in (lowercase L). The grep command
'grep -l 'test' *.text' will return all files containing the word 'test.'
 -i: This option makes your search case insensitive. 'grep -i' test 'example.txt' will return every line containing the
words' or 'Test'.
 The chmod command in Linux: One of the most important Linux security commands is chmod, which sets read,
write, and execute permissions. Every object on your Linux system has a permission mode that specifies what
actions a user can take with it. Permissions are classified into three types: read (r), write (w), and execute (x).
Reading a file means viewing its contents. For example, for someone to read the text contained within a text file,
read permission must be granted. If the user wishes to add a sentence to that file, he or she must have written
permission. Someone with execute permission can run a file, such as a shell script or a binary program file. The
permissions associated with a file are displayed by the ls -l command.
ls -l
-rw-rw-r-- 1 bruce bruce 0 Jul 10 16:25 schedule10.txt
Some permissions (rw) are repeated because they apply to distinct users, groups, and other entities. The user is the
same as the owner, and the group is the user's main group, and both are bruised. "Other" includes all additional
users.
The object's kind is indicated by its first position: - for files, d for directories, and l for symbolic links. The
authorization mode is described by the following nine slots, which are arranged in threes. The groups are arranged
by user, group, and other, while the positions are arranged by r, w, and x.
rwx rwx rwx
uuu ggg ooo
u=user, g=group, o=other
The ssh key command in Linux: In essence, Secure Shell (SSH) keys are an authentication method employed by the
SSH protocol. The largest Infrastructure-as-a-Service (IaaS) systems available today, like Google Cloud and AWS,
depend on them. SSH keys come in a variety of sizes, but RSA 2048-bit encryption, equivalent to a 617-character
long password, is a common option. You can create your own SSH key pair on Windows PCs by downloading and
running an SSH client like PuTTY.
For Linux:
1. Update or install OpenSSH as recommended.
sudo apt-get update
 Install openssh-server:
sudo apt-get openssh-server
Open a command-line terminal and type the following command to begin:
ssh-keygen -t rsa
Your key files will then be created as usual in the /HOME/.ssh/directory (including the private key). However, if you
want to generate them somewhere else, you can select another place.
Important: Don't ever divulge your private key to anyone.
$HOME/.ssh/id rsa1.pub (public key)
$HOME/.ssh/id rsa1 (private net)
You'll have the choice to generate a passphrase to aid in preventing unauthorized people from accessing your
accounts and preserve the privacy of your keypairs. You'll upload your public key to your server so that SSH key
authentication can be used for access control. To automate the transfer process, use the ssh-copy-id command
from the OpenSSH package with the syntax shown below:
ssh-copy-id username@host
 The public SSH key can also be manually placed on the distant server and added to your account.
 The ifconfig command in Linux: A tool for managing networks is called ifconfig (interface configuration). In Linux
operating systems, it is used to configure and view the status of the network interfaces. You can adjust the ARP
cache, routes, enable or disable interfaces, assign IP addresses, and more with ifconfig.
Use the -s option to display a short list instead of all the details.
$ ifconfig -s
 The bash command in Linux: Bash is an interpreter for the sh command language that can run scripts that are
read from files or the standard input. Additionally, bash integrates helpful elements from the Korn and C shells (ksh
and csh). Bash is meant to be a conformant implementation of the IEEE POSIX specification's Shell and Utilities
section (IEEE Standard 1003.1). Bash can be set up to be by default POSIX-compliant. You can invoke bash with any
of the single-character shell parameters listed in the explanation of the set built-in command. There are also the
following choices:
 -c : The -c option causes commands to be read from a string if it is available. If there are arguments after the string,
they are assigned to the positional parameters, starting with $0.
 -i: The shell is interactive if the -i option is specified. See invocation, below, for further details on interactive shells.
 -r: The shell is made limited if the -r option is used; for more information, see the "Restricted Shell" section below.
 -s: Commands are read from standard input if the -s option is available or if no arguments are left after option
processing. When launching an interactive shell, this option enables the positional parameters to be set.
 -D: On the standard output, a list of all double-quoted strings with a $ prefix is displayed. When the current locale
is not C or POSIX, these strings may be translated into another language. The -n option is implied by this; no
commands are run.
 The apt command in Linux: On Ubuntu, Debian, and related Linux distributions, apt is a command-line tool for
installing, updating, removing, and managing deb packages in general. It combines the most popular apt-get and
apt-cache tool commands with various default settings for several options. Apt is made to be used interactively.
Use apt-get and apt-cache instead of other packages in your shell scripts because they are backward compatible
and offer additional functionality. Let's look at how to install new packages or security updates on an Ubuntu or
Debian Linux server using the apt command. Enter the following to download package data from all preset sources:
sudo apt update
How is Linux different from other OSs?
It's crucial to comprehend how Linux differs from other operating systems, including Windows 95/98, Windows NT,
OS/2, and other personal computer implementations of Unix. First and foremost, it should be made clear that Linux
can coexist peacefully with different operating systems on the same platform. For example, Linux may run side by
side with Windows NT and OS/2 without encountering any issues. You'll find that there are even techniques to
communicate between different operating systems.
Linux is a great option for home Unix computing. Why use Windows at home if you produce Unix software? You
may create and test Unix software on your PC with Linux, including databases and X programs. There's a good
probability that Unix is used by your university's computing system if you're a student. You can manage and
configure your own Unix system using Linux. If you don't have access to other Unix workstations, installing and
running Linux is a great way to learn Unix.
But let's keep our bearings. Linux isn't simply for home users of Unix. It is flexible and strong enough to handle
demanding distributed computing requirements as well as large tasks. Many companies are switching from other
Unix-based workstation systems to Linux. One of the most reliable and powerful operating systems currently
available, Linux offers a fantastic price-performance ratio and is totally adaptable to your needs thanks to its open-
source nature. Linux is proving to be the ideal platform for teaching operating systems design courses in
universities.
Finally, the fact that the Linux kernel and other key components are free and open-source software is the main
distinction between Linux and many other widely used modern operating systems.
What is the difference between Linux and Windows OS?
Linux is a free and open-source operating system that complies with industry standards. It offers a wide range of
applications. Linux operating system includes a number of independently developed components, resulting in a
system that is entirely interoperable and free of proprietary code.
Windows is a commercial operating system that is intended for corporate and alternative industrial users as well as
individuals without any programming knowledge. It is quite basic and easy to use.
The key difference between the Linux and Windows packages is that the former is entirely free, while the latter is a
commercial product and is pricey. Linux is an open-source operating system where users can view and modify the
system's code. On the other hand, even if Windows is an authorized operating system, users cannot access system
files. Let's see how Linux and Windows vary from one another:
Linux Windows
open-source not open-source
Cost-free Expensive
Case-sensitive regardless of the case
monolithic kernel microkernel
Better Efficiency Less effective
forward slash is used to separate folders the backslash is used to separate directories
offers greater security offers less security
frequently utilized in purpose-based system
does not offer very good hacking efficiency
hacking
4 different types of user accounts: - Administrator - Standard -
3 sorts of user accounts: - Regular - Root - Service
Child - Visitors
the root user is the super user and has full All administrative rights on Windows PCs are available to the
administrative rights administrator user
What is the Difference Between Linux and FreeBSD?
Like Linux, FreeBSD is a Berkeley Software Distribution, or BSD, an operating system that is based on the Unix
operating system. It is free, open-source, and secure. One of the most widely used BSD operating system
distributions is FreeBSD. Despite having numerous similarities with Linux variants, FreeBSD differs significantly from
them in a number of crucial areas. In contrast to FreeBSD, Linux is a far more widely used operating system. The
original Bell Unix, which was created by the University of California, Berkeley, was later upgraded and altered in
several ways, evolving into the modern BSD. One of the full-featured open-source BSD operating systems is
FreeBSD.
Below are the top differences between Linux and FreeBSD.
 Linux is more like a kernel, but FreeBSD is a complete operating system.
 Linux is licensed under the GNU General Public License, but FreeBSD is licensed under its own license, which is the
BSD license.
 Linux has excellent support for SMP but FreeBSD has good support for SMP.
 Package management in Linux depends heavily on its distribution. Debian has excellent package management
capabilities, but package management in FreeBSD is excellent, especially in ports and binary areas.
 Linux supports all types of Oracle or ERP applications, but FreeBSD does not support any of these Oracle or ERP
applications.
 Linux shows good performance but FreeBSD has excellent performance.
 Linux has good security, but FreeBSD has better security than Linux.
 Linux has good reliability but is fast as FreeBSD has to use only a few rules.
 Linux has excellent support for all Dell, HP, and IBM servers, but FreeBSD does not have support for any of these
servers.
What is the Difference Between Linux and macOS?
Linux is an open-source operating system that can be used on any device. In contrast, Mac is an operating system
that can only be used on Mac devices. Linux serves as a server, an operating system, and a platform for other
system applications. Mac OS is an operating system that does not permit the use of other system programs.
Despite sharing many characteristics with different Linux distributions, MacOS is very different from them in a
number of critical respects.
The differences between Linux and macOS are listed in the following table:
Linux macOS
Linus Torvalds is the creator of Linux Apple Incorporation created macOS
In 1991, Linux was introduced.Embedded systems, mobile devices,
macOS was launched in 2001. Workstations,
personal computers, servers, mainframe computers, and
laptops, and embedded systems are the system
supercomputers are among the system types Linux is intended to
types that macOS is intended to run on.
run on.
The computer architectures that macOS
Linux supports the IA-32, x86-64, ARM, PowerPC, and SPARC supports include Ax86-64 (10.4.7 and higher),
computer architectures. IA-32 (10.4.4 through 10.6.6), and PowerPC
(10.0-10.5.8).
"Hybrid with modules" is the kernel type used
Linux uses a monolithic kernel.
by macOS.
The native APIs for macOS are BSD-POSIX, Java,
LINUX/POSIX is the native APIs for Linux.
Cocoa, and Carbon.
The preferred licenses for macOS are GNU GPL,
The GNU GPLv2 is the Linux kernel's recommended license.
APSL, and proprietary.
The macOS installer handles package
Linux distribution-specific package management is dependent.
management for macOS.
Linux's subsystems support the non-native APIs Mono, Java, Win16, The subsystems of macOS support Toolbox,
and Win32. Win16, and Win32 as non-native APIs.
Software Update is used to manage updates for
Linux distribution-specific factors affect how updates are managed.
the Mac OS.
HFS+, APFS, HFS, UFS, AFP, ISO 9660, FAT, UDF,
The ext2, ext3, ext4, btrfs, ReiserFS, FAT, ISO 9660, UDF, and NFS
NFS, SMBFS, NTFS, FTP, WebDAV, and ZFS are
file systems are supported by Linux.
among the file systems supported by macOS.
Table 2. Linux vs macOS
Is Linux More Secure than Windows?
Yes. In terms of security, while Linux is open source, it is extremely difficult to breach, making it a highly secure
operating system when compared to other operating systems. One of the main reasons for Linux's popularity and
widespread use is its high-tech security.
Meanwhile, Linux is open source and has a large user community. Because the entire user base has access to the
source code, they can monitor for issues, and any vulnerabilities are likely to be discovered before hackers target
them.
Furthermore, because Linux is open source, users will investigate and resolve the issue immediately. As a result,
Linux receives a high level of support from its developer community.
Windows users, on the other hand, are unable to resolve the issue because they lack access to the source code. If
they discover a vulnerability in the system, they must notify Microsoft and wait for it to be fixed.
Users on Windows have full administrative access to their accounts. As a result, when a virus enters the system, it
quickly corrupts the entire system. So, in the case of Windows, everything is at risk.
On the other hand, Linux has the advantage of accounts that give users limited access, so that if a virus attacks, only
a portion of the system is damaged. Because Linux does not run as root by default, the virus will not be able to
infect the entire system.
There is UAC (user account control) mechanism in Windows to control access privileges, though it is not as robust
as Linux.
To improve system security, Linux employs IP tables. Iptables aid in network traffic control by configuring specific
rules that are enforced via the Linux kernel firewall. This contributes to a more secure environment for running
commands or gaining network access.
Linux has segmented working environments that protect it from virus attacks. However, because the Windows OS is
not well segmented, it is more vulnerable to threats.
Linux has fewer users. Linux accounts for nearly 3% of the market, while Windows accounts for more than 80%. As
a result, hackers are always more interested in targeting Windows because the virus or malicious software they
create affects a large number of users. As a result, Linux users are safer.
To summarize, Linux has some security features that make it more secure than Windows and other operating
systems.
Does Linux have a Firewall built in?
Yes. Because the Linux kernel includes a built-in firewall, and technically all Linux distributions include one that is
not configured or activated. This is due to the fact that using a firewall necessitates some knowledge.
Even without an active firewall, Linux remains secure. Most distributions, including Ubuntu and Linux Mint, have no
open ports by default, ensuring that intruders cannot access your computer.
Nonetheless, you must enable a firewall. A firewall consumes few resources but adds an extra layer of security. An
inexperienced user may unknowingly open some ports by installing samba, ssh, or apache, for example.The firewall
will still protect the system from unauthorized access in this case.
In Linux, you can configure and run a firewall using a variety of programs listed below:
 UFW is the most user-friendly firewall available for Linux. Use UFW if you are a complete newbie or simply want to
use your Linux without delving too deeply into its settings.
 iptables which is a more advanced but likely correct way to configure the Linux firewall. If you truly want to learn
Linux and become a Linux expert, you must first learn iptables.
Using Zenarmor on Linux Distributions
Whether you have a small home network or a multi-device business environment, Zenarmor can be installed and
secured in a matter of seconds.
Zenarmor adds next-generation firewalling features like Application Filtering & Control, TLS Inspection, Advanced
Network Analytics, and many more to your BSD/Linux-based packet-filtering firewall.
Zenarmor can be deployed as a gateway or per-server in any cloud environment.
Before installing Zenarmor, make sure you have the minimum system requirements to run Zenarmor and have the
best user experience.
You can try Zenarmor Free Edition forever by installing it on Linux or other platforms. These Linux platforms are
supported:
 Ubuntu Linux
 RedHat EL
 CentOS Linux
 Debian
 Alma Linux
 Amazon Linux
warning
To use all of Zenarmor's filtering features, you must have either the netmap framework or the nfqueue framework
installed on your system. Netmap is not installed by default in Ubuntu, CentOS, or Debian. On Linux distributions,
you can use the default NFQ framework or install netmap manually.
To install Zenarmor on supported Linux distributions, simply run the one-liner below, which will install the package
repository as well as the main package
5W1H of Open Source Software. Examples , Top Projects, Advantages and more about Open Source
Update Date: 01.09.2023
A sort of licensing arrangement known as "open source" permits users to freely change works, use them in new
ways, incorporate them into bigger projects, or create new works based on the original. Open source encourages
the free exchange of ideas within a community to foster growth in the arts, sciences, and technology by reducing
barriers between innovators. Open-source software encourages creativity and original thinking. The foundation of
open-source is teamwork. Code that is open source is freely accessible to the public. Everyone has access to
opportunities. To contribute to open-source, you don't need a degree, a certificate, or a GPA of 4. Each of these
explains the significance of open source.
Many people have asserted that the open-source movement began with the advent of the Internet in 1969.
However, some people do not distinguish between free software and open-source movements. In actuality, MIT
programmer Richard Stallman started an unofficial campaign in 1983 that had the aim of making source code freely
available. Stallman thought that software should be available to programmers so they could alter it as they pleased
to comprehend, discover, and enhance it. Stallman started disseminating open-source software under his own GNU
Public License. The Open Source Initiative was established in 1998 as a result of the new methodology and mindset
that had become prevalent in the software development industry. Eric Raymond and Bruce Perens founded the
Open Source Initiative (OSI) in February 1998.
In 2001, even major corporations like Microsoft started creating official open-source websites. Just a handful of the
businesses having large public stakes in today's fiercely competitive open-source industry are IBM, Oracle, Google,
and State Farm.
The use of open source software is common. Many free and paid products employ open-source software, which is
developed and maintained by a community of volunteer programmers. The Apache HTTP Server, the e-commerce
platform osCommerce, the web browsers Mozilla Firefox and Chromium (the project where the great bulk of
development of the freeware Google Chrome is done), and the entire office suite LibreOffice are notable examples
of open-source goods. The open-source GNU/Linux operating system and its derivatives, an operating system for
mobile devices, are two of the most popular open-source products. Open-source software is standard practice in
various sectors.
Throughout this article, we will go over what open source software is and the well-known examples, how open
source software works, why we use open source software, who owns open source software, the advantages of
using open source software, and the challenges with open source software. Additionally, we will discuss the
distinction between free and open source software and why open source is preferable to proprietary or closed-
source programs. We'll finish by responding to the following queries:
 Is Java Open Source?
 Is Android Open Source?
 Is open-source software safe?
 What is an open-source software license?
 What are the Open Source Software License Types?
What is Open Source Software and What are the Well-Known Examples?
Open-source software (OSS) is computer software containing source code that is distributed under a license that
provides users the right to use, study, modify, and distribute the program and its source code for any purpose. A
broad software license is known as "open source" makes source code available to the entire public with few or no
limitations on its usage and modification. The development of open source software is decentralized and
collaborative, depending on peer review and community contribution. Because it is produced by communities
rather than a single author or organization, open source software is frequently less expensive, more flexible, and
more durable than its proprietary counterparts.
Most computer users never view the source code, which is the portion of the software that computer programmers
modify to determine how a program or application operates. A program can be altered by programmers who have
access to the source code by adding to it, altering it, or fixing any problematic sections. In order to facilitate the
quick evolution of the program, it turns a piece of software into an open source project with few restrictions on its
usage or distribution by any company or user.
Something being "open source" doesn't merely mean it's free. The application must allow the dissemination of the
source code as well as the built version. The desired format in which a programmer would alter the software must
be included in the source code. It must be possible to distribute derivative works and modified versions of the
software under the same conditions as the original software. The distribution of software created from modified
source code must be expressly permitted by the license. There must be no bias against any individual or group of
individuals in the license. Additionally, the license cannot prevent someone from using the program in a certain
industry. It might not prevent the application from being utilized for genetic research or in a commercial setting, for
instance. The rights associated with the program must apply to everyone to whom it is redistributed without the
necessity for those parties to execute an extra license. All parties to whom the program is redistributed should have
the same rights as those that are provided in conjunction with the original software distribution if the program is
extracted from that distribution and utilized or distributed in accordance with the license's terms. Other software
that is delivered with the licensed software cannot be subject to restrictions imposed by the license. For instance,
the license cannot mandate that only open-source software may be used to distribute additional applications on
the same medium.
Last but not least, no licensing clause may be based on a specific interface or technology.
Drupal Association, FreeBSD Foundation, Linux Foundation, OpenSUSE Foundation, Mozilla Foundation, Wikimedia
Foundation, WordPress Foundation, and Debian, are the largest open-source software initiatives in the world.
How Does Open-Source Software Work?
In the software development community, open source has played a significant role. Indeed, a generation of open
source tools has been developed and is currently being utilized by developers to help improve and troubleshoot
open source code throughout the early stages of software development.
Open Source Software(OSS) is frequently shared extensively and stored in a public repository. Anyone with access
to the repository can use the code independently or add to its overall functionality and design.
On GitHub, SourceForge, Launchpad, and other similar websites, you may access repositories and take part in
community projects for a variety of open source projects.
OSS frequently comes with a distribution license. This license outlines the rules for the program's use, analysis,
modification, and most importantly distribution.
When source code is amended, OSS must document both the changes and the techniques employed. Depending on
the licensing terms, the software that results from these modifications may or may not be required to be made
freely available.
Why Do We Use Open-Source Software?
There are several reasons why people or businesses adopt open source. These are the top six benefits of open-
source software:
 Open Collaboration: The emergence of vibrant open source communities means that you can access assistance,
materials, and viewpoints that go beyond a single industry or business.
 No Vendor Lock-in: Open source software is portable and usable at any time for any purpose.
 Flexibility: Because open source code places a strong emphasis on modification, you can utilize it to solve issues
that are exclusive to your company or neighborhood. You aren't forced to use the code in any particular way, and
you may rely on peer review and community support when you put innovative solutions into practice.
 Reliability: The upkeep, maintenance, and operation of proprietary code is the sole responsibility of the individual
author or entity in charge of it. Since open source code is frequently updated by vibrant open source communities,
it outlives the original authors. Open source software is regularly and appropriately tested thanks to open
standards and peer review.
 Transparency: Do you need to know precisely what types of data are being sent or where they are going, or what
changes have been made to the code? Without having to rely on vendor guarantees, open source enables you to
examine and monitor that for yourself.
 Peer Review: Since the source code is publicly available and the open source community is quite active, peer
reviewers regularly check and update open source code. Instead of a closed-off, stagnant code, think of it as a living
code.
Who Owns Open Source Software?
Typically, the developer of an open-source project owns the software but grants other "contributors'' permission to
replicate, modify, and redistribute it. The licenses provided to software providers and consumers are frequently
standardized (see MIT, GNU LGPL, and Apache as examples). Contributors must typically make their modifications
to the software (or updates, alternate versions, or derivative works) available as open-source as well. For example,
the popular open-source search tool Elasticsearch can be modified by contributors, and licenses to use the
modifications made by the contributors are available to the community, but the creator of the original Elasticsearch
software and the contributors all retain copyright to the parts of software that they created.
Both the developer and contributors to open-source software have the option of assigning their copyright to a
single person or legal body, most typically an open-source foundation. This has many advantages. For starters, it
simplifies copyright enforcement because there are fewer parties engaged in each dispute with only one copyright
holder. It can be difficult to determine how to comply with all of the licenses issued if varying licenses govern a
piece of code when several people hold separate copyrights over different elements of the same software.
Assigning copyrights to a single entity also reduces the possibility of contributors changing the license they grant for
their contribution to the program after a subsequent contributor relied on a previous license. This may cause legal
complications for future contributors who were not told of the change.
Organizations such as the Open Source Initiative (OSI) operate as watchdogs, approving these standard forms of
license as suitable for promoting open source projects.
What are the Advantages of Using Open Source Software?
Today, using open source software has become indispensable. This is because using open source software has
many advantages. We can list these advantages as follows.
 Since open-source software is typically simpler to access than proprietary software, usage tends to rise.
 Software that is open source is free. Additionally, fewer marketing and logistics services are required for OSS. The
OSS development methodology has made it possible to create dependable, high-quality software fast and
affordably.
 A built-in community that supports open source constantly edits and enhances the source code. Due to this, open-
source development has the ability to accelerate creativity, the production of innovation, and the creation of social
value. For instance, a French government incentive program encouraged the use of free open-source software,
which led to an annual increase of approximately 600,000 OSS contributions, creating social value by raising the
amount and caliber of open-source software. Additionally, this legislation is thought to have increased the number
of tech companies by up to 18% and the employment of IT professionals by 14%.
 Open source software is claimed to be more dependable since thousands of independent programmers often test
and solve software flaws. Open source is independent of the organization or author who first developed it. The
code will continue to exist and be improved even if the company fails. Additionally, it adheres to open standards
that are available to everyone, eliminating the issue of incompatible formats that may arise with proprietary
software.
 Users may rely on open source because it is stable and the source code is made available to the public because they
know that the code's developers can't just stop working on the project or let it deteriorate.
 For new programmers, open source offers fantastic learning possibilities. Additionally, open source encourages
creativity; programmers can use pre-existing code to enhance the product and even develop original ideas.
 It is innovative because open-source programs are the result of collaboration between many different
programmers, and it is adaptable because modular systems allow programmers to develop bespoke interfaces or
add new capabilities to them. Innovation is sped up by the blending of diverse viewpoints, organizational aims, and
individual objectives. Developers are permitted to freely modify the code to better suit their specific needs by
looking at how it functions and fixing any broken or troublesome parts of the application.
Figure 1. Advantages of Open Source Software
What are the Challenges with Open Source Software?
As with any technology, using OSS can present some difficulties for developers and businesses. The major issue is
that it is freely available for the public to use and alter.
First of all, there are cyber attacks resulting from publicity. Everyone has easy access to the source code in the open
source community. The ability to highlight any loose ends in the code thanks to this open accessibility is one
benefit, but it is also how hackers exploit programs and potentially hurt their users.
The National Vulnerability Data (NVD) platform makes open source vulnerabilities accessible, which is how hackers
discover and exploit code flaws. Since even a small vulnerability could result in a security breach, this vulnerability
is one of the main difficulties associated with implementing an OSS solution.
Risks Every organization strives to increase production speed because of legacy code. Developers frequently reuse
code that has been in use for a long time in order to expedite the development process, trusting it implicitly
because of its widespread use. But given the legacy code's numerous interconnected dependencies, which may
expose the application to security concerns, this is less than ideal.
There might be liability risks with open source software. In contrast to commercial software, which is entirely under
the vendor's control, open source seldom includes warranty, liability, or infringement indemnity protection. This
places the responsibility for maintaining legal compliance on the user of the OSS.
Due to its complicated installation and lack of user-friendly interfaces, open source may be difficult to use and
embrace. Training people, importing data, and installing essential gear might incur unanticipated expenditures with
open source.
Open source might offer compatibility concerns. When trying to program proprietary hardware using OSS, specialist
drivers that are often only available from the hardware vendor are frequently required.
And lastly, there can be a lack of uniform license compliance. A license that comes with open source software
enables users to use, improve, and edit the source code. The legal terms contained in the OSS apply to you if you
are a developer or an organization using the software. However, as some licenses do not adhere to OSI's
regulations, utilizing such software poses a serious security risk.
Software distributed under multiple banners occasionally complies with differing licensing requirements, and not all
items issued under a given banner do so. Users find it challenging to use a variety of goods in their projects due to
the lack of a uniform licensing authority, and the variances in compliance create even more vulnerabilities.
What's the Difference Between Free and Open Source Software?
Richard Stallman, the founder of the free software movement, claims that the primary distinction is that by
selecting one phrase over the other (such as "open source" or "free software"), one communicates one's objectives
to others: "Free software is a social movement; open source is a development technique".
Even yet, there is a lot of common ground between free and open source software. According to the Free Software
Foundation (FSF), the term "open source" encourages a different form of ambiguity by conflating the right to just
access the source code with the freedom to use, change, and redistribute it. However, the term "free software" has
come under fire for its historical unclear meaning and the vagueness with which the word "free" has been used in
the past, which was thought to discourage commercial adoption.
In summary, the difference between free software and open source software is:
 The Free Software Foundation first used it in the 1980s. OSS Philosophy The term "open source" was first used in
the late 1990s to describe a movement against the limitations of free software.
 Software from FS Philosophy plays a significant role in people's lives. OSS Philosophy Software is only software,
after all. It has no definite ethical implications.
 Social freedom is correlated with software freedom.OSS Philosophy Ethics should be connected to humans rather
than to software.
 According to the FS philosophy, freedom is a value that is more significant than any economic benefit. In OSS
Philosophy, the idea of freedom is not unqualified. Freedom ought to be granted, not forced.
 Every piece of free software is free. Every piece of open-source software is not completely free.
 There are a wide variety of open-source software licenses, some of which are very restrictive and produce open-
source software that is not free. Such a problem doesn't exist in free software.
 There are no limitations placed on free software. Occasionally, users are subject to restrictions imposed by open-
source software.
What is the Most Popular Open Source Software?
The first piece of Open-Source software was published in 1997. Despite the industry, almost every software now
has an Open-Source alternative. Since the beginning of the twenty-first century, numerous Open-Source Operating
Systems, databases, video editors, pdf editors, collaboration tools, password managers, and automation have been
produced thanks to technical advancements and inventions.
Open source operating systems should be our first focus. The following are some of the top open-source operating
systems:
1. Linux Kernel: Linus Torvalds created the Linux kernel. It provides the fundamental operations necessary for an
operating system, such as data deletion, memory processing, and hardware interfacing. Because Linux is open-
source software, many programmers have studied the source code and created a wide range of practical plug-ins
and operating systems to suit their needs.
2. FreeBSD: FreeBSD is a prominent server platform and free Unix-like operating system with open source. Depending
on your demands, FreeBSD may be used as a powerful desktop or a development computer. Additionally, it
supports network services such as web, email, files, and other applications. Internet server reliability is one of the
most well-known characteristics of FreeBSD. Netflix and Sony rely on FreeBSD to provide reliable PlayStation
console service.
The most well-known open source databases are included in the list below.
1. MySQL: A popular relational database management system (RDBMS) called MySQL runs as a server and gives
multiple users access to various databases. The daughter of co-founder Michael Widenius, My, inspired the name
MySQL. The majority of MySQL's development staff, which has Swedish roots, currently works for Oracle
Corporation, which bought MySQL in 2008. Over 3,500 open source developers have contributed to MySQL, which
has been translated into more than 65 languages.
2. MariaDB: MariaDB is a relational database management system. MariaDB, a clone of MySQL, is designed to be free
and open-source software under the GNU General Public License. Some of the original MySQL developers that
branched MySQL in 2009 out of fear that MySQL would be acquired by Oracle Corporation built it. It can be used as
a substitute for MySQL and is particularly well-liked by businesses that choose open-source solutions over
proprietary ones. The software's main functions are very comparable to those of MySQL, and the majority of its
improvements enhance performance and usability. It should also be simple for you to move between databases if
necessary because it is compatible with MySQL.
3. PostgreSQL: The open source relational database management system (RDBMS) PostgreSQL places a strong
emphasis on standards compliance, portability, and dependability. It was developed in 1986 at the University of
California, Berkeley, by Michael Stonebraker and colleagues. Support for complex data types and SQL extensions
stands out as a distinguishing feature. It is a well-liked option for companies creating enterprise software because
of its wide feature set. Extensible Stylesheet Language Transformations (XSLT) are used by PostgreSQL to produce
XML.
The top 3 open source video editing programs for 2022 are shown below:
1. ShotCut: One of the best video editing programs that is also open-source is ShotCut. Because it is built on FFmpeg,
it can support a wide variety of file formats. The video rendering and processing speeds are quite slow because
hardware acceleration is not supported. ShotCut is a suitable option for both novices and specialists. ShotCut runs
on Microsoft Windows, Mac OS, and Linux. ShotCut is a straightforward-looking but effective open source video
editing program. ShotCut offers features like a non-linear timeline for video editing, cross-platform compatibility, a
clean, simple user interface, support for a wide range of video file types, and a good library of video and sound
effects.
2. Blender: For those who enjoy making and editing 3D videos, Blender is the best option. Due to its primary benefit,
it is also well-liked by those who create animated films. Additionally, it is an adaptable video editing program,
allowing for customization. However, there aren't many traditional video editing capabilities available in the
program's default configuration. It's best for animators, 3D motion graphic designers, and producers of 3D videos.
Blender is compatible with Linux, Mac OS, and Microsoft Windows. A few of Blender's capabilities include extensive
3D options including sculpting and modeling, thorough technical support, suitability for seasoned users, support for
a variety of file types, 32 slots for inserting video or audio tracks, and video hardware tools.
3. LightWorks: Through an open-source application, LightWorks is synonymous with high-quality video production
and editing. That is why some of the most well-known Hollywood films' videos were edited using LightWorks
software. It provides an intuitive editing interface, and people highly praise its effective technical help. LightWorks
runs on Microsoft Windows, Mac OS, and Linux. LightWorks is open-source video editing software of the highest
caliber, and even the free edition has a ton of fantastic editing features. LightWorks provides a variety of video file
types, enables Multicam video editing, includes royalty-free video and audio samples, and has presets for 2D and
3D text animation.
The most popular sort of file for business is a PDF. It's simple to view and share PDFs now that there are so many
excellent PDF readers available. Additionally, you can send a PDF file as an attachment to an email or through
instant messaging. Here, we'll introduce the top 3 free and open-source PDF editors.
1. Soda PDF: It's best for quickly and efficiently converting to and from PDFs and editing PDFs with PDF tools. To edit a
PDF document, Soda PDF 360 provides desktop and online PDF editing capabilities. It allows you to edit, redact,
search, and add content to already existing texts. Additionally, it allows you to convert from PDF to other file types
and vice versa. You can merge and compress PDF files, as well as generate forms. With Soda PDF's assistance, you
can accomplish a lot with your PDF file.
2. LibreOffice: LibreOffice is best for modifying pre-existing text in PDFs. One of the most incredible free PDF editors is
LibreOffice, which is available for Windows, Linux, and macOS. It is just as dependable as Word because it was
designed by MS Word to open and edit PDF files. Words and photos can be edited, and you can whiteout the text
you wish to redact and then type on top of it. Although it is a sophisticated word processor, it is not very good at
editing PDF files. However, it does allow for rudimentary modification.
3. Inkscape: The best method for editing and adding text to a PDF document. An open-source vector graphics editor
called Inkscape is comparable to programs like Corel Draw, Xara X, Adobe Illustrator, etc. One of the greatest open-
source PDF editors we have found so far is this one.
Teams and organizations are always looking for innovative methods to boost collaboration at work. However,
finding the ideal package of collaboration tools can be a difficult endeavor. There are many excellent commercial
software options, but there are also many excellent open-source alternatives that provide you with enterprise-level
capabilities. The top 3 tools for cooperation are as follows:
1. Kolab: The extensive scheduling, sharing, and resource management facilities of Kolab, a free and open-source
collaboration application, help teams operate effectively. With this safe and highly scalable application, you may
manage tasks, emails, calendar synchronization, sending and receiving notes, tagging, and many other
collaboration-related tasks. It may be set up to operate on many devices as well. The Kolab suite is made up of a
number of parts, including the KDE PIM-Suite Kontact, Roundcube, and Microsoft Outlook with Kolab-Connector
Plugins. Thunderbird, Lightning, and Mozilla are also included.
2. Group-Office: Group-Office is a sophisticated project, calendar, file, and email sharing tool that is open-source and
free. With its flexible features and ease of use, it is a wonderful option for teams looking to collaborate and work
effectively together. The software also offers paid advanced modules to expand its functionality in addition to a
free basic community edition.
3. OpenProject: OpenProject Organizations can work together on projects from the beginning to the end using the
open-source project management tool OpenProject. Its sophisticated features can be used by teams to organize,
discuss, and record numerous tasks. Teams may share schedules, collaboratively develop, and transparently
visualize project plans using its workflow capabilities throughout the project.
Managing and organizing activities to meet important deadlines and boost team productivity is simple with
Openproject. The community version is cost-effective for start-ups and small enterprises because it is free.
Open-source password managers encourage honesty and openness. By just inspecting the source code, businesses
may rapidly verify whether security measures are being put into place correctly. Any security professional may
contribute to correcting defects because open-source software is based on the concept of collaboration, which
enhances the process of patching flaws. The top three open-source password managers for 2022 are shown
below.
1. KeePass: KeePass is a feature-rich, open-source Windows program that also works with Linux and macOS. Data is
encrypted by KeePass using SHA-256 hashing, the same technique used by banks. Additionally, this password
manager provides a number of database migration options. It offers many customization possibilities, a powerful
password generator, and searchable password groups. The user does not need to go through the installation
process because the software is portable. As the database remains in a single file, exporting and importing the data
is also simple.
2. Dashlane: Security experts recommend Dashlane since it has established itself as a trustworthy security service.
Dashlane has never experienced a security breach or been penetrated by a hacker since it was first created. Given
how frequently data leaks occur in organizations of all kinds each year, this security breach allegation is notable.
The system's foundation of U.S.-based patented security architecture and AES 256-bit encryption gives the
corporation its assurance. Customers may feel secure knowing that Dashlane takes all reasonable measures to
safeguard their data, even at the most minute level.
3. 1Password: Ten team members can be secured at once with 1Password's assistance. It gives customers access to a
virtual safe where they may manage their software licenses, login information, and other confidential data that is
protected by a master password using PBKDF2. One of 1Password's main selling points is its comprehensive
privilege management capabilities, which are ideal for businesses that frequently handle sensitive data and depend
on different user roles. Administrators can use the software to manage login sessions, discover disguised access,
provision and de-provision passwords, and safeguard login credentials.
Automation and manual testing, functionality, regression, load, performance, stress, unit testing, online, mobile,
and desktop testing, and so on are all aided by testing tools. The top three most popular open source software
automation tools are given below:
1. Katalon Platform: The Katalon Platform is a one-stop shop for online, API, mobile, and desktop app test
automation. It is effective in enabling cross-functional activities at scale for product development teams. The
Katalon Platform, being a codeless solution, is simple to use and grow, while it includes the required components
for complex demands, such as built-in keywords and project templates.
2. QA Wolf: QA Wolf is an open-source end-to-end automated testing tool that is one of the quickest ways we've
encountered to develop QA tests. It is entirely hosted, so no downloads or installations are required. With its low
learning curve and automatic code generation, your entire team from non-technical team members to senior
developers can participate in test creation.
3. Selenium: Selenium is undoubtedly among the top open-source testing tools on the market right now. Selenium is
a fantastic automated testing solution for web apps since it works with a wide range of programming languages,
testing frameworks, browsers, and OS systems. It enables you to write very efficient test scripts for exploratory
testing, regression testing, and quickly reproducing bugs.
Is Java Open Source?
Yes. Java is open source, with a global community dedicated to directing its continued development and expansion.
Java's use cases may have shifted over time, but its purpose and mantra have remained consistent: write once, run
anywhere. Java, on the other hand, was developed and supported by Sun Microsystems and is now supported by
Oracle.
Because Java traveled a tortuous route to its open source destination in the early stages, developers and other
users have been naturally perplexed about whether Java is open source. However, the open source status of Java
can be stated as follows: Java began its open source journey in 2006, but it was finished with a full reference
implementation in 2011 with the release of Oracle's Java SE 7. Oracle leads the OpenJDK community in open-source
Java development. The Java Community Process(JCP) manages the specification procedures.
Is Android Open Source?
Yes. Android is an open source mobile operating system and a corresponding open source project led by Google.
Android is built on the Linux kernel, and like that sophisticated piece of code, the majority of its components are
open-source, with the exception of a few binary blobs that are included to make things work with specific
hardware. Anyone can do whatever they want with the core Android platform, known as the Android Open Source
Project (AOSP). The Android Open Source Project (AOSP) repository contains the information and source code
required to develop custom variants of the Android operating system, port devices, and accessories to the Android
platform, and ensure devices meet the compatibility requirements that keep the Android ecosystem healthy and
stable for millions of users.
Android's purpose as an open source project is to avoid any central point of failure in which one industry player can
limit or influence the innovations of any other participant. For that purpose, Android is a complete, production-
quality operating system for consumer products, complete with customizable source code that can be ported to
practically any device and publicly available documentation.
Is Open Source Software Safe?
Yes. Open-source software is typically safe. Applications or desktop programs created by a group of volunteers are
secure and cost nothing to use. Collaboratively developed projects benefit from the expertise of numerous
experienced programmers and testers.
Open source projects are frequently thought to have fewer vulnerabilities by many consumers and developers.
There is a claim that fewer defects exist since so many people are reviewing the open source code. When a security
flaw is discovered and recorded, it can be rectified faster than with private software.
However, downloading open-source software from reputable projects is secure. To create high-quality applications,
a global community of designers, developers, and testing engineers offers their skills. Patches for bugs, weaknesses,
and improvements are frequently released faster than for comparable commercial products.
In open-source software, flaws are difficult to conceal. Many people are keeping an eye on well-known, established
projects, so any issues are reported and rapidly fixed. You may get the most secure versions of open-source
software by downloading it from the F-Droid app store, GitHub, or other reliable sites. This is because the danger is
increased by the availability of the source code and the frequent use of additional open-source components. Cyber
attacks are more likely to happen on smaller projects. These programs have fewer developers and slower patch
release cycles.
Big open-source projects' community members conduct code reviews before integrating a contributor's work to
make sure it complies with security standards. The resources to do security testing and appropriate code reviews
are available in a big open source project.
Smaller projects may unintentionally accept harmful contributions or use insecure libraries because they lack such
resources. In huge projects, maintainers frequently aren't as devoted to the community as the case of Event-
Stream serves as an example of how crucial a robust community is to the security of a project.
What is an Open Source Software License?
An explicit license (such as the Apache Contributor License Agreement) or an implicit license may apply when an
author contributes code to an open-source project (such as Apache.org). Some open-source initiatives require joint
assignment of the author's copyright in order to accept code contributions rather than accepting donated code
under a license.
The proliferation of open-source licenses is a drawback of the movement since it is frequently challenging to
comprehend the legal ramifications of the various license variations. The difficulty of managing open-source use
within "closed-source" commercial organizations has significantly increased with the availability of more than
180,000 open-source projects and more than 1,400 unique licenses. Some are self-developed, while others are
based on popular FOSS licenses such as the GNU General Public License(GPL), Apache, or the MIT-style
(Massachusetts Institute of Technology). Due to this, open-source developers are beginning to utilize classification
techniques that aggregate FOSS licenses (typically based on the existence and obligations imposed by the copyleft
provision; the strength of the copyleft provision).
When the US federal appeals court concluded in 2008 that free software licenses absolutely do establish legally
binding limits on the use of copyrighted work and are therefore enforceable under existing copyright law, it was a
significant legal victory for the open source and free software movements. As a result, if end users disregard the
terms of the agreement, their license will expire and they will be guilty of copyright infringement. Despite this
licensing risk, the majority of commercial software suppliers use open-source software in their products while
adhering to the rules of their licenses, for example by utilizing the Apache license.
In conclusion, an open source software license is free, and anyone is free to redistribute the software without any
restrictions. The source code must be made available so that the recipient can improve or alter it. The license may
stipulate that enhanced versions of the program bear a different name or version number than the original
product. The software could be ported to a different operating system.
In recent years, numerous famous and extensively used open source software licensing agreements have adopted
the definition of open source. Most common Open Source Software licenses are listed below:
 The Apache web server license
 The Berkeley Software Distribution license
 The GNU General Public License
 The Massachusetts Institute of Technology License
 The Mozilla Public License
 The GNU Lesser General Public License
 The Eclipse Public License
What are the Open Source Software License Types?
Copyleft licenses and permissive licenses are two types of open source licenses. Although there are more than 200
open source licenses available, they all typically fall into one of two groups. Permissive and copyleft are those. By
2020, 14% of open source software will be based on copyleft licenses and 76% will be permissive.
 Permissive License: With permissive licenses, you can freely reproduce, alter, mix, and redistribute the work.
Permissive licenses will be the foundation of about 76% of open source software by 2020. When redistributing
software with a permissive license, users are typically simply obliged to include "the original copyright notice" and
"a copy of the license text". The Apache, MIT, and BSD licenses are the three most widely used permissive open-
source licenses.
 Copyleft License: You are also granted the same rights under copyleft and permissive licenses. However, you must
make the entire work available under a copyleft license. To put it another way, if you release a software library
under a copyleft license (like the GPL), someone else would not be permitted to use it with a proprietary library.
The complete program must be developed under the GPL license.
What are Linux Distributions ?
Last Updated : 23 Jul, 2025



A Linux distribution, often shortened to “distro,” is a packaged version of Linux that comes with the Linux kernel
plus a collection of software and utilities that make the OS functional and user-friendly.
Some distros are optimized for business environments, offering tools for productivity and enterprise management,
while others focus on multimedia enthusiasts, bundling advanced audio and video editing software. Distributions
for software developers come preloaded with compilers, programming tools, and integrated development
environments (IDEs).
Each distribution packages the necessary tools to perform specialized functions, ensuring users have an optimized
experience without requiring extensive setup. Whether you’re into creative multimedia projects, writing code,
managing servers, or simply browsing the web, there’s a Linux distribution that fits your needs.
Key Components of a Linux Distribution
Every Linux distribution is built from essential components that work together to create a fully functional operating
system. These components ensure the system can manage hardware, run software, and provide a seamless user
experience -
1. Linux Kernel: It is the core of every Linux distribution. It manages hardware resources, provides device drivers,
and handles low-level system functions like memory management and process scheduling. The kernel acts as a
bridge between the hardware and the software, enabling seamless interaction.
2. System Libraries and Utilities: System libraries, such as the GNU C Library (glibc), play a crucial role in providing
standard functions and APIs that applications use to interact with the kernel. These libraries are essential for
running programs and executing system calls effectively.
3. User Interface (UI): Linux distributions offer two primary types of user interfaces -
 Graphical User Interfaces (GUIs): Popular GUIs like GNOME, KDE, and Xfce provide a user-friendly visual
environment for interacting with the system.
 Command-Line Interface (CLI): For more advanced users, the CLI offers direct control of the system through
terminal commands.
4. Software Packages: Distributions come preloaded with various software packages tailored for specific use cases.
These include -
 Productivity tools (e.g., LibreOffice)
 Web browsers (e.g., Firefox, Chromium)
 Media players (e.g., VLC)
 Development tools (e.g., compilers, IDEs)
5. Package Management System: Package managers streamline the installation, update, and removal of software.
Each distribution uses its own package manager, such as -
 APT for Debian-based distros like Ubuntu.
 YUM/DNF for Red Hat-based distros like Fedora and CentOS.
 Pacman for Arch Linux.
6. Configuration and Customization: Linux distributions provide extensive tools to configure and personalize the
system. Users can adjust network settings, user accounts, security policies, and display preferences. This flexibility
allows Linux to be tailored for everything from personal use to enterprise-level deployments.
7. Support and Community: Most Linux distributions have strong support networks, including documentation,
forums, and active communities. These resources allow users to seek help, learn from others, and contribute to the
development and improvement of their chosen distribution.
Examples of Popular Linux Distributions
Here are some of the most popular Linux distributions, each with its own unique characteristics:
1. Ubuntu
 Audience: Beginners and general users
 Why it’s popular: Ubuntu is one of the most widely used Linux distributions, especially for beginners. It’s user-
friendly and has a large community, which means help is easy to find. It’s also supported by most software vendors.
 Features: Easy installation, long-term support (LTS) versions, and a large software repository.
2. Debian
 Audience: Advanced users and developers
 Why it’s popular: Debian is known for its stability and is often used as the base for other distros, like Ubuntu. It’s a
great choice for those who want a solid, secure system and don’t need the latest bleeding-edge features.
 Features: Reliable, secure, and versatile.
3. Fedora
 Audience: Developers and enthusiasts
 Why it’s popular: Fedora is known for always having the latest software and technologies. It’s backed by Red Hat, a
major player in the enterprise Linux world, and is often used by developers who want to work with cutting-edge
technologies.
 Features: Newest software, excellent for development, supported by Red Hat.
4. Arch Linux
 Audience: Advanced users and tinkerers
 Why it’s popular: Arch Linux is for those who want to fully customize their system. It’s a rolling release distro,
meaning it’s constantly updated, and it gives users complete control over what gets installed on their system.
 Features: Minimalist, highly customizable, rolling releases.
5. CentOS
 Audience: Servers and enterprises
 Why it’s popular: CentOS is based on Red Hat Enterprise Linux (RHEL) and is commonly used for server
environments. It’s free and offers long-term stability, which is perfect for businesses and data centers.
 Features: Enterprise-grade stability, long-term support.
6. Mint
 Audience: Beginners and those transitioning from Windows
 Why it’s popular: Linux Mint is an easy-to-use distribution that looks and feels similar to Windows. It’s a good
choice for users who are new to Linux and want something familiar.
 Features: Simple, user-friendly, and ready-to-use out of the box.
Why Use Linux Distributions?
Linux distributions are widely used because they provide a flexible, secure, and cost-effective operating system.
Here are the key reasons why Linux distributions are preferred:
1. Cost-Free and Open Source
 Most Linux distributions are free to use and don’t require licensing fees.
 They are open-source, allowing users to view, modify, and distribute the code.
2. Customizable
 Linux allows users to modify the operating system’s appearance and functionality according to their needs.
 Users can choose from a variety of desktop environments, file systems, and tools.
3. Security
 Linux is highly secure and less vulnerable to viruses and malware compared to many other operating systems.
 Regular updates and strong user permissions enhance system security.
4. Resource-Efficient
 Linux can run efficiently on older or low-spec hardware, extending the usability of older machines.
 Lightweight distributions like Lubuntu and Puppy Linux are designed for systems with limited resources.
5. Development and Programming
 Linux distributions are ideal for software development due to their compatibility with programming languages and
tools.
 Many distributions include pre-installed compilers, editors, and debugging tools.
6. Diverse Options
 Linux offers a variety of distributions tailored to different use cases, such as personal use, servers, gaming, or
education.
 Examples: Ubuntu (general use), CentOS (servers), Kali Linux (security).
7. Stability and Reliability
 Linux distributions are known for their stability, especially in server environments.
 They are widely used in mission-critical systems due to their consistent performance.
8. Active Community Support
 A large global community provides extensive support through forums, wikis, and online resources.
 This makes troubleshooting and learning easier for users at all levels.
Choosing the Right Linux Distribution
Choosing the right Linux distribution depends on your needs. Here are a few factors to consider:
 Experience Level: If you’re new to Linux, it’s best to start with a beginner-friendly distro like Ubuntu or Linux Mint.
If you're more experienced or need a specialized environment, you might consider Fedora, Debian, or Arch Linux.
 Use Case: For general desktop use, Ubuntu or Mint are excellent choices. If you’re setting up a server, you might
want to go with CentOS or Debian. Developers often prefer Fedora or Arch for its latest software.
 System Resources: Some distros are lighter on resources than others. If you’re working with older hardware,
distros like Lubuntu or Xubuntu are designed to run efficiently on lower-spec machines.
More on Linux Distribution:
 Top 10 Best Linux Distros For Laptops
 Rolling vs. Fixed release Linux Distros?
Conclusion
Linux distributions are designed to address a wide range of computing needs, offering solutions for users at all skill
levels and for various use cases, including personal desktops, servers, development environments, and lightweight
systems. With their open-source nature, robust security, and extensive customization options, Linux distributions
provide a reliable and efficient platform for modern computing. The availability of diverse distributions ensures that
users can select the one best suited to their technical requirements and objectives.

Unit10:An IntroductiontoLinuxOS
Linux is a true 32/64-bit operating system that run on different platforms. It is a multi-user, multi-tasking and
time sharing operating system. Linux is a very stable OS and is used in many application areas, such as by
Internet Service Providers (ISPs) and as a network OS for providing various services. The Linux OS derived its
name from its creator, Linux Torvalds. Linux started writing the Linux kernel in 1991, as a hobby, and created
one of the most powerful operating systems available today. Perhaps the most important factor for the
immense success of Linux is that it is free. It can be copied and redistributed without having to pay any fee or
royalty.

Lesson1:OverviewofLinuxOperatingSystem
LearningObjectives
On completion ofthis lesson youwill beable toknow:
 TheHistoryofLinuxOperatingSystem
 FeaturesofLinuxOperating System
 PrivilegeofLinuxOperatingSystem

A Briefhistoryof Linux

All modern operating systems have their roots in 1969 when Dennis Ritchie and Ken Thompson developed the
C language and the UNIX operating system atAT&T BellLabs.Theysharedtheirsourcecodewith the rest of the
world, including the hippies in Berkeley California. By 1975, when AT&T started selling UNIX commercially,
HistoryofLinux
about half of the source code was written by others. The hippies were not happy that a commercial company
sold software that they had written;theresulting(legal)battleendedintherebeingtwo versions of UNIX in the
Seventies: the official AT&T UNIX, and the free BSD UNIX.
IntheEightiesmanycompaniesstarteddevelopingtheirownUNIX:IBM created AIX, Sun SunOS (later Solaris), HP
HP-UX and about a dozen other companies did the same. The result was a mess of UNIX dialects and a dozen
different ways to do the same thing. And here is the first real root of Linux, when Richard Stallman aimed to
end this era of UNIX separation and everybody re- inventingthewheelbystarting the GNU project (GNU is Not
Unix). His goal was to make an operating system that was freely available to everyone, and where everyone
could work together (like in the Seventies). Many of the command line tools that you use today on Linux or
Solaris are GNU tools.

The Nineties started with Linus Torvalds, a Swedish speaking Finnish student, buying a 386 computer and
writing a brand new POSIX compliant kernel. He put
thesourcecodeonline,thinkingitwouldneversupportanythingbut386
AnIntroductiontoLinuxOS

hardware.ManypeopleembracedthecombinationofthiskernelwiththeGNU tools, and the rest, as they say, is history.

Featuresof Linux OperatingSystem

Hierarchical FileSystem
Linuxprovidesastandardfilestructureinwhichsystemfiles/userfilesare arranged.

Multiprogramming
Linux is a multiprogramming system means multiple applications can run at same time.

Time-Sharing
Multi-programmingismadepossibleon theLinuxsystembytime-sharingfeature.

Multi-Tasking
A program in Linux is broken down into tasks, each task is something like reading from or writing to the disk, or
waiting for input from a user. The ability of any as to handle the execution of multiple tasks is known as multi-
tasking.

Multi-User
Linux is a multiuser system means multiple users can access system resources like memory, ram, and application
programs at same time.

OpenSource
Linux source code is freely available and it is community based development project. Multiple teams’ works in
collaboration to enhance the capability of Linux operating system and it is continuously evolving.

Licensing
Linux is copyrighted under the GNU General Public License. The licensing for Red Hat Linux states that a person
can make any number of copies of the software and distribute it freely or charge a price for it. One can freely
download Linux from the Internet for use.

TheAdvantageofLinuxOperating System

Cost
The most important advantage of using Linuxis the fact that it is free to obtain. Linuxdistribution can be
installed on any number of computers, without paying a single penny.

Reliability
UsersontheLinuxoperatingsystemworkconsistentlywiththeLinuxserver, without reporting any operating system
failures.

200
AnIntroductiontoLinuxOS

BackwardCompatibility
Linuxis perfect for those old computers with barely any processing power or
memory.Thereareendlesspossibilitiestofindold 386or486computerswith barely any RAM run Linux without any
issue.

SimpleUpgrade andInstallationProcess
The installation procedure of most Linux versions is menu-driven. It includes the ability to upgrade from prior
versions. The upgrade process preserves the existing configuration files and maintains a list of its actions during
installation.

GUI Interface
The graphical interface forLinuxistheXWindowsystem.Itisdividedintotwosub systems consisting of a server and
a client. Linux has a number of graphical user interfaces called Desktop Environments, such as K Desktop
Environment (KDE)and GNU Object Model Environment (GNOME), both of which are versions of theX Window
system. They run on the X server.

ExcellentSecurityFeatures
Security- Linux provides user security using authentication features like password protection/ controlled access
to specific files/ encryption of data. This is the reason why many Internet Service Providers (ISPs) are replacing
their current OS with Linux systems.

201
AnIntroductiontoLinuxOS

Exercises

Multiplechoice questions
a. TheUNIXoperatingsystemwasfirstdevelopedat
(i) Berkeley
(ii) AT&TBelllaboratories
(iii) Sun Microsystems
(iv) Microsoftcorporation

b. Who has invented Linux?


(i) RichardMathewStallman
(ii) Prof.AndyTanenbaum
(iii) LinusTorvalds
(iv) JonMaddogHall

Questionsforshortanswers
a) WhoisLinus Torvalds?Mentionhiscontribution in the historyof Linux.
b) WhenUNIXwas invented andwho were the inventors?
c) Whatdoyoumean bySamba?
d) WhatistheUtilityofCRONScheduler?
e) WhydoesISP (InternetServiceProvider)preferLinuxtootherOS?

Analyticalquestions
a) NarratehistoryofUNIX.
b) DiscusssomefeaturesofLinuxOS.
c) MentiontheadvantagesofLinuxOS.

202
AnIntroductiontoLinuxOS

Lesson2:StructureandComparisonofLinux
LearningObjectives
On completion ofthis lesson youwill beable toknow:
 AboutLinux Architecture
 DifferencebetweenLinuxand UNIX
 DifferencebetweenLinuxand Windows
 AboutdistributionofLinux

LinuxArchitecture

The Linux operating system consists of three main software components as shown below:

LinuxArchitecture

ComponentsoftheLinuxOS

Kernel
Thekernel is a program that constitutes the central core of a computer operating system. It has
complete control over everything that occurs in the system. Since the kernel communicates directly
with the hardware, the parts of the kernel must be customized to the hardware features of each
system. However, the kernel does not deal directly with a user. Instead, the login process starts up a
separate, interactive program, called the shell, for each user.

Shell
A shell isaprogramthatprovidesthetraditional,text-onlyuser interface forLinuxand other Unix-
likeoperating systems. Its primary function is to readcommandsthataretypedintoa console(i.e.,anall-
textdisplaymode)orterminal window (an all-text window) in a GUI (graphical user interface) and then
execute (i.e., run) them. The features of the shell will be discussed in lesson 2 unit 4.

203
AnIntroductiontoLinuxOS

Linux UtilitiesandApplication Programs


The Linux utilities or commands are a collection of programs that service day-to- day processing requirements.
These programs are invoked through the shell, which is itself another utility. Apart from the utilities provided as
part of the Linux operating system, more than a thousand Linux-based application programs, like database
management systems, word processors, and various other programs are available from independent software
vendors.

Linuxas compared to UNIX

Linux was developed considering UNIX as a reference model.Thisiswhy;thebasic architecture and most of the
features of Linux and UNIX are the same. Actually, Linux is also considered another version of UNIX. The main
difference between Linux and UNIX is that Linux is FREE. Various distributors of Linux charges aprice, which is
quite low as compared to other operating systems.

The Linux operating system requires at least 850 MB hard disk space, 64MBMemory for Red hat Linux 9.0.

ComparisonbetweenLinuxandUNIX

Feature Linux Unix


Shell bash,pdksh, tcsh zsh, ash Bourne,korn,C
Available
Variants RedHat,Caldera,Debain, LinuxPPC, AT&T, MULTICS, BSD,
SUSE SCO,HP-Ux,IRIX,Ultrix,
Sun Solaris
Licensing FreelyDistributed Expensivelicensing
Linuxas comparedto Windows

Most of the organizations having small, medium, or large networks require a few basic services such as file and
print services, E-mail access, Internet access, and Intranet services. Most of the tasks that you are wanting to
execute on a Windows machine can also be executed on a Linux machine.
The following table compares some of the common applications used on the Linux and Windows operating
systems.
ComparisonbetweenLinuxand Windows
Service Linux Windows
Web Server Apache InternetInformation Server

EmailServer Sendmail MicrosoftExchange


RelationalDatabase Sybase/MYSQL MicrosoftSQL Server
ProxyServer SquidObject Cache WindowsPro Server
BackupServer BRU Includedwith Windows

204
AnIntroductiontoLinuxOS

ThedistributorofLinux

A Linux distribution is collection softwareof (usually open source) software on


topofaLinuxkernel.Adistribution(orshort,distro)canbundleserver software,system
managementtools,documentationandmanydesktopapplications in a central secure
A Linuxdistribution is collection soft wareof (usually open source) software on top of aLinuxkernel. software repository. A
distro aims to provide a common look and feel, secure and easy software management and often a specific
operational purpose.
Let'stakealookatsomepopulardistributions.

RedHat

Red Hat is a billion dollar commercial Linux Company that puts a lot of effort in developing Linux. They have
hundreds of Linux specialists and are known for their excellent support. They give their products (Red Hat
Enterprise Linux and Fedora) away for free. While Red Hat Enterprise Linux (RHEL) is well tested before
release and supported for up to seven years after release, Fedora is a distro with faster updates but without
support.

Ubuntu
Canonical started sending out free compact discs with Ubuntu Linux in 2004 and
quicklybecamepopularforhomeusers(manyswitchingfromMicrosoftWindows). Canonicalwants Ubuntu to be
aneasy to use graphicalLinux desktop without need to ever see a command line. Of course they also want to
make a profit by selling support for Ubuntu.

Debian
ThereisnocompanybehindDebian.Insteadtherearethousandsofwell organised developers that elect a Debian
Project Leader every two years. Debian is seen asone of themoststableLinuxdistributions.Itisalsothebasisof
everyrelease of Ubuntu. Debian comes in three versions: stable, testing and unstable. Every Debian release is
named after a character in the movie Toy Story.

205
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

UNIT-I
LINUXUTILITIESANDSHELLPROGRAMMING
I. Introduction toLinux:

Linux is a Unix-like computer operating system assembled under the model of free and opensource
software development and distribution. The defining component of Linux is the Linuxkernel, an operating
system kernel first released 5 October 1991 by Linus Torvalds.

Linux was originally developed as a free operating system for Intel x86-based personal computers. It has
since been ported to more computer hardware platforms than any other operatingsystem. It isa
leadingoperatingsystemon serversandother big ironsystemssuchas mainframe computers and
supercomputers more than 90% of today's 500 fastestsupercomputers run some variant of Linux,
including the 10 fastest. Linux also runs on embedded systems (deviceswhere the operating
systemistypically built into the firmware and highly tailored to the system) such as mobile phones, tablet
computers, network routers, televisions and video game consoles; the Android system in wide use on
mobile devices isbuilt on the Linux kernel.
Basic Features
FollowingaresomeoftheimportantfeaturesofLinuxOperatingSystem.
 Portable - Portability means softwares can works on different types of hardwares in
sameway.Linuxkernelandapplicationprogramssupportstheir installationonanykind of hardware platform.
 Open Source - Linux source code is freely available and it is community based development
project.Multipleteamsworksincollaborationto enhancethecapability of Linux operating system and it is
continuously evolving.
 Multi-User-Linuxisamultiusersystemmeansmultipleuserscanaccesssystem resources like memory/
ram/ application programs at same time.
 Multiprogramming - Linux is a multiprogramming system means
multiple applications can run at same time.
 HierarchicalFileSystem -Linuxprovidesastandard filestructureinwhichsystem

1
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

files/userfilesarearranged.
 Shell - Linux provides a special interpreter program which can be used to execute
commandsoftheoperatingsystem.It canbeused todo varioustypesofoperations,call application programs
etc.
 Security -Linuxprovidesuser securityusingauthenticationfeatureslikepassword protection/ controlled
access to specific files/ encryption of data.

LinuxAdvantages
1. Lowcost: Youdon’t needto spendtimeand moneytoobtainlicensessinceLinuxandmuch
ofitssoftwarecomewiththeGNUGeneralPublic License.Youcanstarttoworkimmediately without worrying
that your software may stop working anytime because thefree trial version expires. Additionally, there
are large repositories from which you canfreely download high quality software for almost any task you
can think of.
2. Stability:Linuxdoesn’t needtoberebootedperiodicallyto maintainperformance levels. Itdoesn’t
freeze up or slow downovertime due tomemoryleaks and such. Continuous up- times of hundreds of
days (up to a year or more) are not uncommon.
3. Performance: Linux provides persistent high performance on workstations and
onnetworks.Itcanhandleunusually largenumbersofuserssimultaneously,andcanmake oldcomputers
sufficiently responsive to be useful again.
4. Network friendliness: Linux was developed by a group of programmers over theInternet and
has therefore strong support for network functionality; client and server systems can be easily set up
on any computer running Linux. It can perform tasks such as network backups faster and more reliably
than alternative systems.
5. Flexibility: Linux can be used for high performance server applications, desktop applications,
and embedded systems. You can save disk space byonly installing the componentsneeded
foraparticularuse.Youcanrestrict theuseofspecificcomputersby installing for example only selected
office applications instead of the whole suite.
6. Compatibility:It runsallcommonUnixsoftwarepackagesandcanprocessallcommonfile formats.
7. Choice: The large number of Linux distributions gives you a choice. Each distribution is
developedandsupportedbyadifferentorganization. You canpicktheoneyou likebest;the

2
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

corefunctionalitiesarethesame;mostsoftwarerunsonmostdistributions.
8. Fastandeasyinstallation: MostLinuxdistributionscomewithuser-friendlyinstallation and setup
programs. Popular Linux distributions come with tools that make installation of additional software
very user friendly as well.
9.Fulluseofhard disk:Linuxcontinuesworkwellevenwhenthehard diskisalmostfull.
10. Multitasking: Linuxisdesignedto domanythingsatthesametime;e.g.,alargeprinting job in the
background won’t slow down your other work.
11. Security: Linux is one of the most secure operating systems. “Walls” and flexible file access
permission systems prevent access by unwanted visitors or viruses. Linux users have to option to select
and safely download software, free of charge, from online repositories
containingthousandsofhighqualitypackages.Nopurchasetransactionsrequiringcredit card numbers or
other sensitive personal information are necessary.
12. OpenSource: Ifyou develop softwarethat requiresknowledgeor modificationofthe
operatingsystemcode,Linux’ssourcecodeisat yourfingertips.MostLinuxapplications are Open Source
as well.
DifferencebetweenUNIXandLINUX

Features LINUX UNIX

Cost Linuxcanbefreelydistributed, DifferentflavorsofUnixhave


downloadedfreely,distributed differentcoststructuresaccording
throughmagazines,Booksetc. to vendors
Therearepricedversions for
Linuxalso,but theyare
normallycheaperthan
Windows.

Development LinuxisdevelopedbyOpen Unixsystemsaredividedinto


and Sourcedevelopmenti.e.through variousotherflavors, mostly
Distribution sharingandcollaborationof developedbyAT&T aswellas
codeandfeaturesthrough variouscommercialvendorsand
forumsetcanditisdistributed non-profitorganizations.

3
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

byvarious vendors.

Manufacturer Linuxkernelisdeveloped by Threebigestdistributionsare


thecommunity.LinusTorvalds Solaris(Oracle), AIX(IBM)&HP-
overseesthings. UXHewlettPackard.AndApple
MakesOSX,anunixbasedos..

User Everyone.Fromhomeusersto Unixoperatingsystemswere


developersandcomputer developed mainlyformainframes,
enthusiastsalike. serversandworkstationsexcept
OSX,Whichisdesignedfor
everyone.TheUnixenvironment
andtheclient-server program
modelwereessentialelementsin
thedevelopment oftheInternet

Usage Linuxcan beinstalledonawide TheUNIXoperatingsystemisused


varietyofcomputerhardware, ininternet servers,workstations&
ranging frommobilephones, PCs. Backboneofthemajorityof
tabletcomputersand video finance infastructureandmany
gameconsoles,tomainframes 24x365highavailabilitysolutions.
andsupercomputers.

File system Ext2,Ext3,Ext4,Jfs,ReiserFS, jfs,gpfs,hfs,hfs+,ufs,xfs,zfs


support Xfs,Btrfs,FAT, FAT32,NTFS format

Textmode BASH(BourneAgainSHell)is OriginallytheBourneShell.Now


interface theLinuxdefaultshell. Itcan it'scompatiblewithmanyothers
supportmultiplecommand includingBASH, Korn&C.
interpreters.

Whatis it? Linux isanexampleofOpen Unixisanoperating systemthatis


Sourcesoftwaredevelopment verypopularinuniversities,
andFreeOperating System companies,bigenterprisesetc.
(OS).

10

4
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

GUI Linuxtypicallyprovides two InitiallyUnixwasa command


GUIs,KDEandGnome.But basedOS, butlateraGUI was
thereare millionsofalternatives createdcalledCommonDesktop
suchasLXDE,Xfce,Unity, Environment.Mostdistributions
Mate,twm,ect. nowshipwithGnome.

Price Freebutsupportisavailablefor Somefreefordevelopment use


aprice. (Solaris)butsupport isavailablefor
aprice.

Security Linux hashad about60-100 AroughestimateofUNIXviruses


viruseslistedtilldate. Noneof is between85-120virusesreported
themactivelyspreading tilldate.
nowadays.

Threat Incase ofLinux,threat Becauseoftheproprietarynatureof


detectionand detectionandsolutionis very theoriginalUnix,usershaveto
solution fast, asLinuxismainly waitfor awhile,togetthe proper
communitydrivenand bugfixingpatch. Butthesearenot
whenever anyLinuxuserposts ascommon.
anykindofthreat,several
developersstartworkingonit
fromdifferentpartsoftheworld

Processors Dozensofdifferentkinds. x86/x64,Sparc,Power,Itanium,


PA-RISC,PowerPCandmany
others.

Examples Ubuntu,Fedora,RedHat, OSX,Solaris,AllLinux


Debian,Archlinux,Androidetc.

Architectures Originallydeveloped forIntel's isavailableonPA-RISCand


x86hardware,ports available Itaniummachines.Solaris also
for overtwodozenCPUtypes availableforx86/x64based
including ARM systems.OSXisPowerPC(10.0-

5
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

10.5)/x86(10.4)/x64(10.5-10.8)

Inception InspiredbyMINIX(aUnix-like In1969,itwasdevelopedby a


system)andeventuallyafter groupofAT&TemployeesatBell
addingmanyfeaturesofGUI, LabsandDennisRitchie.Itwas
Driversetc, LinusTorvalds writtenin“C”languageandwas
developedtheframeworkofthe designedtobeaportable,multi-
OSthatbecameLINUXin taskingandmulti-usersystemina
1992.TheLINUXkernelwas time-sharingconfiguration
releasedon17th September,
1991

LinuxDistribution(OperatingSystem)Names
Afewpopularnames:
1.RedhatEnterpriseLinux
2.FedoraLinux
3.DebianLinux
4.SuseEnterpriseLinux
5.Ubuntu Linux
CommonThingsBetween Linux&UNIX
Bothsharemanycommonapplicationssuchas:
1.GUI,file, andwindowsmanagers(KDE, Gnome)
2.Shells(ksh,csh,bash)
3.VariousofficeapplicationssuchasOpenOffice.org

6
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

4.Developmenttools(perl,php, python,GNUc/c++compilers)
5.Posixinterface
LayeredArchitecture:

LinuxSystemArchitectureisconsistsoffollowinglayers
 Hardwarelayer-Hardwareconsistsofallperipheraldevices(RAM/HDD/ CPUetc).
 Kernel-CorecomponentofOperatingSystem,interactsdirectlywithhardware, provides low level services to
upper layer components.
 Shell - An interface to kernel, hiding complexityofkernel's functions fromusers. Takes commands from
user and executes kernel's functions.
 Utilities-Utilityprogramsgivingusermostofthefunctionalitiesofanoperating systems.

LINUXFilesystem
Linux file structure files are grouped according to purpose. Ex: commands, data files,
documentation. Parts of a Unix directory tree are listed below. All directories are grouped under
the root entry"/". That part of the directorytree is left out of the below diagram.

7
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

1. /–Root
Everysinglefile anddirectorystartsfromthe root
 directory.
Onlyrootuserhaswriteprivilegeunderthis
 directory.
Pleasenotethat/rootis root user’shomedirectory,whichisnotsameas
 /.
2. /bin–UserBinaries
Containsbinary
 executables.
Common linux commands you need to use in single-user modes are located under this
 directory.
Commandsusedbyalltheusers ofthe systemarelocated
 here.
Forexample:ps,ls,ping,grep,
 cp.
3. /sbin– SystemBinaries
Justlike/bin,/sbinalsocontainsbinary
 executables.
But,thelinuxcommandslocatedunderthisdirectoryareusedtypicallybysystem aministrator, for system

maintenance purpose.

Forexample:iptables,reboot,fdisk, ifconfig,
 swapon
4. /etc –ConfigurationFiles

8
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes
Containsconfigurationfilesrequiredbyall
 programs.
This also contains startup and shutdown shell scripts used to start/stop individual
 programs.
Forexample:/etc/resolv.conf,
 /etc/logrotate.conf
5. /dev–Device Files
Containsdevice
 files.
Theseincludeterminaldevices,usb, oranydeviceattached tothe
 system.
Forexample:/dev/tty1,
 /dev/usbmon0
6. /proc–ProcessInformation
Containsinformationaboutsystem
 process.
Thisisapseudofilesystemcontainsinformationaboutrunningprocess.For
 example:
/proc/{pid}directorycontains informationabouttheprocesswiththatparticular pid.
Thisisavirtualfilesystemwithtextinformationaboutsystemresources.For
 example:
/proc/uptime
7. /var–VariableFiles
varstandsforvariable
 files.
Contentofthefilesthatareexpected togrow canbefoundunderthis
 directory.
This includes — system log files (/var/log); packages and database files (/var/lib);emails (/var/mail); print

queues (/var/spool); lock files (/var/lock); temp files needed across reboots (/var/tmp);

8. /tmp– TemporaryFiles
Directorythatcontainstemporaryfilescreatedbysystemand
 users.
Files underthis directoryaredeletedwhensystemis
 rebooted.
9. /usr–UserPrograms
Containsbinaries,libraries,documentation,andsource-codeforsecondlevel
 programs.
/usr/bincontainsbinaryfilesforuserprograms.Ifyoucan’tfindauserbinary
 under
/bin,lookunder/usr/bin.Forexample:at,awk,cc,less,scp
/usr/sbin contains binary files for system administrators. If you can’t find a system binaryunder /sbin, look

under /usr/sbin. For example: atd, cron, sshd, useradd, userdel

/usr/libcontains librariesfor/usr/binand
 /usr/sbin
/usr/localcontainsusersprogramsthatyouinstallfromsource.Forexample,when
 you

9
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

installapachefromsource,itgoesunder/usr/local/apache2
10. /home–Home Directories
Homedirectoriesfor alluserstostoretheir personal
 files.
Forexample:/home/john,
 /home/nikita
11. /boot – Boot LoaderFiles
Containsbootloaderrelated
 files.
Kernelinitrd,vmlinux,grubfilesarelocatedunder
 /boot
Forexample:initrd.img-2.6.32-24-generic,vmlinuz-2.6.32-24-
 generic
12. /lib–SystemLibraries
Containslibraryfilesthatsupportsthebinaries locatedunder/binand
 /sbin
Libraryfilenamesareeitherld*or
 lib*.so.*
Forexample:ld-2.11.1.so,
 libncurses.so.5.7
13. /opt–Optionaladd-onApplications
optstandsfor
 optional.
Containsadd-onapplicationsfromindividual
 vendors.
add-onapplicationsshouldbeinstalledundereither/opt/or/opt/sub-
 directory.
14. /mnt–Mount Directory
Temporarymountdirectorywheresysadminscanmount
 filesystems.
15. /media–RemovableMediaDevices
Temporarymount directoryforremovable
 devices.
For
 examples, /media/cdrom for CD-ROM; /media/floppy for floppy drives;
/media/cdrecorderforCD writer
16. /srv– ServiceData
srvstandsfor
 service.
Containsserverspecificservicesrelated
 data.
Forexample,/srv/cvscontainsCVSrelated
 data.

1. LinuxUtilities:

FileHandling utilities:
Cat

10
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Command:
cat linuxcommandconcatenates filesandprintitonthestandard output.

SYNTAX:
TheSyntax is
cat [OPTIONS] [FILE]...

OPTIONS:
-A Showall.
-b Omitsline numbersforblankspaceinthe output.
-eA$characterwillbeprintedattheendofeachlinepriorto anew line. -E Displays a $ (dollar
sign) at the end of each line.
-n Linenumbersforalltheoutputlines.
-sIftheoutputhasmultipleemptylinesit replacesit with oneemptyline. -T Displays the tab
characters in the output.
Non-printingcharacters(withtheexceptionoftabs,new-linesandform-feeds)
-vare printedvisibly.

Example:
ToCreateanewfile: cat >
file1.txt
Thiscommandcreatesanewfilefile1.txt.Aftertypingintothefilepresscontrol+d (^d)
simultaneously to end the file.

1. ToAppenddataintothe file: cat >>


file1.txt
Toappenddataintothesamefileuseappendoperator>> towriteintothefile, else the file will be
overwritten (i.e., all of its contents will be erased).

2. Todisplaya

11
J.B.INSTITUTE OF
ENGINEERINGAND
TECHNOLOGY

LinuxProgrammingNotes
file:cat
file1.txt
Thiscommanddisplaysthedatainthe file.

3. Toconcatenateseveralfilesand display: cat


file1.txt file2.txt

12
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

The above cat command will concatenate the two files (file1.txt and file2.txt) and it will displaythe
output inthe screen. Some timesthe output maynot fit the monitor screen. In such situation you
can print those files in a new file or display the file using less command.

catfile1.txtfile2.txt|less

4. Toconcatenateseveralfilesandtotransfertheoutputtoanother file. cat file1.txt file2.txt


> file3.txt
Intheaboveexampletheoutputisredirectedto newfile file3.txt.Thecat commandwill create new file
file3.txt and store the concatenated output into file3.txt.

rm COMMAND:
rmlinuxcommandisused toremove/deletethefilefromthedirectory.

SYNTAX:
TheSyntax is
rm[options..] [file|directory]

OPTIONS:

-f Removeallfiles inadirectorywithoutpromptingthe user.


Interactive.Withthisoption, rmprompts forconfirmationbefore removing
-i
anyfiles.
Recursivelyremovedirectoriesandsubdirectories intheargumentlist. The
-r(or)-R directory will beemptied of filesandremoved.Theuseris normally
prompted for removalof any write-protectedfileswhichthe directory
contains.
EXAMPLE:

13
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

1. To Remove / Delete afile: rm file1.txt


Herermcommand willremove/deletethefilefile1.txt.

2. Todeleteadirectorytree: rm -ir tmp


This rm command recursively removes the contents of all subdirectories of the tmp directory, prompting
you regarding the removal of each file, and then removes the tmp directory itself.

3. To remove more files atonce rm file1.txt


file2.txt
rmcommandremovesfile1.txtandfile2.txtfilesatthesametime.

cdCOMMAND:
cdcommandisusedtochangethedirectory.

SYNTAX:
TheSyntax is
cd [directory|~|./|../|-]

OPTIONS:

-L Usethephysicaldirectorystructure.
-P Forcessymboliclinks.
EXAMPLE:
1. cdlinux-command
Thiscommandwilltake youtothesub-directory(linux-command) fromitsparent directory.

14
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

2. cd..
Thiswillchangetotheparent-directoryfromthecurrentworkingdirectory/sub-directory.

3. cd~

Thiscommand willmovetotheuser'shomedirectorywhich is"/home/username".

cpCOMMAND:
cpcommandcopyfiles fromone locationto another.Ifthedestinationisanexisting file, then the file is
overwritten; if the destination is an existing directory, the file is copied into the directory (the directory is
not overwritten).

SYNTAX:
TheSyntax is
cp[OPTIONS]...SOURCEDEST
cp[OPTIONS]...SOURCE...DIRECTORY
cp[OPTIONS]...--target-directory=DIRECTORYSOURCE...

OPTIONS:

-a sameas-dpR.
--backup[=CONTROL] makea backup ofeachexisting destinationfile
-b like--backupbutdoesnotacceptanargument.

ifanexistingdestinationfilecannotbeopened,removeitandtry
-f
again.
-p sameas--preserve=mode,ownership,timestamps.

15
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

-- preserve the specified attributes (default:


mode,ownership,timestamps)andsecuritycontexts,ifpossible
preserve[=ATTR_LIST]
additionalattributes:links,all.
--no-
don'tpreservethespecifiedattribute.
preserve=ATTR_LIST
--parents appendsource pathtoDIRECTORY.
EXAMPLE:
Copytwo
files: cp file1file2

Theabovecpcommandcopiesthecontentoffile1.phptofile2.php.

1. Tobackupthecopied file: cp -b
file1.php file2.php
Backupoffile1.phpwillbe createdwith'~'symbolasfile2.php~.

2. Copy folder and subfolders:cp-


Rscripts scripts1
Theabovecp commandcopythe folderand subfoldersfromscriptstoscripts1.
lsCOMMAND:
lscommandliststhefilesanddirectoriesundercurrentworkingdirectory.

SYNTAX:
The
Syntaxis
ls[OPTIONS]... [FILE]

16
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

OPTIONS:
-l Listsallthefiles,directoriesandtheirmode,Numberoflinks,ownerofthe
file,filesize,Modifieddateandtimeandfilename.
-t Lists inorderoflastmodificationtime.

-a Listsallentries includinghiddenfiles.

-d Listsdirectoryfilesinsteadofcontents.

-p Putsslashattheendofeachdirectories.

-u Listinorderoflastaccess time.

-i Displayinodeinformation.

-ltr Listfilesorder bydate.

-lSr List filesorderbyfile size.


EXAMPLE:
Displayrootdirectory contents: ls /

liststhecontentsofrootdirectory.

1. Display hidden files and


directories: ls -a
listsallentriesincludinghiddenfilesand directories.

2. Displayinodeinformation:

ls-i
7373073book.gif
7373074clock.gif
7373082globe.gif
7373078pencil.gif
7373080child.gif

17
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

7373081email.gif
7373076indigo.gif
Theabovecommanddisplaysfilenamewithinodevalue.

lnCOMMAND:
lncommand isusedtocreatelinkto afile(or)directory.It helpstoprovidesoft link for desired files.
Inode will be different for source and destination.

SYNTAX:
The Syntaxis
ln[options]existingfile(ordirectory)namenewfile(ordirectory)name

OPTIONS:

-f Link fileswithoutquestioningtheuser,evenifthemodeoftargetforbids
writing.Thisisthedefaultifthestandardinputisnotaterminal.
-n Doesnotoverwriteexistingfiles.

-s Usedtocreatesoftlinks.
EXAMPLE:
1. ln-sfile1.txt file2.txt
Creates a symboliclink to'file1.txt' with the name of 'file2.txt'.Here inodefor 'file1.txt' and
'file2.txt' will be different.
2. ln-snimi nimi1
Createsasymboliclinkto'nimi'withthenameof'nimi1'.

chownCOMMAND:
chowncommand isusedto changetheowner/userofthe fileordirectory.Thisis an admin
command, root user only can change the owner of a file or directory.

SYNTAX:
TheSyntax is
chown[options]newownerfilename/directoryname

18
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

OPTIONS:

-R Changethepermissiononfilesthatareinthesubdirectoriesofthe directory
thatyouarecurrently in.
-c Changethepermissionforeachfile.
Preventschownfromdisplayingerrormessageswhenitisunableto change
-f
theownership ofafile.
EXAMPLE:

1. chownhioxtest.txt

Theowner ofthe'test.txt'fileisroot,Changetonewuserhiox.

2. chown-Rhioxtest

Theownerofthe'test'directoryisroot,With-Roptionthefilesand subdirectories user also gets changed.

3. chown-c hioxcalc.txt

Herechangetheownerforthespecific'calc.txt'file only.

SecurityBy File
Permissionschmod
Command:
chmodcommandallows youtoalter/Changeaccessrightstofilesanddirectories.

FilePermissionisgivenforusers, groupandothersas,

ReadWrite Execute

19
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

User Grou Others


Permission Symbolic

000

SYNTAX:
TheSyntax is
chmod[options][MODE]FileName

FilePermission

# FilePermission
0 none
1 executeonly
2 writeonly
3 writeandexecute
4 readonly
5 readandexecute
6 readandwrite
7 setallpermissions

OPTIONS:

-cDisplays namesofonlythosefileswhosepermissionsarebeingchanged -f Suppress most error


messages
-R Changefilesanddirectoriesrecursively

20
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

-v Outputversioninformationand exit.
EXAMPLE:

1. Toviewyourfileswithwhatpermissionthey are: ls -alt


Thiscommandisusedtoviewyour fileswithwhatpermissiontheyare.

2. Tomakeafilereadableandwritablebythegroupandothers. chmod 066 file1.txt


3. Toalloweveryonetoread, write,andexecutethefile

chmod777file1.txt
mkdirCOMMAND:
mkdircommandisusedtocreateoneor more directories.

SYNTAX:
TheSyntax is
mkdir[options]directories

OPTIONS:

-m Settheaccessmodefor thenew directories.


-pCreateinterveningparent directoriesiftheydon't exist. -v Print help
message for each directory created.
EXAMPLE:

1.Createdirectory:
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

mkdirtest

Theabovecommandisusedto createthedirectory'test'.

2.Create directory and


setpermissions: mkdir -m
666 test
Theabovecommand isusedtocreatethedirectory'test'andsetthe readand write permission.

rmdirCOMMAND:
rmdircommandisusedtodelete/removeadirectoryand itssubdirectories.

SYNTAX:
TheSyntax is
rmdir[options..]Directory

OPTIONS:

Allowuserstoremovethedirectorydirnameanditsparentdirectorieswhich
-p
becomeempty.
EXAMPLE:

1. Todelete/removeadirectory rmdir tmp


rmdir command willremove/deletethedirectorytmpifthedirectoryis empty.

2. To deleteadirectorytree:

rm-irtmp
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

This command recursively removes the contents of all subdirectories of the tmpdirectory,
prompting you regarding the removal of each file, and then removes the tmp directory itself.

mv COMMAND:
mv command which is short for move. It is used to move/rename file fromone directoryto
another.mvcommand isdifferent fromcpcommandasit completelyremovesthe file fromthe source
and moves to the directoryspecified, where cp command just copies the content from one file to
another.

SYNTAX:
TheSyntaxis
mv[-f][-i]oldnamenewname

OPTIONS:

Thiswillnotpromptbeforeoverwriting(equivalentto--reply=yes). mv-fwill
-f
movethe file(s)withoutpromptingevenifitiswritingoveranexisting
target.-iPromptsbeforeoverwritinganotherfile.
EXAMPLE:

1. ToRename/Movea file: mv file1.txt


file2.txt
Thiscommandrenamesfile1.txtasfile2.txt

2. Tomoveadirectory

mvhscriptstmp
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

In the above line mv command moves all the files, directories and sub-directories from hscripts
folder/directoryto tmp directory if the tmp directoryalready exists. Ifthere is no tmp directory it
rename's the hscripts directory as tmp directory.

3. To Move multiple files/More files into anotherdirectory mv file1.txt


tmp/file2.txt newdir
This command moves the files file1.txt from the current directory and file2.txt from the tmp
folder/directory to newdir.

diffCOMMAND:
diffcommandisusedtofinddifferencesbetweentwofiles.

SYNTAX:
TheSyntaxis
diff[options..] from-fileto-file

OPTIONS:

-a Treatallfilesastextandcomparethemline-by-line.
-bIgnorechangesinamountofwhitespace. -c Use
the context output format.
-e Makeoutputthatisavalidedscript.
Useheuristicstospeed handlingoflargefilesthathavenumerousscattered
-H
smallchanges.
-iIgnorechangesincase;considerupper-and lower-caselettersequivalent.
PrintsinRCS-format,like -fexceptthateachcommandspecifiesthenumber
-n
oflinesaffected.
OutputRCS-formatdiffs;like-fexceptthateachcommandspecifiesthe
-q
numberoflinesaffected.
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

-r Whencomparingdirectories,recursivelycompareanysubdirectories found.
-s Reportwhentwofilesarethesame.
-wIgnorewhitespacewhencomparinglines. -y Use the side
by side output format.
EXAMPLE:

Letscreatetwo filesfile1.txtandfile2.txtandletithavethe followingdata.

Data infile1.txt Data infile2.txt


HIOXTEST
HIOXTEST
hscripts.com
HSCRIPTS.com
withfriendship
hioxindia withfriendship

1. Compare files ignoring


white space: diff -w file1.txt file2.txt
Thiscommandwillcomparethefilefile1.txtwithfile2.txtignoringwhite/blank space and it will produce the
following output.

2c2
<hscripts.com
---
>HSCRIPTS.com
4d3
<Hioxindia.com

2. Comparethefilessidebyside,ignoringwhite space: diff -by file1.txt


file2.txt
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Thiscommandwillcomparethefilesignoringwhite/blankspace,It iseasierto differentiate the files.


HIOXTEST HIOXTEST

hscripts.com | HSCRIPTS.com
with friend ship withfriendship
Hioxindia.com <

Thethirdline(withfriendship)infile2.txt hasmore blankspaces,butstillthe-bignores

theblankspaceanddoesnot showchangesintheparticular line, -yprintoutthe result side by


side.

3. Compare the files ignoring case.


diff -iy file1.txt file2.txt
Thiscommandwillcomparethefilesignoring case(upper-caseandlower-case)and displays the
following output.

HIOXTEST HIOXTEST
hscripts.com HSCRIPTS.com
withfriendship |withfriendship

chgrpCOMMAND:
chgrpcommand isusedtochangethegroupofthefileordirectory.Thisisan admin
command. Root user only can change the group of the file or directory.

SYNTAX:
TheSyntax is
chgrp[options]newgroupfilename/directoryname

OPTIONS:
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

-R Changethepermissiononfilesthatareinthesubdirectoriesofthedirectory
thatyouarecurrently in.
-c Changethepermissionforeachfile.

-f Force.Donotreporterrors.

Hioxindia.com <
EXAMPLE:

1. chgrphioxtest.txt

Thegroupof'test.txt'fileisroot,Change tonewgrouphiox.

2. chgrp-Rhiox test

Thegroupof'test'directoryisroot. With -R,the filesand itssubdirectoriesalso changes to newgroup hiox.

3. chgrp -chioxcalc.txt

Theyabovecommandisusedtochangethegroupforthespecificfile('calc.txt')only.

About wc

Short for wordcount, wcdisplaysacountoflines, words,andcharacters inafile.

Syntax

wc[-c |-m|-C][-l] [-w][ file...]

-c Countbytes.

-m Countcharacters.

-C Sameas -m.
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

-l Countlines.

Countwordsdelimitedbywhitespacecharactersornewlinecharacters.
DelimitingcharactersareExtendedUnixCode(EUC)charactersfromanycode set defined by iswspace()
File Nameoffiletoword count.

Examples

wcmyfile.txt-Displays informationaboutthefilemyfile.txt. Belowisanexampleofthe output.

5 13 57myfile.txt

5=Lines
13=Words
57=Characters
About split
Split afile into pieces.

Syntax

split[-linecount|-llinecount][ -asuffixlength][file[name]] split -b n [k | m]


[ -a suffixlength ] [ file [name]]
-linecount|-lNumberoflinesineachpiece.Defaultsto1000lines.
linecount

-a Usesuffixlength lettersto formthesuffixportion ofthe filenamesofthe split


ngth file. If -a is not specified, the default suffix length is 2. Ifthe sumofthe name
operandandthesuffixlengthoption-argument wouldcreateafilenameexceeding
NAME_MAXbytes,anerrorwillresult;splitwill exitwithadiagnosticmessage
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

andnofileswillbecreated.

-bn Splitafileinto piecesnbytesinsize.

-bnk Splitafile into piecesn*1024 bytesinsize.

-bnm Splitafile into piecesn*1048576 bytesinsize.

Thepathnameoftheordinaryfileto besplit. Ifno input file isgivenorfile is -, the standard input will be used.
The prefixto be used for eachofthe files resulting fromthe split operation. If no nameargument
isgiven,xwillbeusedastheprefixoftheoutputfiles.The
combined lengthofthebasenameofprefixandsuffixlengthcannotexceed NAME_MAX bytes; see OPTIONS.

Examples

split-b22newfile.txtnew-wouldsplit the file "newfile.txt"intothreeseparatefiles called newaa,


newab and newac each file the size of 22.

split-l300file.txtnew-wouldsplit thefile"newfile.txt"intofilesbeginningwiththe name "new" each


containing 300 lines of text each

Aboutsettimeandtouch

Change fileaccessand modificationtime.

Syntax

touch[-a][-c][-m][-rref_file|-ttime]file settime [ -f ref_file ]


file
Changetheaccesstimeoffile.Do notchangethemodificationtimeunless -mis also specified.
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

-c Donotcreateaspecifiedfileifitdoesnotexist. Donotwriteanydiagnostic
messagesconcerningthiscondition.

-m Changethemodificationtimeoffile.Donotchangetheaccesstimeunless-ais

alsospecified.

-r ref_file Usethecorrespondingtimesofthefilenamedbyref_fileinsteadofthecurrent

time.

-ttime Usethespecifiedtimeinsteadofthecurrenttime.timewill beadecimalnumber

oftheform:

[[CC]YY]MMDDhhmm[.SS]

MM - The month of the year [01-12].

DD - The day of the month [01-31].


hh - The hour of the day [00-23].
mm - The minute of the hour [00-59].
CC - The first two digits of the year.
YY - The second two digits of the year.
SS-The secondofthe minute[00-61].

-fref_file Usethecorrespondingtimesofthefilenamedbyref_fileinsteadofthecurrent

time.

File Apathname ofa file whosetimesare tobe modified.

Examples

settimemyfile.txt

Setsthefilemyfile.txtasthecurrenttime/date.

touchnewfile.txt
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Createsafileknownas"newfile.txt", ifthe filedoesnot alreadyexist. Ifthe filealready exists the accessed /


modification time is updated for the file newfile.txt

Aboutcomm

Selectorrejectlinescommontotwofiles.

Syntax

comm[-1][-2][-3]file1file2

-1 Suppresstheoutputcolumnoflinesuniquetofile1.

-2 Suppresstheoutputcolumn oflinesuniquetofile2.

-3 Suppresstheoutputcolumnoflinesduplicatedinfile1andfile2. file1
Name of the first file to compare.
file2 Nameofthesecondfileto compare.

Examples

commmyfile1.txtmyfile2.txt

Theaboveexamplewouldcomparethetwofiles myfile1.txtandmyfile2.txt.

Processutilities:

ps Command:
pscommandisusedtoreporttheprocessstatus. psistheshortnameforProcessStatus.

SYNTAX:
TheSyntaxis ps
[options]
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

OPTIONS:

-a Listinformationaboutallprocesses mostfrequentlyrequested:allthose
except processgroupleadersandprocessesnotassociatedwitha terminal..
-AoreListinformationforallprocesses.

-d Listinformationaboutallprocessesexceptsessionleaders.

-e Listinformationabouteveryprocessnowrunning.

-f Generatesafull listing.

-j PrintsessionIDandprocessgroup ID.

-l Generatealonglisting.
EXAMPLE:

1. ps

Output:

PIDTTY TIMECMD
2540pts/1 00:00:00bash
2621pts/1 00:00:00ps

Intheaboveexample, typingpsalonewouldlistthecurrentrunning processes.

2. ps-f

Output:

UID PIDPPIDCSTIMETTY TIMECMD


nirmala 2540 2536 015:31pts/1 00:00:00 bash
nirmala 2639 2540 015:51pts/1 00:00:00 ps-f

Displaysfullinformationaboutcurrentlyrunningprocesses.
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

killCOMMAND:
killcommandisusedtokillthebackground process.

SYNTAX:
TheSyntax is
kill[-s] [-l]%pid

OPTIONS:

-s Specifythesignalto send.Thesignal maybegivenasa signalnameor


number.
Writeallvaluesofsignalsupportedbytheimplementation,ifnooperandis
-l
given.
-pid Processidorjobid.

-9 Forcetokillaprocess.
EXAMPLE:

StepbyStep process:

 Open a process
music player. xmms

pressctrl+z tostopthe process.

 Toknowgroupidorjobidofthebackground task. jobs -l


 Itwilllistthebackgroundjobswithitsjobidas,
 xmms3956
kmail3467

 To kill a job or
process. kill 3956
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

killcommand killsorterminatesthebackground processxmms.

Aboutnice

Invokesacommandwithanalteredschedulingpriority.

Syntax

nice[-increment|-nincrement]command[argument...]

-increment|-increment must be intherange1-19;ifnot specified, anincrementof10is n


increment assumed. An increment greater than 19 is equivalent to 19.

The super-user may run commands with priority higher than normal by using a
negativeincrementsuchas-10.Anegativeincrementassignedby

an unprivileged user is ignored.


command Thenameofacommandthat istobe invoked. Ifcommand namesanyofthe special built-in
utilities, the results are undefined.
argument Anystringtobesuppliedasanargumentwheninvokingcommand.

Examples

nice+13picomyfile.txt -runsthepico command onmyfile.txt withanincrementof+13. About at


Schedulesacommandtoberanataparticulartime, suchasaprintjoblateatnight.

Syntax

at executescommandsataspecifiedtime.

atq liststheuser'spendingjobs,unlesstheuser isthesuperuser;inthat case,everybody'sjobs


arelisted.Theformatoftheoutputlines(oneforeachjob)is:Jobnumber,date,hour, job
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

class.

atrm deletesjobs,identified bytheirjobnumber.

batchexecutescommandswhensystemload levels permit;inotherwords,whenthe load average drops below


1.5, or the value specified in the invocation of atrun.

at [-c |-k|-s] [-f filename][-qqueuename][-m]-ttime[date][-l][-r]

-c Cshell.csh(1)isusedto executetheat-job.
-k Kornshell.ksh(1)isused toexecutethe at-job.

-s Bourneshell.sh(1) isused toexecutetheat-job.

-f filename Specifiesthefilethatcontainsthecommandtorun.

-m Sendsmailoncethecommandhasbeen run.

-ttime Specifiesatwhattimeyouwantthecommandtoberan.Formathh:mm.am/pm

indicationcanalsofollowthetimeotherwisea24-hourclockisused.Atimezone
nameofGMT,UCTor ZULU(caseinsensitive)canfollowtospecifythatthe
timeis inCoordinatedUniversalTime.Othertimezonescanbespecifiedusing
theTZenvironmentvariable.Thebelowquicktimescanalsobe entered:

midnight - Indicates the time 12:00 am (00:00).

noon - Indicates the time 12:00 pm.


now-Indicatesthecurrentdayandtime.Invokingat-nowwillsubmitsubmit
anat-jobfor potentiallyimmediate execution.

date Specifiesthedateyouwishittoberanon.Formatmonth,date,year.The

following quick days can also be entered:

today - Indicates the current day.

tomorrow-Indicatesthedayfollowing thecurrentday.
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

-l Liststhecommandsthathavebeensettorun.

-r Cancelsthecommandthat you haveset inthepast.

Examples

at -m 01:35 < atjob = Run the commands listed in the 'atjob' file at 1:35AM, in addition all outputthat is
generated fromjob mailtothe user running the task. Whenthis command has been successfully enter you
should receive a prompt similar to the below example.

commands will be executed using /bin/csh


job1072250520.a atWed Dec 2400:22:002003

at -l=Thiscommandwilllist eachofthescheduledjobsasseenbelow. 1072250520.a Wed Dec 24


00:22:00 2003
at-r1072250520.a=Deletesthejobjustcreated. or
atrm23 =Deletesjob23.

Ifyouwishto createajobthat isrepeated youcouldmodifythe filethat executesthecommands with another


command that recreates the job or better yet use the crontab command.

Note:Performing justtheatcommandatthepromptwillgive youanerror"GarbledTime", this is a standard


error message if no switch or time setting is given.

Diskutilities:
du(abbreviatedfromdiskusage)isastandard Unixprogramusedtoestimatefilespace usage—space used
under a particular directory or files on a file system.
du takesasingleargument,specifyingapathnamefor du towork;ifitisnotspecified,the current
directory is used. The SUS mandates for du the following options:
-a,displayanentryforeachfile(andnotdirectory)containedinthecurrentdirectory
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

-H,calculatediskusageforlinkreferencesspecifiedonthecommandline
-k,showsizesas multiplesof1024bytes, not512-byte
-L,calculatediskusage forlinkreferencesanywhere
-s,reportonlythesumoftheusageinthecurrentdirectory,notforeachfile
-x,onlytraverse filesanddirectoriesonthedeviceonwhichthepathnameargument is specified.

Other Unix and Unix-like operating systems mayadd extra options. For example, BSD and GNUduspecifya-
hoption, displayingdiskusage ina format easiertoreadbytheuser, adding units with the appropriate SI
prefix’

$du-sk*
152304directoryOne
1856548directoryTwo

Sumofdirectoriesinhuman-readableformat(Byte,Kilobyte,Megabyte,Gigabyte,Terabyteand Petabyte):

$du-sh*
149M directoryOne
1.8GdirectoryTwo

diskusageofallsubdirectoriesand filesincludinghiddenfileswithinthecurrent directory (sorted by


filesize) :

$du-sk.[!.]**|sort-n

diskusageofallsubdirectoriesand filesincludinghiddenfileswithinthecurrent directory (sorted by


reverse filesize) :

$du-sk.[!.]**|sort–nr

Theweightofdirectories:

$ du-d1-c-h
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

dfcommand:Reportfilesystemdiskspaceusage

Dfcommandexamples-tocheckfree diskspace

Typedf-hordf-ktolist freedisk space: $


df -h
OR
$df–k

Output:
Filesystem SizeUsed AvailUse%Mountedon

/dev/sdb1 20G 9.2G 9.6G 49%/


varrun 393M 144k 393M 1%/var/run
varlock 393M 0 393M 0%/var/lock
procbususb 393M123k393M1%/proc/bus/usb
udev 393M 123k 393M 1% /dev
devshm 393M0 393M 0%/dev/shm
lrm 393M 35M 359M9%/lib/modules/2.6.20-15-generic/volatile
/dev/sdb5 29G 5.4G 22G 20%/media/docs
/dev/sdb3 30G 5.9G 23G 21%/media/isomp3s
/dev/sda1 8.5G 4.3G 4.3G 51% /media/xp1
/dev/sda2 12G 6.5G 5.2G 56% /media/xp2
/dev/sdc1 40G 3.1G 35G 9%/media/backup

ducommand examples

dushowshowmuchspaceoneoremorefilesordirectoriesis using. $ du -sh


103M

-soptionsummarizethespaceadirectoryisusingand -hoptionprovides"Human- readable" output.

Networkingcommands:
Theseare most usefulcommands inmylist while workingonLinuxserver,thisenables you to quickly
troubleshoot connection issues e.g. whether other system is connected or not ,
whetherotherhostisrespondingornotandwhileworkingforFIXconnectivityforadvanced trading system this
tools saves quite a lot of time .
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Thisarticle is incontinuationofmyarticle Howtoworkfast inUnixandUnixCommandtutorials and


Examples for beginners.
• finding host/domainnameandIPaddress -hostname
• testnetworkconnection– ping
• gettingnetworkconfiguration–ifconfig
• Networkconnections,routingtables,interfacestatistics–netstat
• queryDNSlookupname– nslookup
• communicatewithotherhostname–telnet
• outingstepsthat packetstaketogettonetworkhost–traceroute
• viewuserinformation–finger
• checkingstatusofdestinationhost-telnet

ExampleofNetworkingcommandsin Unix

let's see some example of various networking command in Unix and Linux. Some of themare quite basic
e.g. ping and telnet and some are more powerfule.g. nslookup and netstat. When
youusedthesecommandsincombinationoffindandgrep youcanget anything youarelooking for e.g.
hostname, connection end points, connection status etc.

hostname

hostname with no options displays the machines host name hostname–


ddisplaysthedomainnamethemachinebelongsto hostname –f displays
the fullyqualified host anddomain name hostname –i displays the IP
address for the current machine
ping
Itsendspacketsofinformationtotheuser-defined source.Ifthepacketsarereceived, the destination
device sends packets back. Ping can be used for two purposes

1. Toensurethatanetworkconnectioncanbeestablished.
2. Timinginformationasto thespeed oftheconnection.

Ifyoudo ping www.yahoo.comitwilldisplay itsIPaddress.Usectrl+Cto stopthetest.

ifconfig
Viewnetworkconfiguration,itdisplaysthecurrentnetworkadapterconfiguration.Itishandyto
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

determine ifyouaregettingtransmit(TX)orreceive(RX) errors.

netstat
Mostusefuland veryversatile forfindingconnectionto andfromthehost.Youcanfindout all the multicast
groups (network) subscribed by this host by issuing "netstat -g"

netstat -nap | grep port will display process id of application which is using that portnetstat-
aornetstat–allwilldisplayallconnectionsincludingTCPandUDP netstat --tcp or netstat –t will
display only TCP connection
netstat--udpornetstat–uwilldisplayonlyUDPconnectionnetstat
-gwilldisplayallmulticastnetworksubscribedbythis host.

nslookup
IfyouknowtheIPaddress it willdisplayhostname.TofindalltheIPaddresses foragiven domain name, the
command nslookup is used. You must have a connection to the internet for this utility to be useful.
E.g.nslookup blogger.com

Youcanalso usenslookupto convert hostnametoIPAddressand fromIPAddress from hostname.

traceroute
Ahandyutilityto viewthenumber ofhopsandresponsetimeto getto aremotesystemor web site is
traceroute. Again you need an internet connection to make use of this tool.

finger
Viewuser information,displaysauser’sloginname,realname,terminalnameandwritestatus. this is pretty old
unix command and rarely used now days.

telnet
Connectsdestinationhost viatelnet protocol, iftelnet connectionestablishonanyport means
connectivity between two hosts is working fine.
telnethostnameport willtelnethostname withtheportspecified.Normallyitisusedto see whether host
is alive and network connection is fine or not.

10Mostimportantlinuxnetworkingcommands

Linux is most powerfuloperating systemwhich often needs to use commands to explore it


effectively.Someofthecommandsarerestrictedtonormaluser groupsasthey arepowerful and has more
functionality involved in it.Here we summarized most interesting and useful networking commands
which every linux user are supposed to be familiar with it.
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

1. Arp manipulatesthekernel’s ARPcache invariousways. Theprimaryoptionsareclearing an address


mapping entryand manually setting up one. For debugging purposes, the arp programalso
allowsacompletedumpofthe ARPcache.ARPdisplaystheIPaddressassigned to particular ETH card and mac
address

[fasil@smashtech]# arp
Address HWtypeHWaddress FlagsMask Iface
59.36.13.1 ether C eth0

2. Ifconfig isusedtoconfigurethenetworkinterfaces.Normallyweusethiscommandto check the


IP address assigned to the system.It is used at boot time to set up interfaces as necessary. After
that, it is usually only needed when debugging or when system tuning
isneeded.

[fasil@smashtech~]# /sbin/ifconfig
eth0UPBROADCASTRUNNINGMULTICASTMTU:1500Metric:1
RXpackets:126341errors:0dropped:0overruns:0frame:0 TX
packets:44441 errors:0 dropped:0 overruns:0 carrier:0 collisions:0
txqueuelen:1000

3. Netstatprintsinformationaboutthenetworking subsystem.Thetypeofinformationwhichis usually


printed by netstat are Print network connections, routing tables, interface statistics, masquerade
connections, and multicast.

[fasil@smashtech~]# netstat
ActiveInternetconnections(w/oservers)
ProtoRecv-QSend-QLocalAddress ForeignAddress State
tcp0 0 .230.87:https ESTABLISHED
ActiveUNIXdomainsockets(w/oservers)
ProtoRefCntFlagsType State I-Node Path
unix10 [] DGRAM 4970/dev/log
unix2 [] DGRAM 6625@/var/run/hal/hotplug_socket
unix2 [] DGRAM 2952 @udevd
unix2 [] DGRAM 100564
unix3 [] STREAM CONNECTED 62438/tmp/.X11-unix/X0
unix3 [] STREAM CONNECTED 62437
unix3 [] STREAM CONNECTED 10271@/tmp/fam-root-
unix3 [] STREAM CONNECTED 10270
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

unix3 [] STREAM CONNECTED 9276


unix3 [] STREAM CONNECTED 9275

4. ping command is used to check the connectivityofa systemto a network.Whenever there


isprobleminnetworkconnectivityweusepingtoensurethesystemisconnectedtonetwork.

[root@smashtech~]#ping google.com
PINGgoogle.com(74.125.45.100)56(84)bytesofdata.
64 bytes from yx-in-f100.google.com (74.125.45.100): icmp_seq=0 ttl=241 time=295 ms 64 bytes
from yx-in-f100.google.com (74.125.45.100): icmp_seq=1 ttl=241 time=277 ms 64 bytes from yx-
in-f100.google.com (74.125.45.100): icmp_seq=2 ttl=241 time=277 ms

---google.comping statistics---
3packetstransmitted, 3received, 0%packetloss,time 6332ms
rttmin/avg/max/mdev=277.041/283.387/295.903/8.860ms,pipe2

5. Nslookup is a program to query Internet domain name servers. Nslookup has two modes:
interactive and non-interactive. Interactive mode allows the user to query name servers for
information about various hosts and domains or to print a list of hosts in a domain. Non-
interactivemodeisusedtoprintjustthenameandrequestedinformationforahostordomain.

[fasil@smashtech~]#nslookupgoogle.com
Server: server ip
Address: gatewayip 3

Non-authoritativeanswer:
Name: google.com
Address:209.85.171.100
Name: google.com
Address:74.125.45.100
Name: google.com
Address:74.125.67.100

6. dig (domain information groper) is a flexible tool for interrogating DNS name servers. It
performsDNS lookupsanddisplaystheanswersthat arereturned fromthenameserver(s)that were queried.
Most DNS administrators use dig to troubleshoot DNS problems because of its flexibility, ease ofuse and
clarityofoutput. Other lookuptools tend to have less functionality than dig.

[fasil@smashtech~]#diggoogle.com
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

;<<>> DiG9.2.4<<>>google.com
;;globaloptions:printcmd
;;Gotanswer:
;;->>HEADER<<- opcode:QUERY,status:NOERROR,id:4716
;;flags:qr rdra;QUERY:1, ANSWER:3, AUTHORITY:4,ADDITIONAL:4

;;QUESTIONSECTION:
;google.com. IN A

;;ANSWERSECTION:
google.com. 122 IN A 74.125.45.100
google.com. 122 IN A 74.125.67.100
google.com. 122 IN A 209.85.171.100

;;AUTHORITY SECTION:
google.com. 326567 IN NS ns3.google.com. google.com. 326567
IN NS ns4.google.com. google.com. 326567 IN NS ns1.google.com.
google.com. 326567 IN NS ns2.google.com.

;;ADDITIONALSECTION:

ns1.google.com. 152216 IN A 216.239.32.10


ns2.google.com. 152216 IN A 216.239.34.10
ns3.google.com. 152216 IN A 216.239.36.10
ns4.google.com.152216 INA216.239.38.10

;;Querytime:92msec
;;SERVER:172.29.36.1#53(172.29.36.1)
;;WHEN: Thu Mar5 14:38:45 2009
;;MSGSIZErcvd: 212

7. Route manipulates the IProuting tables. Its primaryuse is to set upstatic routesto specific hosts or
networks via an interface after it has been configured with the ifconfigprogram.When the add or del
options are used, route modifies the routing tables. Without these options, route displays the current
contents of the routing tables.

[fasil@smashtech~]#route
Kernel IP routing table
Destination Gateway Genmask FlagsMetricRef Use Iface
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

54.192.56.321* 255.255.255.0 U00 0eth0


* 255.255.0.0 U 0 0 0eth0
default 0.0.0.0 UG 0 0 0eth0

8. Traceroute:Internet isalargeandcomplexaggregationofnetworkhardware,connected together


by gateways. Tracking the route one’s packets follow (or finding the miscreant gateway that’s
discarding your packets) can be difficult.

Traceroute utilizes the IP protocol‘time to live’ field and attempts to elicit an ICMP
TIME_EXCEEDEDresponse fromeachgatewayalongthepathtosomehost.Theonly mandatoryparameter
is the destination host name or IP number. The default probe datagramlengthis40 bytes, butthis
maybe increasedbyspecifyingapacket length(in bytes) after the destination host name.

[fasil@smashtech~]# traceroutegoogle.com
traceroute:Warning:google.comhasmultipleaddresses;using209.85.171.100 traceroute to
google.com (209.85.171.100), 30 hops max, 38 byte packets
1***

9.W-displays information about the users currently on the machine, and their processes. The
headershows, inthis order,thecurrenttime, how longthesystemhasbeenrunning, howmany users are
currently logged on, and the system load averages for the past 1, 5, and 15 minutes.

[fasil@smashtechl~]# w
15:18:22up 4:38, 3users, loadaverage:0.89, 0.34,0.19
USER TTYFROM LOGIN@IDLEJCPUPCPU WHAT
root :0 - 10:41?xdm?24:53 1.35s/usr/bin/gnome-session
root pts/1 :0.0 10:58 1.00s 0.34s 0.00sw
root pts/2 :0.0 12:10 23:32 0.03s 0.03s bash

Filters:

moreCOMMAND:
morecommand isusedtodisplaytext intheterminalscreen.Itallowsonlybackward movement.
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

SYNTAX:
TheSyntax is
more[options]filename

OPTIONS:

-c Clearscreenbeforedisplaying.
-e Exitimmediatelyafterwriting thelastlineofthelastfileintheargument list.
-n Specifyhow manylinesareprintedinthescreenforagiven file.
+n Startsupthefilefromthe givennumber.
EXAMPLE:

1. more-c index.php

Clearsthescreenbeforeprintingthefile.

2. more -3 index.php

Printsfirstthreelinesofthegivenfile. PressEntertodisplaythefilelinebyline.

headCOMMAND:
headcommand isusedto displaythe firsttenlinesofafile,andalso specifieshowmany lines to display.

SYNTAX:
TheSyntax is
head[options]filename

OPTIONS:

-n Tospecifyhow manylinesyouwanttodisplay.
-nnumberThenumberoption-argumentmustbeadecimalintegerwhosesign affects
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

thelocationinthe file,measured inlines.


Thenumberoption-argument must beadecimalintegerwhosesignaffects the
-c number location in the file, measured in bytes.

EXAMPLE:

1. headindex.php

Thiscommandprintsthefirst10linesof'index.php'.

2. head-5index.php

Theheadcommanddisplaysthefirst5linesof'index.php'.

3. head -c5index.php

Theabovecommanddisplaysthefirst5charactersof'index.php'.

tailCOMMAND:
tailcommand isusedtodisplaythe last orbottompartofthe file.Bydefault it displays last 10 lines of a
file.

SYNTAX:
TheSyntax is
tail[options]filename

OPTIONS:

-l To specifythe unitsof lines.


-b To specifythe unitsofblocks.
-n Tospecifyhowmanylinesyouwanttodisplay.

Thenumberoption-argumentmustbeadecimalintegerwhosesignaffectsthe
-c number
locationinthefile,measured inbytes.
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

numberThenumberoption-argument must beadecimalintegerwhosesignaffects the location in the file,


measured in lines.
EXAMPLE:

1. tailindex.php

Itdisplaysthelast10linesof'index.php'.

2. tail-2index.php

Itdisplaysthelast2linesof'index.php'.

3. tail-n5index.php

Itdisplaysthelast5linesof'index.php'.

4. tail-c5index.php

Itdisplaysthelast5charactersof'index.php'.

cutCOMMAND:
cut command isusedto cutout selected fieldsofeachlineofa file.Thecut command uses delimiters
to determine where to split fields.

SYNTAX:
The Syntax is
cut[options]

OPTIONS:

-c Specifiescharacterpositions.
-b Specifiesbytepositions.
-dflagsSpecifiesthedelimitersandfields.
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

EXAMPLE:
1. cut-c1-3text.txt

Output:

Thi

Cutthefirstthreelettersfromtheaboveline.

2. cut -d,-f1,2text.txt

Output:

Thisis, anexampleprogram

Theabovecommandisusedtosplitthefieldsusingdelimiterandcutthefirsttwofields.

pasteCOMMAND:
pastecommand isusedtopastethecontent fromone filetoanotherfile.Itisalso usedto set column
format for each line.

SYNTAX:
The Syntax is
paste[options]

OPTIONS:

-s Pasteone fileatatime insteadofinparallel.


-d ReusecharactersfromLISTinstead ofTABs.
EXAMPLE:

1. pastetest.txt>test1.txt

Pastethecontent from'test.txt'fileto'test1.txt' file.


J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

2. ls|paste----

Listallfilesanddirectoriesinfourcolumnsforeach line.

sort COMMAND:
sortcommandisusedtosortthelinesinatextfile.
SYNTAX:
TheSyntax is
sort[options] filename
OPTIONS:

-r Sortsinreverseorder.
-u Iflineisduplicateddisplayonlyonce.
-ofilenameSendssortedoutputtoafile.
EXAMPLE:

1. sorttest.txt

Sortsthe'test.txt'fileandprintsresultinthe screen.

2. sort-rtest.txt

Sortsthe'test.txt'fileinreverseorderandprintsresultinthe screen.

Aboutuniq

Reportorfilteroutrepeatedlines inafile.

Syntax

uniq[-c|-d|-u][ -ffields][-schar ][-n] [+m][input_file[output_file] ]

-c Precedeeachoutputlinewitha countofthe numberoftimestheline occurredin


J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

theinput.
-d Suppressthewritingoflinesthatarenotrepeatedintheinput.

-u Suppressthewritingoflinesthatarerepeatedintheinput.

-f fields Ignorethefirstfieldsfieldsoneachinputlinewhendoingcomparisons, where

fieldsisapositivedecimalinteger.Afieldisthemaximalstringmatchedbythe
basicregularexpression:

[[:blank:]]*[^[:blank:]]*

Iffieldsspecifiesmorefieldsthanappear onaninputline, anullstringwillbe

usedfor comparison.

-schar Ignorethefirstcharscharacterswhendoingcomparisons,wherecharsisa

positivedecimalinteger.Ifspecifiedinconjunctionwiththe-foption,thefirst
charscharactersafterthefirstfieldsfieldswillbeignored.Ifcharsspecifiesmore
charactersthanremainonaninputline,anullstringwill beusedfor comparison.

-n Equivalentto -ffieldswithfieldssetton.

+m Equivalentto-scharswithcharssettom.

input_file Apathnameoftheinputfile.Ifinput_fileisnotspecified,oriftheinput_fileis-

, the
standardinputwillbeused.

output_file Apathnameoftheoutputfile.Ifoutput_fileisnotspecified,thestandardoutput

willbeused. Theresultsareunspecifiedifthefilenamedbyoutput_fileisthe
file named byinput_file.

Examples

uniqmyfile1.txt>myfile2.txt-Removesduplicatelinesinthefirstfile1.txtandoutputsthe

resultstothesecondfile.
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Abouttr

Translate characters.

Syntax

tr[-c][-d][-s][string1][string2]

-c Complementtheset ofcharactersspecifiedbystring1.

-d Deletealloccurrencesofinputcharactersthatarespecifiedbystring1.

-s Replaceinstancesofrepeatedcharacterswithasinglecharacter.

string1 Firststringorcharactertobe changed.

string2 Secondstringorcharacterto changethestring1.

Examples

echo "12345678 9247" | tr 123456789 computerh - this example takes an echo response of '12345678
9247' and pipes it throughthe tr replacing the appropriate numbers with the letters. In this example it
would return computer hope.

tr-cd'\11\12\40-\176'<myfile1>myfile2-thisexamplewouldtakethefile myfile1andstrip all non printable


characters and take that results to myfile2.
TextprocessingutilitiesandBackuputilities: Text
processing utilities:
cat:concatenatefilesandprintonthestandardoutput Usage: cat
[OPTION] [FILE]...
eg.catfile1.txtfile2.txt cat n
file1.txt
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

echo : display a line of text


Usage:echo[OPTION][string]... eg. echo
I love India
echo$HOME
wc:printthenumberofnewlines,words,andbytesinfiles Usage: wc
[OPTION]... [FILE]...
eg.wcfile1.txt wc L
file1.txt
sort:sort linesoftextfiles
Usage:sort[OPTION]...[FILE]...
eg.sortfile1.txt sort r
file1.txt

GeneralCommands:

dateCOMMAND:
datecommandprintsthedateand time.

SYNTAX:
TheSyntax is
date[options] [+format] [date]

OPTIONS:

Slowlyadjust the timebysss.fffseconds(fffrepresentsfractionsofa second).


-a
Thisadjustmentcanbepositiveor negative.Onlysystemadmin/super user
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

canadjustthetime.

- date-Setsthetimeanddatetothevaluespecfied inthe datestring. Thedatestrmay string contain


the month names, timezones, 'am', 'pm', etc.
-u Display(orset)the dateinGreenwichMeanTime(GMT-universaltime).

Format:

%a Abbreviated weekday(Tue).

%A Fullweekday(Tuesday).

%b Abbreviatedmonthname(Jan).

%B Fullmonthname(January).

%c Country-specificdateandtimeformat..

%D Dateintheformat%m/%d/%y.

%j Juliandayofyear(001-366).

%n Insert anewline.

%p Stringtoindicatea.m.or p.m.

%T Time intheformat%H:%M:%S.

%t Tabspace.

%V Weeknumberin year(01-52);start weekonMonday.


EXAMPLE:
datecommand date

TheabovecommandwillprintWed Jul2310:52:34IST2008

1. Tousetab space:
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

date+"Dateis%D%t Timeis%T"

The above command will remove space and print as


Dateis07/23/08Timeis10:52:34

2. Toknowtheweeknumberoftheyear, date -V
Theabovecommandwillprint30

3. Tosetthe date,

date-s"10/08/200811:37:23"

TheabovecommandwillprintWedOct0811:37:23IST2008

whoCOMMAND:
who commandcanlist thenamesofuserscurrentlylogged in,theirterminal,thetimethey have
been logged in, and the name ofthe host fromwhich they have logged in.

SYNTAX:
TheSyntax is
who[options][file]

OPTIONS:

Print theusernameoftheinvokinguser, The'am'and'i' must bespace separated.


am i
-bPrintstimeoflast systemboot. -d print dead
processes.
-H Printcolumnheadingsabovetheoutput.
-i Include idletimeasHOURS:MINUTES.Anidletimeof.indicates activity
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

withinthelastminute.
-m Sameaswhoami.
-qPrintsonlytheusernamesandtheusercount/totalnoofuserslogged in. -T,- w Include user's
message status in the output.
EXAMPLE:

1.who–Uh

Output:

NAME LINE TIME IDLE PIDCOMMENT

hiox ttyp3 Jul1011:08. 4578

Thissampleoutput wasproducedat11a.m.The"."indiacatesactivitywithinthe last minute.

2.whoami

whoamicommandprintsthe username.

echo COMMAND:
echocommand printsthegiveninputstringtostandardoutput.

SYNTAX:
TheSyntax is
echo[options..] [string]

OPTIONS:

-n donot outputthetrailingnewline
-eenable interpretationofthebackslash-escapedcharacterslistedbelow -E disable
interpretation of those sequences in STRINGs
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Without-E,thefollowingsequencesarerecognizedandinterpolated:

\NNN thecharacterwhoseASCIIcodeis NNN


(octal)
\a alert (BEL)
\\backslash
\b backspace
\c suppresstrailingnewline
\f formfeed
\n newline
\r carriagereturn
\t horizontaltab
\v verticaltab

EXAMPLE:
echocommand
echo "hscriptsHioxIndia"

TheabovecommandwillprintashscriptsHioxIndia

1. Touse backspace:

echo-e"hscripts\bHiox\bIndia"

TheabovecommandwillremovespaceandprintashscriptsHioxIndia

2. Tousetabspaceinechocommand echo -e
"hscripts\tHiox\tIndia"
Theabovecommandwillprintashscripts Hiox India
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

passwdCOMMAND:
passwdcommandisusedtochange your password.

SYNTAX:
The Syntax is
passwd[options]

OPTIONS:

-a Showpasswordattributesforallentries.
-l Lockspasswordentryforname.
Deletespasswordforname. Theloginnamewillnotbepromptedfor
-d
password.
Forcetheuser to changepassword atthenextloginbyexpiring thepassword
-f
forname.
EXAMPLE:

1. passwd

Enteringjustpasswdwouldallowyoutochangethepassword. Afterenteringpasswdyou will receive the


following three prompts:

CurrentPassword:
NewPassword:
ConfirmNew Password:

Eachofthesepromptsmust beenteredcorrectlyforthepasswordtobesuccessfully changed.

pwdCOMMAND:
pwd-Print WorkingDirectory.pwdcommandprintsthefullfilenameofthecurrent working directory.
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

SYNTAX:
The Syntax is
pwd[options]

OPTIONS:

-P Thepathnameprintedwillnotcontainsymboliclinks.
-L Thepathnameprintedmaycontainsymboliclinks.
EXAMPLE:

1. Displaysthecurrentworkingdirectory. pwd
Ifyouareworking inhomedirectorythen,pwdcommanddisplaysthecurrent working directory as /home.

calCOMMAND:
calcommandisusedtodisplaythe calendar.

SYNTAX:
TheSyntax is
cal[options][month][year]

OPTIONS:

-1 Displayssinglemonthasoutput.
-3 Displaysprev/current/nextmonthoutput.
-sDisplayssundayasthe first dayoftheweek. -m Displays Monday as
the first day of the week.
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

-j DisplaysJuliandates(daysone-based,numberedfromJanuary1).
-y Displaysacalendar forthecurrentyear.
EXAMPLE:

1. cal

Output:

September2008
Su Mo TuWeThFrSa

12 3 4 56
7 8 9101112 13
141516 17181920
212223 24252627
282930

calcommanddisplaysthecurrentmonthcalendar.

2.cal-352008

Output:

April2008 May2008 June2008

Su Mo TuWeThFrSa Su Mo Tu WeThFrSaSuMo TuWeThFrSa


12345 123 1234567
6789101112 45 6 78910 891011121314
13141516171819 111213 14 15 16 17 15161718192021
20212223242526 181920 21 22 23 24 22232425262728
27 282930 25 26 27 28293031 2930

HerethecalcommanddisplaysthecalendarofApril,MayandJunemonthofyear2008.

loginCommand
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Signsintoanewsystem.

Syntax

login[ -p][-ddevice] [-hhostname |terminal|-r hostname ] [name[environ] ]

-p Usedtopassenvironmentvariablestotheloginshell.
-ddevice loginacceptsadeviceoption,device.deviceistakento bethepathnameofthe

TTYportlogin istooperateon.The useofthedeviceoptioncan beexpectedto


improveloginperformance, sinceloginwillnotneedtocallttyname.The-d
optionisavailableonlytouserswhoseUIDandeffectiveUIDareroot.Any
otherattempttouse -dwillcauselogintoquietlyexit.

-hhostname| Usedbyin.telnetdtopass informationabouttheremotehostandterminaltype.

terminal

-rhostname Used by in.rlogind to pass information about

theremotehost.

Examples

logincomputerhope.com-Wouldattempttologintothecomputerhope domain.

unamecommand

Printnameofcurrentsystem.

Syntax

uname[-a][-i][-m][-n] [-p][-r][-s] [-v][-X][-Ssystemname]

-a Printbasicinformationcurrentlyavailablefromthesystem.

-i Print thenameofthehardwareimplementation(platform).
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

-m Printthemachinehardwarename(class). Useofthisoptionis discouraged; use


uname-pinstead.

-n Printthenodename(thenodenameisthenamebywhichthesystemisknown to

acommunications network).

-p Printthecurrenthost'sISAorprocessor type.

-r Printtheoperatingsystemreleaselevel.

-s Printthenameoftheoperatingsystem. Thisisthe default.

-v Printtheoperatingsystemversion.

-X Print expanded system information, one information

element per line, as expected by SCO Unix. The


displayedinformationincludes:

systemname,node,release,version,machine,andnumberofCPUs.

 BusType,Serial,and Users(setto"unknown"inSolaris)
 OEM#andOrigin#(setto0and1,respectively)

-S Thenodenamemaybechangedbyspecifyingasystemnameargument.The
systemname systemnameargumentisrestrictedtoSYS_NMLNcharacters. SYS_NMLNis
animplementationspecific valuedefined in<sys/utsname.h>.Onlythesuper-
user is allowed
thiscapability.

Examples

uname-arv

Listthebasicsysteminformation,OSrelease,andOSversionasshownbelow. SunOS hope 5.7


Generic_106541-08 sun4m sparc SUNW,SPARCstation-10
J.B.INSTITUTEOFENGINEERINGAND
TECHNOLOGY
LinuxProgrammingNotes

uname-p

Displaythe Linuxplatform.

SED:

What issed?
Anon-interactivestream
 editor
Interpretssedinstructionsandperforms
 actions
Usesed
 to:

Automaticallyperformeditsonfile(s)

Simplifydoingthesameeditsonmultiplefiles

Writeconversionprograms
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

SedCommandSyntax(Sed Scripts):

SedOperation

HowDoessedWork?


lineofinputiscopiedintoatemporarybuffercalledpatternspace

editingcommandsareapplied

sedreadslineofinput
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

subsequentcommandsareappliedtolinein the pattern space,not the original input line




once finished,line issenttooutput

(unless–noptionwas used)

lineisremovedfrompatternspace

sedreadsnextlineofinput,untilendof file
 Note:
input file is unchanged
sedinstructionformat(SedAddresses):
addressdetermineswhichlinesinthe input file aretobeprocessedbythe
 command(s)

ifnoaddressisspecified,thenthecommandisappliedtoeachinputline
address
 types:

Single-Lineaddress

Set-of-Linesaddress

Rangeaddress

Nested address

Single-LineAddress
Specifiesonlyonelineintheinput
 file

special:dollarsign($)denoteslastlineofinputfile

Examples:


showonlyline3

sed-n-e'3p'input-file


showonlylast line
J.B.INSTITUTEOFENGINEERING
ANDTECHNOLOGY

sed-n-e'$p'input-file


substitute“endif”with“fi”online10

sed -e'10 s/endif/fi/' input-file

Set-of-LinesAddress
useregularexpressiontomatch
 lines

writtenbetweentwo slashes

processonlylinesthatmatch

maymatchseveral lines

linesmayormaynotbeconsecutives

Examples:

sed-e‘/key/s/more/other/’input-file sed -n -
e ‘/r..t/ p’ input-file
RangeAddress


Definesasetofconsecutivelines
Format:

start-addr,end-addr (inclusive)

Examples:

10,50 line-number,line-number
10,/R.E/ line-number,/RegExp/
/R.E./,10 /RegExp/,line-number
J.B.INSTITUTEOFENGINEERINGAND
TECHNOLOGY
LinuxProgrammingNotes

/R.E./,/R.E/ /RegExp/,/RegExp/
Example: Range Address
%sed-n -e‘/^BEGIN$/,/^END$/p’ input-file
PrintlinesbetweenBEGINandEND,
 inclusive

BEGIN

Line1ofinput
Line2ofinput Line3
of input END
Line4ofinput
Line5ofinput
NestedAddress
Nestedaddresscontainedwithinanotheraddress

Example:
printblanklinesbetweenline20and30

20,30{

/^$/p

Addresswith!
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

address withanexclamationpoint(!):
instructionwillbeappliedtoalllinesthat do notmatchtheaddress Example:
printlinesthatdonotcontain“obsolete”

sed-e‘/obsolete/!p’input-file sed
commands

LineNumber


linenumbercommand(=)writesthecurrentlinenumberbefore eachmatched/output line
Examples:

sed-e'/Two-thirds-time/='tuition.data sed -e
'/^[0-9][0-9]/=' inventory
modifycommands
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

InsertCommand:i
addsoneormore lines directlyto theoutputbeforethe
 address:

inserted“text”neverappearsinsed’spatternspace

cannotbeusedwitharangeaddress;canonlybeusedwiththesingle-lineand set-of-lines address types

Syntax:

[address]i\ text
AppendCommand:a
addsoneormorelinesdirectlyto theoutput afterthe
 address:

Similartotheinsertcommand (i),appendcannotbeusedwitharange address.

Appended“text”doesnotappearinsed’spatternspace.

Syntax:

[address]a\ text
ChangeCommand:c
replacesanentirematchedlinewithnew
 text
acceptsfouraddress
 types:
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

single-line,set-of-line,range,andnestedaddresses.
Syntax:

[address1[,address2]]
c\ text
DeleteCommand:d
deletestheentire pattern
 space

commands following the delete command are ignored since the deleted text isno longer in the
pattern space

Syntax:

[address1[,address2]
]d Substitute
Command (s) Syntax:
[addr1][,addr2]s/search/replace/[flags]
replacestextselectedbysearchstringwithreplacement
 string
searchstringcanberegular
 expression
flags:


global(g),i.e.replacealloccurrences

specificsubstitutioncount(integer), default1

RegularExpressions:usewithsed
J.B.INSTITUTEOFENGINEERING
ANDTECHNOLOGY

SubstitutionBack References

Example:ReplacementString&

$catdatafile
J.B.INSTITUTEOFENGINEERINGAND
TECHNOLOGY

CharlesMain 3.0 .98 334

Sharon Gray 5.3 .97 523

PatriciaHemenway 4.0 .7 4 17

TBSavage 4.4 .84 5 20

AMMain Jr. 5.1 .94 313

Margot Weber 4.5 .89 5 9

AnnStephens 5.7 .94 513

$sed-e‘s/[0-9][0-9]$/&.5/’datafile

CharlesMain 3.0 .98 334.5

Sharon Gray 5.3 .97 523.5

PatriciaHemenway 4.0 .7 4 17.5

TBSavage 4.4 .84 5 20.5

AMMain Jr. 5.1 .94 313.5

Margot Weber 4.5 .89 5 9

AnnStephens 5.7 .94 513.5

TransformCommand(y)
Syntax:
[addr1][,addr2]y/a/b/

translatesonecharacter'a'toanother'b'
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

cannotuseregularexpression metacharacters

cannotindicatearangeofcharacters

similarto“tr”command

Example:

$sed -e‘1,10y/abcd/wxyz/’ datafile

sed i/o commands

Input (next)Command:nandN
Forcessedtoreadthenextinput
 line

Copiesthecontentsofthepatternspacetooutput

Deletesthecurrentlineinthepattern space

Refillsitwiththenextinputline

Continueprocessing
N(uppercase)
 Command

addsthenextinputlinetothecurrentcontentsofthepatternspace

useful whenapplyingpatternstotwoormorelinesatthesametime

OutputCommand:pandP
PrintCommand
 (p)

copiestheentirecontentsofthepatternspacetooutput

willprintsamelinetwiceunlesstheoption“–n”isused
Printcommand:
 P

printsonlythefirstlineofthepatternspace
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes


printsthecontentsofthepatternspaceuptoandincluding anewline character

anytext followingthefirst newlineisnot printed

ListCommand(l)
Thelistcommand:
 l

showsspecialcharacters(e.g.tab,etc)
Theoctaldumpcommand(od-c) canbeusedtoproducesimilar
 result

HoldSpace
temporarystorage
 area

used tosavethe contentsofthepattern space

4commandsthatcanbeusedtomovetextbackandforth between thepattern space and the hold space:


h,H

g,G

Filecommands
allowstoreadandwritefrom/tofilewhileprocessingstandard
 input
read:r
 command
write:w
 command

ReadFilecommand
Syntax:rfilename

queue the contents of filename to be read and inserted into the output streamat the end of the current
cycle, or when the next input line is read
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes


iffilenamecannotberead,it istreatedasifit were anemptyfile,without any error indication

singleaddressonly
WriteFilecommand Syntax:w
filename

Writethe patternspacetofilename

The filenamewillbe created(ortruncated)beforethefirstinputlineis read

allwcommandswhichrefertothesamefilenameareoutputthroughthesame FILE stream

BranchCommand(b)

Changetheregularflowofthecommandsinthescriptfile
 Syntax:
[addr1][,addr2]b[label]

Branch(unconditionally)to‘label’or endofscript

If“label”issupplied,executionresumesatthelinefollowing:label;otherwise, control passes to the end of the script
Branch
 label

:mylabel

Example:Thequit(q)Command Syntax:
[addr]q

Quit(exitsed)whenaddrisencountered.

Example:Displaythefirst50linesandquit

%sed-e’50q’datafile
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNote

Sameas:

%sed-n-e‘1,50p’ datafile

%head-50datafile

Awk

What isawk?
createdby:Aho,Weinberger,and
 Kernighan
scriptinglanguage usedfor manipulatingdataandgenerating
 reports
versionsof
 awk

awk,nawk,mawk,pgawk,…

GNUawk: gawk

What canyoudowithawk?
awk
 operation:

scansafilelinebyline

splitseachinputlineinto fields

comparesinputline/fieldsto pattern

performsaction(s)on matched lines
Useful
 for:

transform datafiles

produceformattedreports
Programming
 constructs:
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes


formatoutputlines

arithmeticandstring operations

conditionals and loops

TheCommand:awk

Basicawk Syntax
awk[options]‘script’
 file(s)
awk[options]–fscriptfile
 file(s)

Options:

-F tochangeinputfieldseparator

-f tonamescript file

Basicawk Program


consistsofpatterns&actions:
pattern{action}

ifpatternismissing,actionisappliedtoalllines
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes


ifactionismissing,thematchedline isprinted

must haveeitherpatternor action

Example:

awk'/for/'testfile


printsalllinescontainingstring“for”in testfile

BasicTerminology:input file
 Afieldisaunitofdatainaline
Eachfieldisseparatedfromtheotherfieldsbythe
 fieldseparator

defaultfieldseparatoriswhitespace
A
 recordisthecollection offieldsinaline
Adatafileismadeupof
 records

ExampleInputFile

Buffers
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes


awk supportstwotypesofbuffers:recordandfield
field
 buffer:

oneforeach fieldsinthecurrent record.

names:$1,$2, …
recordbuffer
 :

$0holdstheentirerecord

Some SystemVariables

FS Fieldseparator (default=whitespace)

RS Recordseparator (default=\n)

NF Numberoffields incurrentrecord

NR Number ofthecurrentrecord

OFS Outputfieldseparator(default=space)

ORS Outputrecordseparator(default=\n)
FILENAME Current filename
Example:Recordsand Fields
J.B.INSTITUTEOFENGINEERING
ANDTECHNOLOGY

%catemps

TomJones 44245/12/66 543354

MaryAdams 5346 11/4/63 28765

Sally Chang 16547/22/54 650000

BillyBlack 1683 9/23/44 336500

%awk'{printNR,$0}'emps

1TomJones 44245/12/66 543354

2MaryAdams 5346 11/4/63 28765

3SallyChang 1654 7/22/54 650000

4BillyBlack 1683 9/23/44 336500

Example:SpaceasField Separator

%catemps

TomJones 44245/12/66543354

MaryAdams 5346 11/4/6328765

Sally Chang 16547/22/54650000

BillyBlack 1683 9/23/44336500

%awk'{printNR,$1,$2,$5}' emps 1 Tom


Jones 543354
2 MaryAdams 28765
J.B.INSTITUTEOFENGINEERING
ANDTECHNOLOGY

3 SallyChang 650000

4 BillyBlack336500

Example:ColonasFieldSeparator

%catem2

TomJones:4424:5/12/66:543354

MaryAdams:5346:11/4/63:2876
5
SallyChang:1654:7/22/54:65000
0 Billy
Black:1683:9/23/44:336500
%awk-F:'/Jones/{print$1,$2}'
em2 Tom Jones 4424
awkScripts

awkscriptsaredividedintothreemajor
 parts:
J.B.INSTITUTEOFENGINEERING
ANDTECHNOLOGY

commentlinesstartwith
 #

BEGIN:pre-processing

performs processing that must be completed before the file
processing starts (i.e., before awk starts reading records
from the input file)

useful for initialization tasks such as to initialize variables
and to create report headings
BODY:
 Processing

contains main processing logic to be applied to input records

likea loopthatprocesses inputdataone recordata time:

if a file contains 100 records, the bodywill be executed
100times, one for each record
END:post-
 processing

contains logic to be executed after all input data have been
processed

logic such as printing report grand totalshould be
performed in this part of the script

Pattern/Action Syntax
J.B.INSTITUTEOFENGINEERING
ANDTECHNOLOGY

CategoriesofPatterns

ExpressionPattern types

match

entireinputrecord

regularexpressionenclosed by‘/’s

explicitpattern-matchingexpressions

~(match),!~(notmatch)

expressionoperators

arithmetic

relational

logical

Example: matchinputrecord

%catemployees2

TomJones:4424:5/12/66:543354
J.B.INSTITUTEOFENGINEERING
ANDTECHNOLOGY

Mary Adams:5346:11/4/63:28765
J.B.INSTITUTEOFENGINEERINGAND
TECHNOLOGY

SallyChang:1654:7/22/54:650000 Billy
Black:1683:9/23/44:336500
% awk –F: '/00$/' employees2
SallyChang:1654:7/22/54:650000 Billy
Black:1683:9/23/44:336500 Example:
explicit match
%catdatafile

northwestNWCharlesMain 3.0 .98 334

western WE Sharon Gray 5.3.97 5 23

southwestSW LewisDalsass 2.7 .8 2 18

southernSO SuanChin 5.1 .95 4 15

southeastSE PatriciaHemenway 4.0 .7 417

eastern EA TBSavage 4.4 .84 520

northeastNE AMMain 5.1 .94 3 13

north NO Margot Weber 4.5.89 59

central CT AnnStephens 5.7 .94 5 13

%awk'$5~/\.[7-9]+/'datafile

southwestSW LewisDalsass 2.7 .8 2 18

central CT AnnStephens 5.7 .94 5 13


J.B.INSTITUTEOFENGINEERING
ANDTECHNOLOGY

Examples: matchingwithREs

%awk '$2 !~ /E/{print $1,


$2}'datafile northwest NW
southwest
SWsouthern
SOnorthNO
central CT
%awk '/^[ns]/{print
$1}'datafile northwest
southwest
southern
southeast
northeast
north
ArithmeticOperators

Operator Meaning Example

+ Add x+y

- Subtract x–y

* Multiply x*y
J.B.INSTITUTEOFENGINEERINGAND
TECHNOLOGY

/ Divide x/y

% Modulus x%y

^ Exponential x^y

Example:

%awk'$3*$4>500{print$0}'file

RelationalOperators

Operator Meaning Example

< Lessthan x<y

<= Less thanorequal x<=y

== Equalto x==y

!= Notequalto x!=y

> Greaterthan x>y

>= Greaterthanorequalto x>=y

~ Matchedbyreg exp x~/y/

!~ Notmatched byreq exp x!~/y/

LogicalOperators

Operator Meaning Example

&& Logical AND a&&b

|| LogicalOR a||b
J.B.INSTITUTEOFENGINEERINGAND
TECHNOLOGY

! NOT !a

Examples:

%awk'($2>5)&&($2<=15) {print$0}'file

%awk'$3==100||$4>50'file

RangePatterns

Matchesrangesofconsecutiveinputlines

Syntax:
pattern1,pattern2 {action}
patterncanbeanysimple
 pattern
pattern1
 turnsactionon
pattern2
 turnsactionoff

RangePatternExample
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

awkActions

awk expressions
Expressionisevaluatedandreturns
 value

consistsofanycombinationofnumericandstring constants,variables,operators, functions, and regular expressions
Caninvolve
 variables

Aspartofexpressionevaluation

Astargetof assignment

awk variables
Ausercandefine anynumberofvariableswithinanawk
 script
Thevariablescanbenumbers,strings,or
 arrays
Variablenamesstart withaletter,followedbyletters,digits,and
 underscore
Variables comeintoexistence thefirst time they are referenced; therefore, they donot need to be

declared before use

Allvariablesareinitiallycreatedasstringsandinitializedtoanullstring
 “”
J.B.INSTITUTEOFENGINEERINGAND
TECHNOLOGY
LinuxProgrammingNotes

awkVaria
bles
Format:
variable=expression

Examples:

%awk'$1~/Tom/

{wage=$3*$4;printwage}' filename

%awk'$4=="CA" {$4="California"; print $0}' filename

awkassignmentoperators

= assignresultofright-hand-sideexpressionto left-hand-side
variable
++ Add 1 to variable

-- Subtract 1fromvariable

+= Assignresultofaddition

-= Assignresultofsubtraction

*= Assignresultofmultiplication

/= Assignresultofdivision

%= Assignresultofmodulo

^= Assignresultofexponentiation
Awk example
J.B.INSTITUTEOFENGINEERING
ANDTECHNOLOGY
 File:grades

john85927894 88

andrea8990759086

jasper84 88 80 92 84

awkscript:
 average

#averagefive grades

{total=$2+$3+$4+$5+

$6avg=total/5 print $1, avg }



Run as:
awk–faverage grades

OutputStatements

print

printeasyandsimple output

printf

printformatted(similar toCprintf)

sprintf

formatstring(similartoC sprintf)
Function: print
J.B.INSTITUTEOFENGINEERING
ANDTECHNOLOGY
 Writestostandardoutput
Outputisterminatedby
 ORS

defaultORSis newline
Ifcalledwithnoparameter,itwillprint
 $0
Printedparametersareseparatedby
 OFS,

default OFSisblank
Printcontrolcharactersare
 allowed:

\n\f \a\t\\…

printexample

%awk'{print}'grades john 85
92 78 94 88
andrea8990759086

%awk '{print $0}'


gradesjohn85927894
88 andrea8990759086

%awk '{print($0)}'
gradesjohn8592789488
andrea8990 759086

Redirectingprint output


Print outputgoestostandardoutput
unlessredirectedvia:

>“file”
J.B.INSTITUTEOFENGINEERINGAND
TECHNOLOGY
LinuxProgrammingNotes

>> “file”

|“command”
willopen fileor command only
 once
subsequentredirectionsappendtoalreadyopen
 stream

print Example

%awk'{print$1,$2 >"file"}'grades

%catfile

john85

andrea89

jasper84

%awk '{print $1,$2 |


"sort"}'grades andrea 89
jasper84

john85

%awk'{print$1,$2|"sort–k2"}'grades jasper 84
john85

andrea89

%date
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Wed Nov 1914:40:07CST

2008%date|

awk'{print"Month:"$2 "\nYear:",

$6}'Mo0nth:Nov Year:
2008
printf:Formattingoutput
Syntax:
printf(format-string,var1,var2,…)

workslikeC printf

each formatspecifierin“format-string”requiresargumentofmatchingtype

Formatspecifiers

%d%i decimal integer

%c singlecharacter

%s string ofcharacters

%f floatingpointnumber

%o octalnumber

%x hexadecimalnumber

%e scientificfloatingpointnotation
J.B.INSTITUTEOFENGINEERINGAND
TECHNOLOGY

%% the letter “%”


Formatspecifierexamples
Formatspecifier modifiers
between“%”and
 letter

%10s

%7d

%10.4f

%-20s

meaning:


widthoffield,fieldisprintedrightjustified

precision:numberofdigitsafterdecimalpoint

“-”willleftjustify

sprintf:Formattingtext Syntax:
sprintf(format-string,var1,var2,…)

Workslikeprintf,butdoesnotproduce output

Insteaditreturnsformattedstring

Example:

text=sprintf("1: %d– 2:%d",$1,$2)


J.B.INSTITUTEOFENGINEERING
ANDTECHNOLOGY

print text

awkArray

awk
 allows one-dimensional arrays to
store strings or numbers
indexcanbenumberor
 string
arrayneednotbe
 declared

itssize

itselements
arrayelementsarecreatedwhenfirst
 used

initializedto0or“”

Arraysinawk Syntax:
arrayName[index]= value

Examples:

list[1] = "one" list[2]="three"


list["other"]="ohmy!"

Illustration:AssociativeArrays

awkarrays canusestringas
 index
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Awkbuiltinsplitfunctions
split(string, array, fieldsep)

dividesstringintopiecesseparatedbyfieldsep,andstoresthepiecesinarray

ifthefieldsepisomitted, thevalueofFSisused.

Example:

split("auto-da-fe",a,"-")

setsthecontentsofthearrayaasfollows:
 a[1] = "auto"
a[2]= "da"

a[3]= "fe"

Example:processsales data

input
 file:
J.B.INSTITUTEOFENGINEERING
ANDTECHNOLOGY

output:


summaryofcategorysales

Illustration:processeachinputlin
e
J.B.INSTITUTEOFENGINEERING
ANDTECHNOLOGY

Illustration:processeachinputline

Summary:awkprogram

Example:completeprogram

%catsales.awk

deptSales[$2]+=$3

END{

for(xindeptSales)
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

printx,deptSales[x]

%awk–fsales.awksales awk
builtin functions tolower(string)
returnsacopyofstring,witheachupper-casecharacterconvertedtolower- case. Nonalphabetic

characters are left unchanged.

Example:tolower("MiXeDcAsE

123")returns"mixedcase123"

toupper(string)

returnsacopyofstring, witheachlower-casecharacter convertedtoupper-case. awk



Example: list of products

103:sway bar:49.99
101:propeller:104.99 104:fishing
line:0.99
113:premiumfishbait:1.00
106:cup holder:2.49
107:cooler:14.89
112:boatcover:120.00
J.B.INSTITUTEOFENGINEERINGAND
TECHNOLOGY

109:transom:199.00
110:pulley:9.88
105:mirror:4.99
108:wheel:49.99
111:lock:31.00
102:trailerhitch:97.95 awk
Example: output Marine
Parts R Us Main catalog
Part-idname price

======================================

101 propeller 104.99

102 trailerhitch 97.95

103 swaybar 49.99

104 fishingline 0.99

105 mirror 4.99

106 cupholder 2.49

107 cooler 14.89

108 wheel 49.99


J.B.INSTITUTEOFENGINEERINGAND
TECHNOLOGY

109 transom 199.00

110 pulley 9.88

111 lock 31.00

112 boatcover 120.00

113 premiumfishbait 1.00

======================================

Catalog has 13 parts


awkExample:complete
BEGIN {
FS=":"

print"MarinePartsRUs" print "Main


catalog"
print"Part-id\tname\t\t\tprice"

print"======================================"

printf("%3d\t%-20s\t%6.2f\n",$1,$2,$3) count++
}
J.B.INSTITUTEOFENGINEERINGAND
TECHNOLOGY

END{

print"======================================"

print"Cataloghas"count" parts"

Applications:

Awkcontrolstructures
Conditional


if-else
Repetition


for

withcounter

witharrayindex

while

do-while

also:break, continue

ifStatement
Syntax:
if(conditionalexpression)
statement-1
else

statement-2

Example:
J.B.INSTITUTEOFENGINEERING
ANDTECHNOLOGY

if( NR<3 )

print$2

else

print$3 for
Loop Syntax:
for(initialization;limit-test; update)
statement
Example:

for(i=1;i<=NR;i++)

total+=$i count++
}

forLoopforarrays Syntax:
for(varinarray) statement
J.B.INSTITUTEOFENGINEERING
ANDTECHNOLOGY

Example:
for(xindeptSales)

printx,deptSales[x]

WhileLoop
Syntax:
while(logicalexpression) statement
Example:

i=1

while(i <=NF)

printi,$i i++
}

do-whileLoop
Syntax:
do

statement
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

while(condition)


statementisexecutedatleastonce, evenifconditionisfalseatthebeginning
Example:

i=1 do{
print$0 i++
}while(i <=10)

loopcontrolstatements

break

exitsloop

continue

skipsrestofcurrentiteration,continueswithnextiteration

ShellProgramming

The shell has similarities to the DOS command processor Command.com (actually Dos was
designasapoorcopyofUNIXshell), it'sactuallymuchmorepowerful,reallyaprogramming language in its own
right.

A shell is always available on even the most basic UNIX installation. You have to go through theshellto
getotherprogramstorun. Youcanwriteprogramsusingtheshell. Youusetheshell to administrate your UNIX
system. For example:

ls-al|more
isashortshellprogramtoget along listingofthepresent directoryandroutetheoutput through the more
command.
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Whatis aShell?

Ashell isaprogramthat actsasthe interfacebetweenyouandtheUNIXsystem, allowing you to enter


commands for the operating system to execute.

Herearesomecommonshells.

Introduction- WorkingwithBourneShell

• The Bourne shell, or sh, was the default Unix shell of Unix Version 7. It wasdeveloped by Stephen
Bourne, of AT&T Bell Laboratories.
• A Unix shell, also called "the command line", provides the traditional user interfacefor the Unix
operating systemand for Unix-like systems. Users direct the operation of the computer by entering
command input as text for a shell to execute.
• Therearemanydifferentshells inuse.Theyare
– Bourneshell(sh)
– Cshell(csh)
– Kornshell(ksh)
Bourne Again shell (bash)

111
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

• When we issue a command the shell is the first agency to acquire the information.
Itacceptsandinterpretsuserrequests.Theshellexamines&rebuildsthecommands &leaves the
execution work to kernel. The kernel handles the h/w on behalf of these commands &all processes
in the system.
• Theshellisgenerallysleeping.Itwakesupwhenaninputiskeyedinattheprompt. This input is actually input to
the program that represents the shell.

Shellresponsibilities
1. ProgramExecution
2. VariableandFilenameSubstitution
3. I/ORedirection
4. PipelineHookup
5. EnvironmentControl
6. Interpreted Programming
Language 1.Program Execution:
• Theshellisresponsiblefortheexecutionofallprogramsthatyourequestfrom your terminal.
• Eachtimeyoutypeinalinetotheshell,theshellanalyzesthelineandthen determines what to do.
• The line that is typed to the shell is known more formally as the command line. The
shellscansthiscommand lineanddeterminesthenameoftheprogramto beexecuted and what arguments
to pass to the program.
2. VariableandFilenameSubstitution:
• Likeanyotherprogramminglanguage,theshellletsyouassignvaluestovariables. Whenever you
specifyone of these variables on the command line, preceded by a dollar sign, the shell substitutes
the value assigned to the variable at that point.
3. I/O Redirection:
• It is the shell's responsibility to take care of input and output redirection on thecommand line. It scans the
command line for the occurrence of the special redirection characters <, >, or >>.
4. PipelineHookup:
• Just astheshellscansthecommandlinelookingforredirectioncharacters,it alsolooks for the pipe character
|. For each such character that it finds, it connects the standard output fromthecommand preceding
the| tothestandard input oftheone following the
|.Ittheninitiatesexecutionofbothprograms.

5. EnvironmentControl:

• The shell provides certain commands that let you customize your environment. Your
environmentincludes homedirectory,thecharacters thattheshelldisplaystopromptyou

112
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

totype inacommand,anda list ofthedirectoriestobesearchedwhenever you request that a


program be executed.

6. InterpretedProgrammingLanguage:

• The shell has its own built-in programming language. This language is interpreted, meaning that the shell
analyzes each statement in the language one line at a time and
thenexecutesit.Thisdiffersfromprogramming languagessuchasCandFORTRAN, in which the programming
statements are typically compiled into a machine-executable form before they are executed.
• Programsdeveloped in interpreted programming languagesare typicallyeasier to debug and modify than
compiled ones. However, they usually take much longer to executethan their compiled equivalents.

PipesandRedirection
Pipesconnectprocessestogether.TheinputandoutputofUNIXprogramscanbe redirected.

Redirecting Output
The>operatorisusedtoredirectoutputofaprogram.For example: ls -l > lsoutput.txt
redirectstheoutputofthelistcommandfromthescreentothefilelsoutput.txt.
To0appendtoafile,usethe>> operator.

ps>>lsoutput.txt

Redirecting Input
Youredirect inputbyusingthe<operator.Forexample: more < killout.txt
Pipes
Wecanconnectprocessestogetherusingthepipe operator( |).Forexample,the following
program means run the ps program, sort its output, and save it in the file pssort.out

ps|sort>pssort.out
Thesort commandwillsortthe listofwordsinatextfile into alphbeticalorderaccordingtothe ASCII code
set character order.

HereDocuments

113
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Aheredocument isaspecialwayofpassing inputtoacommand froma shellscript. The document


starts and ends with the same leader after <<. For example:
#!/bin/sh

cat < this is a heredocument


!FUNKY!

How ItWorks
Itexecutestheheredocumentasifitwereinputcommands.

Running aShellScript
You cantype inasequenceofcommandsand allowtheshellto executetheminteractively, or youu can sotre
these commands in a file which you can invoke as a program.

InteractivePrograms

A quick wayof trying out small code fragments is to just type in the shell script onthe command
line.Here isashellprogramto compileonlyfilesthat containthestringPOSIX.

TheShellasaProgrammingLanguage Creating a
Script
Tocreateashellscript first useatexteditorto createafilecontainingthecommands.For example, type the
following commands and save them as first.sh

114
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Note:commandsstartwitha#.

Theline

#!/bin/sh
isspecialandtellsthesystemtousethe/bin/shprogramtoexecutethisprogram.

Thecommand

exit0
Causesthescriptprogramtoexitandreturnavalueof0,whichmeanstherewerenot errors.

MakingaScriptExecutable
Therearetwowaysto executethescript.1) invoketheshellwiththenameofthescript fileas a parameter,
thus:

/bin/sh first.sh
Or2)changethe modeofthescript toexecutableandthenafterexecuteit byjust typing its name.
chmod +x first.shfirst.sh
Actually,youmayneedtotype:
./first.sh
tomakethefileexecuteunlesthepathvariablehasyour directoryinit.

ShellSyntax
The modernUNIXshellcanbeusedtowritequitelarge,structuredprograms.

Shellmetacharacters

115
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Theshellconsistsoflarge no.ofmetacharacters.Thesecharactersplaysvitalrole in Unix


programming.

Typesofmetacharacters:

1. Filesubstitution

2. I/Oredirection

3. Processexecution

4. Quotingmetacharacter
s 5.Positional parameters
6. Specialcharacters

7. Commandsubstitution

Filenamesubstitution:
Thesemetacharactersareusedtomatchthefilenamesinadirectory.
Metacharacter significance
* matchesanyno.ofcharacters

? matchesasinglecharacter

[ijk] matchesasinglecharactereitheri,j,k

[!ijk] matchesasinglecharacterthatisnotanI,j,k

ShellVariables

Variablesaregenerallycreatedwhenyou first usethem.Bydefault,allvariablesare considered and


stored as strings. Variable names are case sensitive.

116
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes


Ucandefine&usevariablesbothinthecommandlineandshellscripts.These variables are called shell variables.

Notypedeclarationisnecessarybeforeucanuseashellvariable.

Variablesprovidetheabilitytostoreandmanipulatetheinformationwithinthe shell program. The variables are
completely under the control of user.

VariablesinUnixare oftwotypes.

1) User-definedvariables:

Generalizedform:
variable=value. Eg: $x=10
$echo$x

10


To remove a variable
use unset. $unset x


Allshellvariablesareinitializedtonullstringsbydefault.Toexplicitlysetnullvaluesuse

x= orx=‘’ or x=“”

Toassignmultiwordstringstoavariableuse
$msg=‘uhaveamail’

117
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

2) EnvironmentVariables


They areinitialized when the shell script starts and normally capitalized todistinguish them from
user-defined variables in scripts

Todisplayallvariablesinthelocalshellandtheir values,typethesetcommand

Theunsetcommandremovesthevariablefromthe currentshellandsubshell

EnvironmentVariables Description

$HOME Home directory


$PATH Listofdirectoriestosearchforcommands

$PS1 Commandprompt
$PS2 Secondaryprompt

$SHELL Currentloginshell
$0 Nameoftheshellscript

$# No.ofparameterspassed

$$ ProcessIDoftheshellscript

CommandsubstitutionandShellcommands:
read:

Thereadstatementisatoolfortakinginputfromtheuseri.e.making
scriptsinteractive.Itisusedwithoneormorevariables.Inputsupplied
throughthestandardinputisreadintothesevariables.
$readname

Whateveruenteredisstoredinthevariable name.
printf:
Printfisused to print formatted
o/p.printf"format"arg1arg2... Eg:
$printf"Thisisanumber: %d\n"10

118
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

This isanumber:10

Printfsupportsconversionspecificationcharacterslike%d,%s,%x

,%o….Exitstatusofa command:
Everycommandreturnsa valueafter execution.Thisvalueiscalledtheexitstatus or
return value of a command.
This value is said to be true if the command executes successfully and false if it fails.
There is special parameter used by the shell it is the $?. It stores the exit status
ofacommand.
exit:

Theexit statement isusedtoprematurelyterminateaprogram.Whenthisstatement is


encountered in a script, execution is halted and control is returned to the calling
program-inmostcasestheshell.

U don’t need to place exit at the end of every shell script becausetheshell knows when script
execution is complete.
set:
Setisusedtoproducethelistofcurrentlydefinedvariables.
$set

Setisusedtoassignvaluestothepositionalparameters.
$setwelcometoUnix
Thedo-nothing(:)Command It
is a null command.
Insomeolder shellscripts,colonwasusedat thestartofalinetointroducea
comment,butmodernscripts uses#now.
expr:
Theexprcommandevaluatesitsargumentsasanexpression:
$expr8+6

14

$x=`expr12 /4`
$echo $x
 3

export:

119
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes
There isawaytomakethe value ofa variable knowntoasubshell, andthat's
byexporting it with the export command. The format of this command is
exportvariables

wherevariablesisthelistofvariablenamesthatyouwantexported.Foranysub
shellsthatgetexecutedfromthatpointon,thevalueoftheexportedvariableswill
bepasseddowntothe subshell.

eval:

evalscansthecommandlinetwicebeforeexecutingit. Generalformfor eval

isevalcommand-line Eg:
$catlast

evalecho\$$#

$lastonetwothreefour four
${n}

Ifusupplymorethannineargumentsto aprogram, ucannotaccessthetenthand greater arguments


with $10, $11, and so on.
${n}mustbeused.Soto directlyaccessargument10,youmustwrite

${10}

Shiftcommand:

Theshift commandallowsutoeffectivelyleft shiftyourpositionalparameters.Ifu execute the


command

Shift

whatever was previously stored inside $2 will be assigned to $1, whatever was previously
storedin$3willbeassignedto $2, andsoon. Theoldvalueof$1willbe irretrievablylost.

TheEnvironment-EnvironmentVariables
Itcreatesthevariablesalutation,displaysitsvalue,andsomeparameter variables.

120
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

• Whenashellstarts,somevariablesareinitializedfromvaluesinthe environment. Here is a sample of


some of them.

ParameterVariables
• Ifyourscriptis invokedwithparameters, someadditionalvariablesarecreated.

Quoting

Normally,parametersareseparatedbywhitespace,suchasaspace.Singlequot markscan beused to


enclose valuescontaining space(s). Typethefollowing into afilecalled quot.sh

makesuretomakeitexecutablebytypingthecommand:

< chmod a+x


quot.shTheresultsofexecuting

121
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

thefileis:

How ItWorks

Thevariable myvar iscreatedandassignedthe stringHithere.Thecontentofthevariable is displyed using


the echo $. Double quotes don't effect echoing the value. Single quotes and backslash do.

Thetest,or[]Command

Here ishowtocheck fortheexistanceofthe file fred.cusingthetest andusingthe [] command.


Youcanevenplacethethenonthesame lineasthe if, ifyouuaddasemicolonbefore the word then.

Herearetheconditontypesthat canbeusedwiththetest command.Therearestring comparison.

Therearearithmeticcomparison.

122
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Therearefileconditions.

ControlStructures
The shellhasasetofcontrolstructures.

if
tatementisvarysimilarotherprogramminglanguagesexcept itendswithafi. if condition
then
statements
else fi statements
elif

theelifis betterknownas"else if". Itreplacestheelsepartofanifstatement withanother if statement.


You can try it out by using the following script.

123
J.B.INSTITUTE OF
ENGINEERINGAND
TECHNOLOGY

LinuxProgrammingNotes
#!/bin/sh

echo"Isitmorning?Pleaseansweryesor no" read timeofday


if[$ti0meofday="yes"
]then
echo "Good morning"
elif[$timeofday="no"];then
echo"Goodafternoon"

124
J.B.INSTITUTEOFENGINEERING
ANDTECHNOLOGY
LinuxProgrammingNotes
else

125
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

o"Sorry,$timeofdaynotrecognized.Enteryesorno"exit 1 fi
exit0

How ItWorks
Theabovedoesasecondtestonthevariabletimeofdayifitisn'tequaltoyes.

AProblemwithVariables
Ifavariableissettonull, the statement

if[$timeofday="yes"]
lookslike if[="yes"]
sillegal.Thisproblemcanbe fixed byusingdoublequotesaroundthevariablename. if [ "$timeofday" = "yes" ]
.

for

The forconstruct isused forloopingthrougharangeofvalues, whichcanbe anysetof strings. The syntax is:

forvariableinvalues do
statements
done
Tryoutthefollowingscript:
#!/bin/sh

forfooinbarfud43 do
echo$foo
done exit0
Whenexecuted,the outputshould
be:bar fud0 43

How ItWorks

Theaboveexamplecreatesthevariable fooandassignsit adifferent valueeachtimearound the for loop.

126
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

How ItWorks

Hereisanotherscript whichusesthe$(command)syntaxtoexpandalistto chap3.txt, chap4.txt, and


chap5.txt and print the files.
#!/bin/sh

forfilein$(lschap[345].txt); do lpr $file


done0

while
While loops will loop as long as some condition exist. OF course something in the body
statementsoftheloopshouldeventuallychange theconditionandcausethe loopto exit. Here is the while
loop syntax.

whileconditiondo
statements
done
Hereisawhilloopthat loops20
times.#!/bin/sh foo=1
while[ "$foo"-le20
]do
echo"Herewegoagain"foo=
done exit0 $(($foo+1))

How ItWorks
ovescript usesthe[]commandtotestfoofor<=thevalue20.Theline foo=$(($fo0o+1))
incrementsthevalueoffooeachtimetheloop executes..

until
Theuntilstatementloopsuntilaconditionbecomestrue!Itssyntax is:

127
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

until conditiondo
statements
done
Hereisascriptusinguntil.
#!/bin/sh

untilwho|grep"$1">/dev/null do
Sl0eep 60
done
#nowringthebellandannouncetheexpecteduser. echo -e \\a
echo"****$1hasjustlooggedin****"

exit0

case
Thecasestatement allowsthetestingofavariable for morethenonevalue.Thecase statement
ends with the word esac. Its syntax is:

casevariablein
pattern[|pattern]...)statements;; pattern[|pattern]...) statements;;
...
esac
Here isasamplescriptusingacasestatement:
#!/bin/sh

echo"Isitmorning?Pleaseansweryesor no" read timeofday

case"$timeofday"in
"yes") echo "Good Morning";; "no")echo"GoodAfternoon";;
0"y" ) echo "Good Morning";; "n" ) echo "Good Afternoon";;
*)echo "Soory,answernot recognized";;
esac exit0

128
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Thevalue inthe varaibletimeofdayiscomparedtovariousstrings. Whena matchismade,the associated echo


command is executed.
sacasewhere multiplestringsaretestedatatime,to dothesomeaction. case "$timeofday" in
"yes"|"y"|"yes"|"YES")echo"goodMorning";; "n"* | "N"* ) <echo "Good
Afternoon";;
*) <echo"Sorry, answer notrecognized";;
0esac

How ItWorks
Theabovehassever stringstestedfor eachpossiblestatement.
acasestatementthatexecutesmultiplestatementsforeachcase. case "$timeofday" in
"yes" | "y" | "Yes" | "YES" ) echo"GoodMorning"
echo"Upbrightandearlythis morning"
;;
[nN]*) echo"Good Afternoon"
;;
*)
echo "Sorry, answer not
recognized"echo"Pleaseanswer yes
or noo" exit 1
;;

esac

How ItWorks

Whena matchis foundtothevariable valueoftimeofday, allthe statementsuptothe;; are executed.

Arithmeticinshell

The$((...))isabetteralternativetotheexprcommand,whichallowssimplearithmetic commands to be
processed.

x=$(($x+1))

ParameterExpansion

129
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

}aroundavariabletoprotectitagainstexpansion. #!/bin/sh
foriin12 do
my_secret_process${i}_tmp
done
Herearesomeoftheparameterexpansion

How ItWorks
Thetryit outexerciseusesparameter expansiontodemonstratehowparameterexpansionworks.

ShellScriptExamples Example
#!/bin/sh

echo"Isitmorning?(Answeryesor no)" read


timeofday
if[$timeofday= "yes"];then
echo"GoodMorning"
else

echo"Good afternoon"

fi

130
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

exit0

elif-DoingfurtherChecks
#!/bin/sh

echo"Isitmorning?Pleaseansweryesorno" read
timeofday
if[$timeofday="yes"];then echo"Good
Morning"
elif[$timeofday="no"];then echo"Good
afternoon"
else echo"Wronganswer!Enteryesorno" exit 1
fi exit0

InterruptProcessing-trap
pcommand isused forsecifyingtheactionstotakeonreceipt ofsignals.It syntaxis: trap command signal
Hereare some ofthe signals.

How ItWorks
Thetryit outsectionhas youtype inashellscript totestthetrapcommand. Itcreatesafile and keeps saying
that it exists until youu cause a control-C interrupt. It does it allagain.

131
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Functions
ndefinefunctionsintheshell.Thesyntaxis: function_name () {
statements
}0
Hereisasamplefunctionanditsexecution.
#!/bin/sh
foo() {
echo"Functionfoo isexecuting"
}

echo "script starting"foo


echo"scriptended" exit 0
How ItWorks
Whentheabovescript runs, it definesthefuncionfoo,thenscript echosscript starting,then it runs the
functions foo which echos Function foo is executing, then it echo script ended.

anothersamplescriptwithafunctioninit.Saveitasmy_name #!/bin/sh
yes_or_no(){
echo"Parameters are
$*"whiletrue do
echo-n"Enteryesor no" read x
0case"$x"in
y|yes)return0;; n|no)return1;;
*)echo"Answeryesorno"
esac
done
}
echo"Originalparametersare$*"

132
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

ifyes_or_no"ISyournaem$1"then
else fi echo"Hi$1"
0exit0 echo"Nevermind"

How ItWorks
Whenmy_nameisexecutewiththestatement:

my_nameRickandNeil
.givestheoutputof:
OriginalparametersareRickandNeil Parameters are Is your
name Rick Enter yes or no
no
Never mind

Commands

Youcanexecutenormalcommandandbuilt-incommands fromashellscript. Built- in commands


are defined and only run inside of the script.

break

Itisusedtoescape fromanenclosing for,whileoruntilloopbeforethecontrollingcondition has been met.

The:Command
Thecoloncommandisanullcommand.Itcanbeusedforanaliasfortrue..

Continue

Thecontinuecommand makestheenclosing for,while,oruntilloopcontinueatthenext iteration.

TheCommand
Thedotcommandexecutesthecommandinthecurrentshell:

.shell_script
.

133
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

echo

Theecho commandsimplyoutputsastringtothestandardoutput device followed bya newline character.

Eval
Theevalcommand evaluatesargumentsand givesthe results.

exec

Theexeccommandcanreplacethecurrent shellwithadifferent program.It canalso modifythe current file


descriptors.

exitn

Theexit commandcausesthescriptto exit withexit coden.Anexit codeof0 meanssuccess. Here are some
other codes.

export
Theexportcommandmakesthevariablenamedas itsparameteravailableinsubshells.

expr
Theexprcommandevaluatesitsargumentsasanexpression.

0x= `expr$x+ 1`
Herearesomeofitsexpressionevaluations

134
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

printf
Theprintfcommand isonlyavailable inmorerecent shells.Itworkssimilartothe echo command. Its
general form is:

printf"formatstring"parameter1parameter2...
Herearesomecharactersandformatspecifiers.

return
Thereturncommandcauses functionstoreturn. Itcanhaveavalueparameterwhichitreturns.

set

135
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Thesetcommandsetstheparametervariables fortheshell.

shift

Theshift command movesalltheparametersvariablesdownbyone,so $2becomes$1,$3 becomes $2, and


so on.

unset
Theunsetcommandremovesvariablesorfunctionsfromtheenvironment.

CommandExecution
Theresult of$(command) issimplytheoutputstring fromthecommand,whichisthen available to the
script.

DebuggingShellScripts

Whenanerroroccursinascript,theshellprintsoutthe linenumber withanerror. Youcan use the set


command to set various shelloption. Here are some of them.

136
J.B.INSTITUTEOFENGINEERINGAND
TECHNOLOGY
LinuxProgrammingNotes

UNIT-II:
FilesandDirectoriesFileConcept

Filetypes
FileSystemStructure File
metadata
Inodes
kernelsupportfor files
ystem calls for file I/O operations
open,create,read,write,close,
lseek,dup2filestatusinformation-statfamily
fileandrecordlocking-fcntlfunction file
permission- chmod, fchmod
e ownership- chown, lchown,fchown links-
softlinks&hardlinks-
Symlink,Link,ulink 2.11Directories creating-
mkdir, removing - rmdir
changing directories -chdir
obtainingcurrentworkingdirectory-getcwd
scanningdirectories-opendir,readdir,closedir,rewinddirfunctions
.

137
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes
UnitII
FilesandDirectories

WorkingwithFiles
Inthischapter welearnhowtocreate,open,read,write,andclosefiles.

UNIXFile Structure
InUNIX, everythingis afile.

Programscanusedisk files,serialports,printersandotherdevicesintheexactlythesameway as they would use


a file.

Directories,too,arespecialsortsof files.

File types
MostfilesonaUNIXsystemareregular filesordirectories, butthereareadditionaltypesof files:
1. Regular files:The most commontypeoffile,whichcontainsdataofsome form.There is no distinction to the
UNIX kernel whether this data is text or binary.
2. Directory file: A file contains the names of other files and pointers to information on these
files.Anyprocessthat hasreadpermissionforadirectoryfilecanreadthecontents of the directory, but only the
kernel can write to a directory file.
3. Characterspecialfile:Atype offile usedforcertaintypesofdevicesona system.
4. Block special file: Atype of file typicallyused for disk devices. All devices on a system are either character
special files or block special files.
5. FIFO:Atypeoffileusedforinterprocesscommunicationbetweenprocesses.It’ssometimes called a named pipe.
6. Socket: Atype offile used for network communicationbetweenprocesses. Asocket can also be used for
nonnetwork communication between processes on a single host.
7. Symbolic link:Atypeoffilethatpointstoanother file.

Theargumenttoeachofdifferentfiletypes isdefinedas follows_

138
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Macro Typeoffile

S_ISREG() Regular file

S_ISDIR() Directoryfile

S_ISCHR() Characterspecialfile

S_ISBLK() Blockspecialfile

S_ISFIFO() PipeorFIFO

S_ISLNK() Symboliclink

S_ISSOCK() Socket

FileSystemStructure
Filesarearrangedindirectories, whichalsocontainsubdirectories.

Auser,neil,usuallyhas his filesstoresina'home'directory,perhaps/home/neil.

Filesand Devices

139
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Evenhardwaredevicesarerepresented(mapped) byfilesinUNIX.Forexample,as root, you mount a CD-ROM


drive as a file,

$mount-tiso9660/dev/hdc
/mnt/cd_rom$cd/mnt/cd_rom
/dev/console-thisdevicerepresentsthesystemconsole.
/dev/tty-Thisspecialfile isanalias(logicaldevice)forcontrollingterminal(keyboard and screen, or
window) of a process.
/dev/null-Thisisthenulldevice.Alloutputwrittentothisdeviceis discarded.

FileMetadata Inodes
• Astructurethatismaintainedina separateareaoftheharddisk.
• Fileattributesarestored intheinode.
• Everyfileisassociatedwithatablecalledtheinode.
• Theinodeisaccessedbytheinode number.
• Inodecontainsthefollowingattributesofa file: file type, file
permissions , no. of links
UID of the owner, GID of the group owner, file size dateandtimeoflast
modification,lastaccess,change.
File attributes
Attribute valuemeaning
Filetype typeofthe file
Accesspermission fileaccesspermissionforowner,groupandothers
Hardlinkcount no.ofhardlinksofa file.
UID fileowneruserID.
GID thefile groupID.
Filesize filesizeinbytes.
Inodenumber systeminodenumber ofthefile.
FilesystemIDfilesystemIDwherethefileis stored.
KernelSupport ForFiles:

140
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

UNIX supports the sharing of open files between different processes. Kernel has three data structures are
used and the relationship among them determines the effect one process has on another with regard to file
sharing.
1. Everyprocess has an entry in the process table. Within each process table entry is a table
ofopenfiledescriptors,whichistakenasavector,withoneentryperdescriptor.
Associatedwitheach filedescriptorare
a. Thefiledescriptor flags.
b. Apointer toafiletableentry.
2. Thekernelmaintainsafiletablefor allopenfiles.Eachfiletableentrycontains
a. Thefilestatusflagsforthefile(read,write,append,sync,nonblocking,etc.),
b. Thecurrentfileoffset,
c. Apointertothe v-node table entryforthe file.
3. Each open file (or device) has a v-node structure. The v-node contains information about the type of file
and pointers to functions that operate onthe file. For mostfiles the v-nodealso containsthe i-nodeforthe
file. This informationisread fromdiskwhenthe file is opened, so that allthe pertinent information about the
file is readilyavailable.
The arrangement of these three tables for a single process that has two differentfiles open one file is open
on standard input(file descriptor 0) and the other is open standard output(file descriptor 1).
Here, the first process has the file open descriptor 3 and the second process has file open descriptor 4. Each
process that opens the file gets its own file table entry, but only a single v- node table entry. One reason
each process gets itsownfile table entry is so that each process has its own current offset for the file.
After each‘write’ is complete, the current file offset inthe file table entryis incremented by the number of

bytes written. If this causes the current file offset to exceed the current file size, the current file size, in the

i-node table the entry is to the current file offset(Ex: file is extended).

Ifa file is opened withO_APPEND flag, acorresponding flag is set in the filestatus flags of the file table entry.

Each time a ‘write’ is performed for a file with this append flag

141
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

set,thecurrentfileoffset inthe filetableentryisfirstsettothecurrent filesize fromthe i-node table


entry. This forces every ‘write’ to be appended to the current end of file.
The‘lseek’functiononlymodifiesthecurrentoffsetinthefiletableentry.NoI/O table place.

If afileis positioned to its currentendof file usinglseek, all that happensis thecurrent file offset in the file

table entry is set to the current file size from the i-node table entry.

It is possible for more than a descriptor entry to point to the same file table only. The file descriptor
flag is linked with a single descriptor in a single process, while file status flags are descriptors in any
process that point to given file table entry.

SystemCallsandDeviceDrivers
Systemcallsareprovided byUNIXtoaccessandcontrolfilesanddevices. A
number of device drivers are part of the kernel.
Thesystemcallstoaccessthe devicedriversinclude:

LibraryFunctions

Toprovideahigher levelinterfacetodevice anddiskfiles,UNIIXprovidesanumber of


standard libraries.

142
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Low-levelFile Access

Eachrunningprogram,calleda process,hasassociatedwithit anumber offiledescriptors. When a


programstarts, it usually has three ofthese descriptors alreadyopened. These are:

Thewritesystemcallarranges forthe first nbytesbytes frombufto bewrittentothefile associated with


the file descriptor fildes.

Withthisknowledge,let'swriteourfirstprogram,simple_write.c:

143
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Hereishowto runtheprogramanditsoutput.

$ simple_write Hereissomedata
$

read

Thereadsystemcallreadsupto nbytesofdatafromthe fileassociatedwiththe file decriptor fildes


and places them in the data area buf.

Thisprogram, simple_read.c,copiesthe first 128bytesofthestandardinput tothestandard output.

Ifyouruntheprogram,youshouldsee:

144
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

$ echo hello there | simple_readhellothere


$simple_read<draft1.txt Files

open
Tocreateanewfiledescriptor weneedtousetheopen systemcall.

openestablishesanaccesspathto afileordevice.

Thenameofthefileordevicetobeopened ispassedasaparameter, path, and the oflags


parameter is used to specify actions to be takenon opening the file.

TheoflagsarespecifiedasabitwiseORofa mandatoryfileaccess modeandother optionalmodes.


Theopencallmustspecifyoneofthefollowingfileaccess modes:

Thecallmayalso includeacombination(bitwise OR)ofthefollowingoptionalmodes in the oflags


parameter:

145
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

InitialPermissions

Whenwe create a file using the O_CREAT flag withopen, we must use the three parameter form. mode,
thethirdparameter, is made formabitwiseORofthe flagsdefined inthe header file sys/stat.h. These are:

Forexample

Hastheeffectofcreatinga filecalled myfile, withreadpermissionfortheownerandexecute permission for


others, and only those permissions.

umask

Theumaskisasystemvariablethat encodesamask forfilepermissionsto beusedwhena file is created.


Youcanchangethevariablebyexecutingtheumaskcommand tosupplyanewvalue.

Thevalueisathree-digitoctalvalue.EachdigitistheresultsofANDingvaluesfrom1,2,or4.

146
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Forexample, toblock'group'writeandexecute, and'other'write,theumaskwouldbe:

Valuesforeachdigit areANDedtogether;so digit 2willhave2&1,giving3.The resulting umask is


032.

close

147
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Weuseclosetoterminatetheassociationbetweenafiledescriptor,fildes, anditsfile.

ioctl

ioctlisa bit ofarag-bagofthings.Itprovidesaninterface forcontrollingthebehavior of devices, their


descriptors and configuring underlying services.
ioctlperformsthefunctionindicatedbycmd ontheobject referenced bythedescriptor fildes. Try It Out - A File
Copy Program
We nowknowenoughaboutthe open, readandwritesystemcallstowritealow-level program,
copy_system.c, to copy one file to another, character by character.

Runningthe programwillgive thefollowing:

148
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

WeusedtheUNIX timefacilitytomeasurehow longtheprogramtakestorun. Ittook2andone half minutes to


copy the 1Mb file.
Wecanimprovebycopyinginlargerblocks. Hereistheimprovedcopy_block.cprogram.

Nowtrytheprogram,firstremovingtheoldoutputfile:

149
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Therevised programtookundertwo secondsto dothe copy.

OtherSystemCalls forManagingFiles
Herearesome systemcallsthat operateontheselow-levelfile descriptors.

lseek

Thelseeksystemcallsetstheread/writepointerofafiledescriptor, fildes. Youuseittoset where in the file


the next read or write will occur.

Theoffsetparameter isusedto specifythepositionandthe whenceparameterspecifieshow the offset is


used.

whence canbe oneofthefollowing:

dup anddup2

Thedupsystemcallsprovideawayofduplicating afiledescriptor,givingtwoormore, different descriptors that access the


same file.

FileStatusInformation-StatFamily: fstat, statandlstat

150
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Thefstat systemcallreturnsstatusinformationaboutthe fileassociatedwithanopenfile descriptor.

The membersofthestructure,stat,mayvarybetweenUNIXsystems,butwillinclude:

Thepermissionsflagsarethesameasfortheopensystem callabove.File-type flagsinclude:

151
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Othermodeflagsinclude:

Maskstointerpretthe st_modeflags include:

Therearesomemacrosdefinedtohelpwithdeterminingfiletypes. Theseinclude:

Totestthatafiledoesn't represent adirectoryandhasexecutepermissonset fortheownerand no other


permissions, we can use the test:

152
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Fileandrecordlocking-fcntlfunction
• File locking isapplicableonlyforregular files.
• It allows a process to impose a lock on a file so that other processes cannot modifythe file until it is
unlocked by the process.
• Write lock: it prevents other processes from setting any overlapping read / write lockson the locked
region of a file.
• Readlock: itprevents other processesfrom setting any overlapping writelocks on the locked region of a
file.

• Writelock isalsocalledaexclusivelockandreadlock isalsocalledasharedlock.


• fcntlAPI canbeusedtoimposereador writelocksoneither asegmentor anentirefile.
• Functionprototype:

#include<fcntl.h>

intfcntl(intfdesc,intcmd_flag,….);

• Allfilelockssetbyaprocesswillbe unlocked whentheprocessterminates.

FilePermission-chmod

Youcanchangethepermissionsonafileordirectoryusingthe chmodsystemcall. Tis formsthe basis of the chmod


shell program.

chown

153
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Asuperusercanchangetheownerofafileusingthechownsystemcall.

Links-softlinkandhardlink
Softlink(symbolic links):Refertoasymbolicpathindicatingtheabstractlocationof another file.

Usedtoprovidealternative meansofreferencingfiles.

Usersmaycreatelinksforfilesusinglncommandbyspecifying–s option.
hardlinks:Refer to thespecificlocationofphysicaldata.

AhardlinkisaUNIXpathnamefor afile.

Most of the files have only one hardlink. However users may create additional hardlinksfor files using ln
command.
Limitations:

Userscannotcreatehardlinksfordirectoriesunlesstheyhavesuperuser privileges.

Userscannotcreatehardlinksonafilesystemthatreferencesfilesonadifferentsystems.

unlink,link,symlink
Wecanremoveafileusingunlink.

Theunlinksystemcalldecrementsthelinkcountonafile. The link


system call cretes a new link to an existing file.
Thesymlinkcreatesasymboliclinktoanexistingfile.

Directories

Aswellasitscontents,afile hasanameand'administrative information',i.e.the file's


creation/modification date and its permissions.

154
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Thepermissionsarestoredinthe inode,whichalsocontainsthe lengthofthe fileandwhere on the disc it's


stored.
Adirectoryisafilethatholdstheinodesandnamesofotherfiles.

mkdir, rmdir
Wecancreateandremovedirectoriesusingthemkdirandrmdirsystemcalls.

Themkdirsystemcallmakesa newdirectorywithpathasitsname.

Thermdirsystemcallremovesanemptydirectory.

chdir
Aprogramcannaviagate directoriesusingthechdirsystemcall.

CurrentWorkingDirectory-getcwd
Aprogramcandetermineitscurrentworkingdirectorybycalling thegetcwdlibraryfunction.

Thegetcwd functionwritesthenameofthecurrent directoryintothegivenbuffer,buf.

155
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

ScanningDirectories

Thedirectoryfunctionsaredeclared inaheaderfile, dirent.h.Theyuseastructure, DIR, asa basis for directory


manipulation.
Herearethesefunctions:

opendir
Theopendirfunctionopensadirectoryand establishesadirectorystream.

readdir

Thereaddirfunctionreturnsapointertoastructuredetailingthenext directoryentryinthe directory stream


dirp.

Thedirent structurecontainingdirectoryentrydetails includedthefollowingentries:

156
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

telldir

Thetelldirfunctionreturnsavaluethatrecordsthecurrentposition inadirectorystream.

seekdir

Theseekdirfunctionsetsthedirectoryentrypointerinthedirectorystreamgivenbydirp.

12.13.3closedir

Theclosedir functionclosesadirectorystreamand freesup theresourcesassociated with it.

TryItOut-ADirectory Scanning Program


1. Theprintdir, printsoutthecurrentdirectory.Itwillrecursefor subdirectories.

157
J.B.INSTITUTEOFENGINEERING
ANDTECHNOLOGY
LinuxProgrammingNotes

2. Nowwemoveontothemainfunction:

158
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Theprogramproducesoutput like this(edited forbrevity):

How ItWorks

After some initial error checking, using opendir, to see that the directoryexists, printdir makes a
call to chdir to the directoryspecified. While the entries returned by readdir aren't
null,theprogramcheckstoseewhethertheentryisadirectory.Ifit isn't,it printsthefileentry with
indentation depth.

159
J.B.INSTITUTEOFENGINEERING
ANDTECHNOLOGY

Hereisonewaytomaketheprogrammore general.

Youcanrunitusingthecommand:

$printdir /usr/local|more

160
J.B.INSTITUTEOFENGINEERING
ANDTECHNOLOGY
LinuxProgrammingNotes

UNIT-III
3. Process
ProcessconceptLayout of a C
program Image in main
memory
Processenvironment
Environment list
Environment variables- getenv,
setenvKernelsupportforprocess Process
identification
Processcontrol
ProcessCreation
ReplacingAProcessImage Waiting For A
Process
ProcessTermination Zombie
Process,
OrphanProcess
SystemCall InterfaceForProcess Management
Fork, vfork Exit Wait
Waitpid
ExecFamily Process
Groups
Sessions & Controlling Terminal
DifferencesBetweenThreads&Processes

161
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Signals–Introductiontosignals
Signalgeneration and handling Kernel
support for signals
nalfunction-UnreliableSignals,Reliablesignals kill, raise
alarm,pause
3.17.3abort

3.17.4sleepfunctions.

Unit 3 ProcessesandSignals
III.Processesand Signals

Processesandsignalsforma fundamentalpartoftheUNIXoperatingenvironment,controlling almost all


activities performed by a UNIX computer system.
Herearesomeofthethingsyou need to understand.

WhatisaProcess
TheX/OpenSpecificationdefinesaprocessasanaddressspaceandsinglethreadofcontrolthat executes within
that address space and its required system resources.

Aprocessis, essentially,arunning program.

162
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

LayoutofaCprogram
Here ishowacoupleofprocessesmightbearrangedwithintheoperationgsystem.

Eachprocess isallocatedauniquenumber, aprocessidentifier, or PID.

Theprogramcodethatwillbeexecutedbythe grepcommand isstoredinadisk file. The system


libraries can also be shared.
Aprocess hasitsownstackspace.

Imageinmain memory

TheUNIX processtable maybethoughofasadatastructuredescribingalloftheprocesses that are currently


loaded.

ViewingProcesses
Wecanseewhat processesarerunningbyusingthe pscommand. Here is some
sample output:

163
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

ThePIDcolumngivesthePIDs,the TTYcolumnshowswhichterminalstartedtheprocess, the STAT column


shows the current status, TIME gives the CPU time used so far and
theCOMMANDcolumnshowsthecommandusedto starttheprocess. Let's take a
closer look at some of these:

The initialloginwasperformedonvirtualconsolenumber one(v01).Theshellisrunning bash. Its status is s,


which means sleeping. Thiis is because it's waiting for the X Windows sytemto finish.

XWindowswasstartedbythecommand startx. Itwon't finisheduntilweexit fromX.Ittoo is sleeping.

ThefvwmisawindowmanagerforX,allowingotherprogramstobestartedandwindowsto be arranged on the


screen.

ThisprocessrepresentsawindowintheXWindowssystem.Theshell, bash, isrunning inthe


newwindow.Thewindowisrunningonanewpseudo terminal(/dev/ptyp0) abbreviated pp0.

164
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

ThisistheEMACSeditorsessionstartedfromthe shellmentionedabove.It usesthe pseudo


terminal.

This isaclockprogramstartedbythe window manager. It'sinthe middleofaone-minute wait between


updates of the clock hands.

Processenvironment

Let'slookat someotherprocessesrunningonthisLinuxsystem.Theoutputhas been


abbreviated for clarity:

Herewecanseeoneveryimportant processindeed:

Ingeneral, eachprocess isstartedbyanother, knownas its parentprocess. Aprocessso started is known


as a child process.
WhenUNIXstarts, itrunsasingleprogram, theprimeancestrorandprocessnumberone: init.

Onesuchexample isthe loginprocedure init startsthegettyprogramonce foreachterminalthat we can use to


long in.

Theseareshowninthepsoutputlikethis:

165
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

When interacting with your server through a shell session, there are many pieces of information that your
shellcompilesto determine itsbehavior and accessto resources.Some ofthese settings are contained within
configuration settings and others are determined by user input.

One way that the shell keeps track of all of these settings and details is through an area it
maintainscalledtheenvironment. Theenvironmentisanareathattheshellbuildseverytimethat it starts a
session that contains variables that define system properties.

Inthisguide, wewilldiscuss howto interactwiththeenvironment andreadorsetenvironmental and shell


variables interactively and through configuration files. We will be using an Ubuntu
12.04VPSasanexample,butthesedetailsshouldberelevantonanyLinuxsystem.

Every time a shell session spawns, a process takes place to gather and compile information that should be
available to the shell process and its child processes. It obtains the data for these settings from a variety of
different files and settings on the system.

Basically the environment provides a medium through which the shell process can get or set settings and,
in turn, pass these on to its child processes.
EnvironmentList

The environment is implemented as strings that represent key-value pairs. If multiple values are passed,
they are typically separated by colon (:) characters. Each pair will generally will look something like this:
KEY=value1:value2:...

Ifthevaluecontainssignificantwhite-space, quotationsare used:

KEY="valuewithspaces"

The keys inthese scenarios are variables. Theycan be one oftwo types, environmentalvariables or shell
variables.

166
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Environmentalvariablesarevariablesthat aredefined forthecurrent shellandare inheritedby any child


shells or processes. Environmental variables are used to pass information into processes that are
spawned from the shell.

Shellvariablesarevariables that arecontainedexclusivelywithintheshellinwhichtheywere set or defined.


Theyare often used to keeptrack of ephemeral data, like the current working directory.

Byconvention, thesetypesofvariablesareusuallydefinedusingallcapitalletters.Thishelps users distinguish


environmental variables within other contexts.
Environmentvariables-getenv,setenv
Every process has an environment block that contains a set of environment variables and their values.
There are two types of environment variables: user environment variables (set for each user) and system
environment variables (set for everyone).

By default, a child process inherits the environment variables of its parent process. Programs started by the
command processor inherit the command processor's environment variables. To specify a different
environment for a child process, create a new environment block and pass a pointer to it as a parameter to
the CreateProcess function.

The command processor provides the set command to display its environment block or to create new
environment variables. You canalso view or modifythe environment variables byselecting System from the
Control Panel, selectingAdvanced system settings, and clicking Environment Variables.

Eachenvironmentblockcontainstheenvironmentvariablesinthefollowingformat:
Var1=Value1\0
Var2=Value2\0
Var3=Value3\0
...
VarN=ValueN\0\0
Thenameofanenvironmentvariablecannotincludeanequalsign(=).

The GetEnvironmentStrings function returns a pointer to the environment block of the calling process. This
should be treated as a read-only block; do not modify it directly. Instead, use the SetEnvironmentVariable
function to change an environment variable. When you are finished

167
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

with the environment block obtained from GetEnvironmentStrings,call the FreeEnvironmentStrings


function to free the block. Calling SetEnvironmentVariable has no effect on the system environment
variables.

Kernelsupport forprocess
The kernelruns the show, i.e. it manages allthe operations in a Unix flavored environment. The kernel
architecture must support the primary Unix requirements. These requirements fall in two categories
namely, functions for process management and functions for file management (files include device files).
Process management entails allocation of resources including CPU, memory, and offers services that
processes may need. The file management in itself involves handling all the files required by processes,
communication with device drives and regulating transmissionofdatato and fromperipherals. The
kerneloperationgives the user processes a feel of synchronous operation, hiding all underlying
asynchronism in peripheral and hardware operations (like the time slicing by clock). In summary, we can
say that the kernel handles the following operations :
1. Itisresponsibleforschedulingrunningofuserandother processes.
2. Itisresponsibleforallocating memory.
3. Itisresponsibleformanagingtheswappingbetweenmemoryand disk.
4. Itisresponsibleformovingdatatoandfromtheperipherals.
5. itreceivesservicerequests fromtheprocessesandhonorsthem.
ProcessIdentification:

Everyprocess has a unique process ID, a non-negative integer. There aretwo specialprocesses.
ProcessID0isusuallythescheduleprocessand is oftenknownasthe‘swapper’. No programon disk corresponds
to this process – it is part of the kernel and is known as a systemprocess, process ID1is usuallythe ‘init’
process and is invoked bythe kernelat the end of the bootstrap procedure. The program files for this
process loss /etc/init in older version of UNIX and is
/sbin/init isnewerversion.‘init’usuallyreadsthesystemdependent initializationfilesandbrings the system to a
certain state. The ‘init’ process never dies. ‘init’ becomes the parent process of any orphaned child process.
Processcontrol

One furtherpsoutputexampleistheentryforthepscommanditself:

168
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

This indicatesthatprocess192isinarunstate(R)andisexecutingthecommandps-ax.

Wecanset theprocesspriorityusing niceandadjust it using renice,whichreducethepriorityof a process by 10.


High priority jobs have negative values.

Usingtheps-l(forlongoutput),wecanviewthepriorityofprocesses. Thevalueweare interested in is shown


in the NI (nice) column:

Herewecanseethattheoclockprogramisrunningwithadefault nice value.Ifit had been stated with


the command,

itwouldhavebeenallocatedanicevalueof+10.

Wecanchange the priorityofa ruinning processbyusingtherenice command,

Sothat nowtheclockprogramwillbescheduledtorunlessoften. Wecanseethe modified nice value with


the ps again:

Noticethatthestatuscolumn nowalso contains N,to indicatethatthenicevaluehaschanged from the default.

Process Creation
StartingNewProcesses

169
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Wecancauseaprogramto runfrominsideanother programand therebycreateanewprocess by using the


system. library function.

Thesystemfunctionrunsthecommandpassedtoitasstringandwaitsforit tocomplete. The command is


executed as if the command,

hasbeengiventoashell.

Try ItOut-system
1. Wecanusesystemtowritea programto run psforus.

2. Whenwecompileandrunthisprogram,system.c,wegetthefollowing:

170
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

3. Thesystemfunctionusesashelltostartthedesired program.

Wecould put thetask inthe background,bychanging thefunctioncalltothe following:

Now,whenwecompile and runthisversionoftheprogram,weget:

How ItWorks
Inthefirstexample,theprogramcallssystemwiththestring"ps-ax",whichexecutes
thepsprogram.Ourprogramreturnsfromthecalltosystemwhenthe pscommandisfinished.

In the second example, the call tosystem returns as soon as the shell command finishes.
Theshellreturnsassoonasthe psprogramisstarted,just aswould happenifwehadtyped,

atashellprompt.

171
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

ReplacingaProcessImage

There isawhole familyofrelated functionsgroupedunderthe exec heading.Theydiffer inthe way that they
start processes and present program arguments.

Theexec familyoffunctionsreplacethecurrent processwithanothercreatedaccordingto the arguments


given.

Ifwewishto useanexec functiontostartthe psprogramas inourpreviousexamples, wehave the following


choices:

TryItOut-exclp
Let's modifyour exampletousean exexlp call.

172
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Now,whenwerunthisprogram, pexec.c, wegettheusualpsoutput,but no Done.message at all.

Notealsothatthereisnoreferencetoaprocesscalledpexecinthe output:

How ItWorks
Theprogramprintsitsfirst messageandthencalls execlp,whichsearchesthedirectoriesgiven by the PATH
environment variable for a program called ps.

Itthenexecutesthisprograminplaceofour pexec program, starting it as ifwe hadgiventhe shell command:

WaitingforaProcess

Wecanarrange fortheparent processto wait untilthechild finishesbeforecontinuingby calling wait.

173
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Thewait systemcallcausesaparent processtopauseuntiloneofitschildprocessesdiesoris stopped.

Wecaninterrogatethestatusinformationusingmacrosdefinedinsys/wait.h. Theseinclude:

TryItOut-wait

1. Let'smodifyourprogramslightlyso wecanwaitforandexaminethechildprocessexit status. Call


the new program wait.c.

174
J.B.INSTITUTEOFENGINEERINGAND
TECHNOLOGY
LinuxProgrammingNotes

2. Thissectionoftheprogramwaitsforthechildprocessto finish:

175
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Whenwerunthisprogram,weseetheparent wait forthechild.Theoutput isn't confused and the


exit code is reported as expected.

How ItWorks

Theparent processusesthe wait systemcallto suspend itsownexecutionuntilstatus


information becomes available for a child process.

176
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

ZombieProcesses

Whenachildprocessterminates,anassociationwithitsparent survivesuntiltheparent in turn either


terminates normally or calls wait.
Thisterminated child processisknownasazombieprocess.

Try ItOut-Zombies

fork2.c isjsutthesameasfork.c,exceptthatthenumberofmessagesprintedbythechild and paent


porcesses is reversed.

Herearetherelevantlinesofcode:

How ItWorks

Ifweruntheaboveprogramwith fork2 &and thencallthe psprogramafterthechild has finished but before


the parent has finished, we'll see a line like this:

There'sanothersystemcallthat youcanusetowailforchildprocesses.It'scalled waitpidand youu can use it to


wait for a specific process to terminate.

177
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Ifwewantto haveaparent processregularlycheckwhetheraspecificchildprocess had terminated,


we could use the call,

whichwillreturnzeroifthechild hasnot terminatedorstoppedorchild_pidifithas.

OrphanProcess
• WhentheparentdiesfirstthechildbecomesOrphan .
• Thekernelclearstheprocesstableslotfortheparent.

Systemcallinterfaceforprocessmanagement

InadditiontotheprocessID,thereareotheridentifiers foreveryprocess. Thefollowing functions return


these identifiers
#incldue<sys/types.h>
#include<unistd.h>
pid_tgetpid(void); Returns:processIDofcalling process

pid_tgeppid(void); Returns:parentprocessIDOFcallingprocess

uid_t getuid(void); Returns: real user ID of calling process uid_t


geteuid(void); Returns:effectiveuserIDofcallingprocess
gid_t getgid(void); Returns: real group ID of calling process
gid_tgetegid(void); Returns:effectivegroupIDofcallingprocess

forkFunction

178
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

The only way a new process is created by the UNIX kernel is when an existing process calls the fork
function.
#include<sys/types.h>
#include<unistd.h>pid_t
fork(void);
Return:0ischild,processIDofchildinparent,-1onerror

The new process created byfork is called child process. This is called once, but returntwice that is the return
value in the child is 0, while the return value in the parent is the process ID of the new child. The reason the
child’s process ID is returned to the parent is because a process can have more than one child, so there is
no function that allows a process to obtain the process IDs of its children. The reason fork return 0 to the
child is because a process can have only a single parent, so that child can always call getppid to obtain the
process ID of its parent.
Boththe child and parent containexecuting withthe instructionthat follows the callto fork. The child is copy
of the parent. For example, the child gets a copy of the parent’s data space, heapand stack. This is a copy
for the child the parent and children don’t share these portions of memory. Often the parent and child
share the text segment, if it is read-only.
Therearetwo usersforfork:

1. When a process wants to duplicate itself so that the parent and child can each execute different sections of
code at the same time. This is common for network servers_ the parent
waitsforaservicerequestsfromaclient.Whentherequest arrives,theparent calls fork and lets the child handle
the request. The parent goes back to waiting for the next service request to arrive.
When a process wants to execute a different program,this is common for shells. Inthis case the child
does an exec right after it returns from the fork.
vforkFunction

179
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

The function vfork has the same calling sequence and share return values as fork. But the semantics ofthe
two functions differ. vfork is intended to create anew process whenthe purpose of the new process is to
exec a new program. vfork creates the new process, just like fork,without fully copying the address space of
the parent into the child, since the child won’t reference the address space – the child just calls exec right
after the vfork. Instead, while thechild is running, untilit calls either exec or exit, the child runs in the
address space ofthe parent. This optimization provides an efficiencygain on some paged virtual memory
implementations of UNIX.
Anotherdifferencebetweenthetwo functionsisthat vforkguaranteesthatthechildrunsfirst, until the parent
resumes.
exit Function

Therearethreewaysforaprocesstoterminatenormally,andtwoformsofabnormal termination.
1. Normaltermination:
a. Executingareturnfromthemainfunction.Thisis equivalenttocallingexit
b. Callingtheexitfunction
c. Callingthe_exitfunction
2. Abnormaltermination
a. Callingabort:ItgeneratestheSIGABRTsignal
b. Whentheprocessreceivescertainsignals. Thesignalcanbegeneratedbythe process itself
Regardless ofhow a process terminates, the same code in the kernel is eventuallyexecuted. This kernelcode
closes allthe opendescriptors fortheprocess, releases the memorythat it was using, and the like.
For any of the preceding cases we want the terminating process to be able to notify its parenthow it
terminated. For the exit and _exit functions this is done by passing an exit status as the argument to these
two functions. In the case of an abnormal termination however, the kernel generates a termination status
to indicate the reason for the abnormal termination. In any case,the parent of the process can obtain the
termination status from either the wait or waitpid

180
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

function.The exit status is converted into a termination status by the kernel when _exit is finally called. If
the child terminated normally, then the parent can obtain the exit status of the child.
If the parent terminates before the child, then init process becomes the parent process of any process,
whose parent terminates; that is the process has been inherited by init. Whenever a
processterminatesthekernelgoesthroughallactiveprocessesto seeiftheterminatingprocess is the parent of
any process that still exists. If so, the parent process ID of the still existing process is changed to be 1 to
assume that everyprocess has a parent process.
When a child terminates before the parent, and if the child completely disappeared, the parent wouldn’t
be able to fetch its termination status, when the parent is ready to seek if the child had terminated. But
parent get this information by calling wait and waitpid, which is maintained by the kernel.
waitandwaitpidFunctions

When a process terminates, either normally or abnormally, the parent is notified by the kernel sending the
parent SIGCHLD signal. Since the termination of a child is an asynchronous event, this signal is the
asynchronous notification from the kernel to the parent. The default action for this signal is to be ignored.
A parent may want for one of its children to terminate and thenaccept it child’s termination code by
executing wait.
Aprocessthatcallswaitandwaitpidcan

1. block (ifallofitschildrenare stillrunning).


2. return immediately with termination status of a child (if a child has terminated andis waiting for its
termination status to be fetched) or
3. returnimmediatelywithanerror(ifitdownhaveanychild process).

Iftheprocessiscallingwait because it receivedSIGCHLDsignal,weexpect waittoreturn immediately. But,


if we call it at anyrandompoint in time, it can block.
#include<sys/types.h>
#include<sys/wait.h>

181
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

pid_twait(int*statloc);

pid_twaitpid(pid_tpid,int*statloc,intoptions); Both
return: process ID if OK, o or -1 on error The
difference between these two functions is
1. waitcanblockthecalleruntilachildprocessterminates,whilewaitpidhasanoption that prevents it from
blocking.
2. waitpiddoes notwaitfor thefirstchildtoterminate,ithas anumberof options that control which
process it waits for.
If a child has already terminated and is a zombie, wait returns immediately with that child’s
status.Otherwise, it blocksthecalleruntilachildterminates: ifthecallerblocksand hasmultiple children, wait
returns when one terminates, we can know this process by PID return by the function.
For both functions, the argument statloc is pointer to an integer. If this argument is not a null pointer,the
terminationstatusofthe terminated process isstored inthe locationpointed to bythe argument.
If we have more than one child, wait returns on termination of any of the children. A function that waits for
a specific process is waitpid function.
Theinterpretationofthepidargumentforwaitpiddependsonitsvalue:

pid == -1 waitsforanychildprocess.Here,waitpidisequivalenttowait pid > 0


waits for the child whose process ID equals pid
0 waits foranychildwhoseprocessgroupIDequalsthatofthecalling process
waits for anychildwhoseprocessgroupIDequalstheabsolutevalueof pid
waitpid returns the process ID of the child that terminated, and its termination status is returned through
statloc. With wait the only error is if the calling process has no children. With waitpid

182
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

however, it’salso possibletoget anerrorifthespecifiedprocessorprocessgroupdoesnot exist or is not a child


of the calling process.
Theoptionsargument letsusfurthercontroltheoperationofwaitpid.Thisargument iseither0 or is constructed
from the bitwise OR of the following constants.
WNOHANG waitpidwillnotblinkifachildspecifiedbypidis notimmediately
available.Inthiscase, thereturnvalueis0.

ifthestatusofanychildspecified bypidthat hasstopped,andwhose status has not been updated since it


has stopped, is returned
Thewaitpidfunctionprovidesthesefeaturesthatarenotprovidedbythewaitfunctionare:

1. waitpidletsustowaitforoneparticularprocess
2. waitpidprovidesanon-blockingversionofwait
3. waitpidsupportsjobcontrol(wittheWUNTRACEDoption)
exec Function

The fork function can create a new process that then causes another program to be executed by calling one
of the exec functions. When a process calls one of the exec functions, that process is completely replaced
by the new program and the new program starts executing at its main function. The process ID doesn’t
change across an exec because a new process is not created. exec merely replaces the current process with
a brand new program from disk.
There are six different exec functions. These six functions round out the UNIX control primitives. With fork
we can create new processes, and with the exec functions we can initiate new programs. The exit function
and the two wait functions handle termination and waiting for termination. These are the only process
control primitives we need.
#include<unistd.h>

int execl(const char*pathname,const char*arg0,.../*(char*)0*/ int


execv(const char *pathname, char *const argv[]);
int execle(constchar*pathname, constchar*arg0,.../*(char*)0,charenvp[]*/);

183
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

intexecve(constchar*pathname,char*constargv[],char*constenvp[]); int
execlp(const char *pathname, const char *arg0, . . . /* (char *) 0*/); int
execvp(const char *filename, char *const argv[]);
Allsixreturns:-1onerror,noreturnonsuccess.

The first difference inthese functionsisthatthefirst fourtakeapathnameargument,whilethe last two take a


filename argument. When a filename argument is specified:
 iffilenamecontainsaslash,itistakenasa pathname.
 Otherwise,theexecutablefileisasearchedforindirectoriesspecifiedbythe PATH environment variable.
ThePATHvariablecontainsalistofdirectories(calledpathprefixes)thatareseparatedby colors. For example, the
name=value environment string
PATH=/bin:/usr/bin:usr/local/bin/:.

Specifiesfourdirectoriestosearch,where lastoneiscurrentworkingdirectory.

If either of the two functions, execlp or execvp finds an executable file using one of the path prefixes, but
the file isnot amachine executable that wasgeneratedbythe link editor,it assumes the file is a shell script
and tries to invoke /bin/sh with filename as input to the shell.
The next difference concerns the passing ofargument list. The function execl, execlp and execle require
each of the command-line arguments to the new program to be specified as separate arguments.
Theendoftheargument should bea nullpointer. Fortheotherthreefunctionsexecv, execvp and execve, we
have to build an array of pointers to the arguments, and the address ofthis array is the argument to these
three functions.
The finaldifference isthe passing ofthe environment list tothe new program. The two functions execle and
execve allow us to pass a pointer to an array of pointer to an array of pointer to an array of pointers to the
environment strings. The other four functions, however, use the environ variable in the calling process to
copythe existing environment for the new program.

184
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

DifferencesBetweenThreadsandProcesses
UNIXprocessescancooperate;theycansendeachother messagesandtheycaninterrupt one another.

There isaclassofprocessknownasa thread whicharedistinct fromprocesses inthattheyare separate


execution streams within a single process.

Signals

Asignalisanevent generatedbytheUNIXsysteminresponseto somecondition, uponreceipt of which a process


may in turn take some action.
Signalnamesaredefinedintheheaderfilesignal.h.TheyallbeginwithSIGandinclude:

185
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Additionalsignals include:

Ifthe shelland terminaldriver are configured normally, typing the interrupt character (Ctrl-C)
atthekeyboardwillresult inthe SIGINTsignalbeingsenttotheforegroundprocess.Thiswill cause the program
to terminate.

Wecanhandlesignalsusingthesignal libraryfunction.

Thesignalfunctionitselfreturnsa functionofthesametype, whichisthepreviousvalueof the function set


up to handle this signal, or one of these tow special values:

Signalgeneration&Handling

1. We'llstartbywritingthe functionwhichreactstothesignalwhichispassed in the


parameter sig. Let's call it ouch:

186
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

2. Themainfunctionhastointercept theSIGINTsignalgeneratedwhenwe typeCtrl-C. For the


rest of the time, it just sits in an infinite loop, printing a message once a second:

3. Whiletheprogramisrunning,typingCtrl-Ccausesit toreact andthen continue.


When we type Ctrl-C again, the program ends:

187
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

How ItWorks
Theprogramarranges forthefunctionouchtobecalledwhenwetypeCtrl-C, whichgives the SIGINT
signal.

KernelsupportforSignals-Sending Signals
Aprocessmaysend asignaltoitselfbycallingraise.

Aprocess maysendasignaltoanotherprocess, includingitself, bycallingkill.

Signalsprovideuswithausefulalarmclockfacility.

Thealarm functioncallcanbeused byaprocesstoschedulea SIGALRM signalat sometime in the


future.

188
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

TryItOut-AnAlarmClock
1. Inalarm.c,thefirstfunction,ding,simulatesanalarmclock:

2. Inmain,wetellthechildprocesstowait forfivesecondsbeforesendinga SIGALRM signal to its parent:

3. Theparent processarrangestocatchSIGALRM withacallto signalandthenwaitsfor the


inevitable.

189
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Whenwerunthisprogram, it pausesforfivesecondswhile it waits forthesimulated alarm


clock.

Thisprogramintroducesanewfunction, pause, whichsimplycausestheprogramto


suspend execution until a signal occurs.
It'sdeclaredas,

How ItWorks
Thealarmclocksimulationprogramstartsanewprocessvia fork. Thischildprocesssleeps for five
seconds and then sends a SIGALRM to its parent.

ARobustSignalsInterface

X/Openspecificationrecommendsanewerprogramminginterfaceforsignalsthat is more
robust: sigaction.

190
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Thesigaction structure,usedto definetheactionstobetakenonreceipt ofthesignalspecified by sig, is defined


in signal.h and has at least the following members:

Try ItOut-sigaction

Makethechangesshownbelowsothat SIGINT isinterceptedbysigaction.Callthe new program


ctrlc2.c.

191
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Runningtheprogram,wegetamessagewhenwetypeCtrl-C becauseSIGINT ishandled repeated;y by


sigaction.

TypeCtrl-\ toterminatethe program.

192
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

How ItWorks

Theprogramcalls sigactioninsteadofsignalto setthesignalhandler forCtrl-C(SIGINT)to the function ouch.

Signal Sets

Theheader filesignal.hdefinesthetypesigset_tandfunctionsusedto manipulatesetsof signals.

Thefunctionsigismemberdetermineswhether thegivensignalisamemberofasignalset.

193
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Theprocesssignalmaskissetorexaminedbycallingthefunctionsigprocmask.

sigprocmaskcanchangetheprocesssignalmask inanumberofwaysaccordingto the how


argument.
Thehowargumentcanbeoneof:

Ifasignalis blockedbyaprocess, itwon'tbedelivered, butwillremainpending.

Aprogramcandeterminewhichofitsblockedsignalsarpending bycalling the function


sigpending.

Aprocesscansuspend executionuntilthedeliveryofoneofaset ofsignals by calling


sigsuspend.

Thisisamoregeneralformofthepausefunctionwemetearlier.

194
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Signal Functions

Thesystemcallsrelatedtosignalsareexplainedinthefollowing sections.

Unreliablesignals

The signals could get lost – a signal could occur and the process would never know about it. Here, the
process has little control over a signal, it could catch the signal or ignore it, but blocking of a signal is not
possible.
Reliablesignals

LinuxsupportsbothPOSIXreliable signals(hereinafter"standardsignals")andPOSIXreal-time signals.


Signal dispositions
Eachsignalhasacurrent disposition,whichdetermineshowtheprocessbehaveswhenit is delivered the
signal.
Theentriesinthe"Action"columnofthetablesbelowspecifythedefault dispositionfor each signal.

killandraiseFunctions

Thekillfunctionsendsasignaltoa processoragroupofprocesses. Theraise functionallows a process to send


a signal to itself.
#include<sys/types.h>
#include<signal.h>
intkill(pid_tpid,intsigno); int
raise(int signo);
Bothreturn:0ifOK,-1onerror

195
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Therearefourdifferentconditionsforthepidargumenttokill:

pid>0ThesignalissenttotheprocesswhoseprocessIDispid.

0 The signal is sent to all processes whose process group ID equals the process
groupIDofthesenderandforwhichthesenderhaspermissionto send the signal.
The signal is sent to all processes whose process groupID equals
theabsolute value of pid and for which the sender has permission to send the signal.
pid= -1 unspecified.

alarmand pause Functions

The alarm function allows us to get a timer that will expire at a specified time in the future.When the timer
expires, the SIGALRM signal is generated. If we ignore or don’t catch this signal, its default action is to
terminate the process.
#include<unistd.h>

unsignedintalarm(unsignedintseconds);

Returns:0ornumberofsecondsuntilpreviouslysetalarm.

The seconds value is the number of clock seconds in the future when the signal should be generated. There
is only one of the alarm clocks per process. If, when we call alarm, there is a previouslyregistered
alarmclock for the process that has not yet expired, the number of seconds left for that alarm clock to
return as the value of this function. That previously registered alarm clock is replaced by the new value.
If there is a previously registered alarm clock for the process that has not yet expired and if the seconds
value is 0, the previous alarm clock is cancelled. The number of seconds left for that previous alarm clock is
still returned as the value of the function.

Although the default action for SIGALRM is terminating the process, most processes use an alarm clock
catch this signal.

196
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Thepause functionsuspendsthecallingprocessuntilasignaliscaught. #include<unistd.h>


intpause(void);

Returns: -1witherrnosetto EINTR

Theonlytimepausereturnsisifasignalhandler is executedandthat handlerreturns.In that case, pause


returns -1 with errno set to EINTR.
abortFunction

abortfunctioncausesabnormalprogramtermination. #include<stdlib.h>
voidabort(void);

Thisfunctionneverreturns.

This functionsendstheSIGABRT signaltotheprocess. Aprocessshouldnot ignorethis signal. abort


overrides the blocking or ignoring of the signal by the process.
sleepFunction

#include<unistd.h>

unsignedintsleep(unsignedintseconds);
Returns:0or number ofunsleptseconds.
Thisfunctioncausesthecallingprocesstobesuspendeduntileither:

1. Theamountofclockthatisspecifiedbysecondshaselapsedor
2. Asignaliscaughtbytheprocessandthesignalhandlerreturns.
Incase1thereturnvalue is0whensleep returnsearly, becauseofsomesignalbeingcaught case 2, the
return value is the number of unslept seconds.
Sleepcanbe implementedwithanalarmfunction. Ifalarmisused, however, therecanbe interaction
between the two functions.

197
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

UNIT-IV:
IV.InterprocessCommunication
IntroductiontoIPC
IPC between processes on a single computer
systemIPCbetweenprocessesondifferent systems Pipes-
creation
IPCbetweenrelatedprocessesusingunnamedpipes
FIFOs-creation,IPCbetweenunrelatedprocessesusingFIFOs(named pipes) Differences
Between Unnamed And Named Pipes
popen&pcloselibraryfunctions.
4.9MessageQueues-Kernelsupportfor messages
APIsformessagequeues client/server
example.
Semaphores-Kernelsupportforsemaphores
APIsforsemaphores
FilelockingwithSemaphores

198
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

UnitIV

Interprocesscommunication,MessageQueuesandSemaphores

IntroductiontoIPC

InterprocessCommunication-“Interprocesscommunication(IPC)isthetransferof data among different


processes”.

Interprocess communication (IPC) includes thread synchorization and data exchange between
threadsbeyond theprocessboundaries. Ifthreads belongtothesameprocess, theyexecuteinthe same address
space, i.e. theycan access global(static) data or heap directly, without the help of the operating system.
However, ifthreads belong to different processes, theycannot accesseach others address spaces without
the help of the operating system.

TherearetwofundamentallydifferentapproachesinIPC:
 processesareresidingonthesame computer
 processesareresidingondifferentcomputers

The first case is easier to implement because processes can share memory either in the userspace or in the
system space. This is equally true for uniprocessors and multiprocessors.

In the second case the computers do not share physical memory, they are connected via I/O device(for
example serial communication or Ethernet). Therefore the processes residing in different computers can
not use memory as a means for communication.

IPCbetweenprocessesonaSingle System
MostofthischapterisfocusedonIPConasingle computersystem, including four general
approaches:

 Shared memory
 Messages
 Pipes
 Sockets

199
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

The synchronizationobjectsconsidered inthe previouschapternormallywork acrossthe process


boundaries (on a single computer system). There is one addition necessary however: the
synchronization objects must be named. The handles are generally private to the process, while the
object names, like file names, are global and known to all processes.

h=init_CS("xxx");
h=init_semaphore(20,"xxx"
); h = init_event("xxx");
h=init_condition("xxx");
h=init_message_buffer(100,"xxx");
IPCbetweenprocessesondifferentsystems
IPCbetweenprocessesondifferent systems
IPCisInterProcessCommunication, moreofatechniquetosharedataacrossdifferentprocesses
withinonemachine,insuchawaythatdatapassing bindsthecouplingofdifferentprocesses.
Thefirst,isusingmemorymappingtechniques,whereamemorymapiscreated,and others
open the memory map for reading/writing...
The second is, using sockets, to communicate with one another...this has a high overhead,
aseachprocesswouldhavetoopenupthesocket,communicateacross... althougheffective
Thethird,istouseapipeor anamedpipe,averygoodexample

PIPES:
A pipe is a serial communication device (i.e., the data is read in the order in which it was
written),which allows a unidirectional communication. The data written to end
isreadbackfromtheotherend.

The pipe is mainly used to communicate between two threads in a single process or between
parent and child process. Pipes can only connect the related process. In shell,
thesymbolcanbeusedtocreateapipe.

In pipes the capacity of data is limited. (i.e.) If the writing process is faster than the reading
process which consumes the data, the pipe cannot store the data. In this situation the writer
process will block until more capacity becomes available. Also if the reading process tries toread
data when there is no data to read, it will be blocked until the data becomes available. By this,
pipes automatically synchronize the two process.

Creatingpipes:
The pipe() function provides a means of passing data between two programs and also allows to
read and write the data.

#include<unistd.h>
intpipe(intfile_descriptor[2]);

pipe()function is passed with an arrayof file descriptors. It will fillthe arraywith new file
descriptorsandreturnszero. Onerror,returns -1andsetstheerrnotoindicatethereasonof

200
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

failure.

The filedescriptorsareconnected inawaythat isdatawrittentofile_descriptor[1]canbe read back from


the file_descriptor[0].

(Note:Asthisusesfiledescriptorsandnotthe file streams,wemust usereadandwrite system calls to access


the data.)

PipesareoriginallyusedinUNIXandaremadeevenmorepowerfulinWindows95/NT/2000.

Pipes are implemented in file system. Pipes are basically files with onlytwo file offsets: one for
readinganotherforwriting. Writingto apipeandreading fromapipe isstrictlyin FIFO manner. (Therefore pipes
are also called FIFOs).

For efficiency, pipes are in-core files, i.e. they reside in memory instead on disk, as any other global data
structure. Therefore pipes must be restricted in size, i.e. number ofpipe blocks must be limited. (In UNIX
the limitation is that pipes use only direct blocks.)Since the pipes have a limited size and the FIFO access
discipline, the reading and writing processes are synchronized in a similar manner as incase of message
buffers. The access functions for pipesare the same as for files: WriteFile() and ReadFile().

Pipesusedasstandardinput andoutput:
Wecaninvokethestandardprograms,onesthatdon’t expect afiledescriptorasaparameter. #include<unistd.h>
intdup(intfile_descriptor);int
dup2(intfile_descriptor_1,int file_descriptor_2);

Thepurposeofdupcallistoopenanew filedescriptor, whichwillrefer tothesame fileasan existing file


descriptor. In case of dup, the value of the new file descriptor is the lowest number available. In dup2 it
is same as, orthe first available descriptor greaterthan the parameter file_descriptor_2.

Wecanpassdatabetweenprocessbyfirst closingthefiledescriptor0andcallis madeto dup. Bythis the new


file descriptor will have the number 0.As the new descriptor is the duplicateofan existing one, standard
input is changed to have the access. So we have created two file descriptors for same file or pipe, one of
them will be the standard input.

(Note:Thesameoperationcanbeperformed byusingthe fcntl()function.But comparedtothis dup and dup2


are more efficient)

//pipes.c #include<unistd.h>
#include<stdlib.h>
#include<stdio.h>

201
J.B.INSTITUTEOFENGINEERING
ANDTECHNOLOGY
LinuxProgrammingNotes
#include<string.h>int
main()
{
intdata_processed; int
file_pipes[2];
constcharsome_data[]=
"123";pid_tfork_result;

if(pipe(file_pipes)==0)
{
fork_result=fork();
if(fork_result==(pid_t)-1)
{
fprintf(stderr,"forkfailure");
exit(EXIT_FAILURE);
}

202
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

if(fork_result==(pid_t)0)
{
close(0); dup(file_pipes[0]);
close(file_pipes[0]);
close(file_pipes[1]);
execlp("od","od","-c",(char*)0);
exit(EXIT_FAILURE);
}
else
{
close(file_pipes[0]); data_processed=write(file_pipes[1],
some_data,strlen(some_data));close(file_pipes[1]);
printf("%d-wrote%dbytes\n",(int)getpid(),data_processed);
}
}exit(EXIT_SUCCESS);
}

The programcreates a pipe and then forks. Nowbothparent and child process will have its
ownfiledescriptorsforreadingandwriting.Thereforetotallythereare fourfiledescriptors.

Thechildprocesswillcloseitsstandardinput with close(0)andcallsduo(file_pipes[0]).This will duplicate the


file descriptor associated with the read end. Then child closes its original file descriptor. As child will
never write, it also closes the write file descriptor,
file_pipes[1]. Now there is only one file descriptor 0 associated with the pipe that is standard
input.Next,childusestheexectoinvokeanyprogramthat readsstandard input. The od command will
wait for the datato be available from the user terminal.

Since the parent never read the pipe, it starts byclosing the read end that is file_pipe[0]. When
writingprocessofdatahasbeenfinished, thewriteendoftheparent isclosedandexited. Asthere are no file
descriptor open to write to pipe, the odcommand will be able to read the three bytes written to pipe,
meanwhile the reading process willreturn 0 bytes indicating the end of the file.
Therearetwotypesofpipes:
Namedpipes.
Unnamedpipes(Anonymouspipes)

4.6 Namedpipes (FIFOs)

Similar to pipes, but allows for communication between unrelated processes.


Thisisdonebynamingthecommunicationchannelandmakingit permanent.

Likepipe, FIFOistheunidirectionaldata stream.

FIFOcreation:

203
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

intmkfifo(constchar*pathname,mode_tmode);
- makesaFIFOspecialfilewithname pathname.
(modespecifiestheFIFO'spermissions,ascommoninUNIX-like file systems).
- AFIFOspecialfileissimilartoapipe,exceptthatitiscreatedin
adifferent way.Insteadofbeingananonymouscommunicationschannel,a FIFO special file is
entered into the file system by calling mkfifo()

OnceaFIFOspecialfile hasbeencreated,anyprocesscanopenit for reading or


writing, in the same way as an ordinary file.

AFirst-in,first-out(FIFO)file isapipethat hasaname inthe filesystem.Itisalso calledas named pipes.

Creationof FIFO:
WecancreateaFIFOfromthecommandlineand withinaprogram.

Tocreatefromcommand linewecanuseeithermknod ormkfifocommands.


$mknodfilenamep
$mkfifofilename

(Note:Themknodcommand isavailableonlynolderversions, youcanmakeuseofmkfifo in new versions.)

TocreateFIFOwithintheprogramwecanusetwo systemcalls.They are,


#include<sys/types.h>
#include<sys/stat.h>

intmkfifo(const char
*filename,mode_tmode);
int mknod(const char *filename,
mode_tmode|S_IFIFO,(dev_t)0);

If we want to use the mknod function we have to use ORing process of fileaccess mode with
S_IFIFOandthedev_tvalueof0.Instead ofusingthiswecanusethesimplemkfifo function.

Accessing FIFO:
LetusfirstdiscusshowtoaccessFIFOincommand lineusing filecommmands.The useful feature of named
pipes is, as theyappear inthe file system, we canuse them in commands.

Wecanreadfromthe FIFO(empty)
$cat</tmp/my_fifo
Now,letuswritetotheFIFO.
$echo"Simple!!!">/tmp/my_fifo
(Note:Thesetwocommandsshouldbeexecutedindifferentterminalsbecausefirst command will
be waiting for some data to appear in the FIFO.)

204
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

FIFOcanalso beaccessedas likea file intheprogramusing low-levelI/O functionsorC library I/O functions.

The only difference between opening a regular file and FIFO is the use of open_flag with the
optionO_NONBLOCK.Theonlyrestrictionisthatwecan’topenFIFO forreadingandwriting with O_RDWR mode.

//fifo1.c

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h> #include
<string.h> #include
<fcntl.h> #include
<limits.h>
#include<sys/types.h>
#include <sys/stat.h>

#define FIFO_NAME "/tmp/my_fifo" #define


BUFFER_SIZE PIPE_BUF
#defineTEN_MEG(1024*1024*10)

int main()
{
intpipe_fd; int
res;
intopen_mode=O_WRONLY; int
bytes_sent = 0;
charbuffer[BUFFER_SIZE+1];
if(access(FIFO_NAME,F_OK)==-1){ res =
mkfifo(FIFO_NAME, 0777);
if(res!= 0){
fprintf(stderr,"Couldnotcreatefifo%s\n",
FIFO_NAME); exit(EXIT_FAILURE);
}
}
printf("Process%dopeningFIFOO_WRONLY\n",getpid()); pipe_fd =
open(FIFO_NAME, open_mode);
printf("Process%dresult%d\n",getpid(),pipe_fd); if
(pipe_fd != -1) {
while(bytes_sent<TEN_MEG){
res=write(pipe_fd,buffer,BUFFER_SIZE);if (res == -1) {
fprintf(stderr,"Writeerroronpipe\n");
exit(EXIT_FAILURE);
}

205
J.B.INSTITUTEOFENGINEERINGAND
TECHNOLOGY
LinuxProgrammingNotes

}
(void)close(pipe_fd);
}
else{ exit(EXIT_FAILURE);
}
printf("Process %d finished\n",
getpid());exit(EXIT_SUCCESS);
}

//fifo2.c
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h> #include
<string.h> #include
<fcntl.h> #include
<limits.h>
#include<sys/types.h>
#include <sys/stat.h>
#defineFIFO_NAME"/tmp/my_fifo" #define
BUFFER_SIZE PIPE_BUF int main()
{
intpipe_fd; int
res;
int open_mode =
O_RDONLY;charbuffer[BUFFER_SIZE+1];in
t bytes_read = 0;
memset(buffer,'\0',sizeof(buffer));
printf("Process %d opening FIFO O_RDONLY\n",
getpid());pipe_fd=open(FIFO_NAME,open_mode); printf("Process
%d result %d\n", getpid(), pipe_fd);
if(pipe_fd!=-1)
{do{
res = read(pipe_fd, buffer,
BUFFER_SIZE);bytes_read+=res;
} while (res > 0);
(void)close(pipe_fd);
}
else { exit(EXIT_FAILURE);
}
printf("Process%dfinished,%dbytesread\n",getpid(), bytes_read);
exit(EXIT_SUCCESS);
}

Bothfifo1.candfifo2.cprogramsusetheFIFOinblockingmode.

206
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Firstfifo1.cisexecuted.Itblocksandwaitsfor readerto open the named pipe. Now writer unblocks and starts
writing data to pipe. At the same time, the reader starts reading data from the pipe.

4.5Unnamedpipes(Anonymous Pipes)

Anonymouspipesdon'thavenames,thereforetheycan be used only between related processes which can


inherit the file handles (file descriptors).

Anonymous pipes are typically used to "pipe" two programs: standard output fromone program is
redirected to the pipe input (write handle), while the standard inputof the second program is redirected to
from the pipeoutput (read handle). The pipe is created by the parent (usually the login shell), and the pipe
handles are passedto children through the inheritance mechanism.

Anonymous pipes cannot be used across a network. Also, anonymous pipes are unidirectional- in order to
communicatetworelatedprocessesinbothdirections,two anonymous pipes must be created.

ExampleofWin32anonymouspipesusedforprogram piping:
//*********************************************
**********************
//Thisprogramimplementspipingof
programs p1.exe
and p2.exe
// through

an anonymouspipe.The
sa.n Len program creates
sgath.bInheritHandle= two child
= processes
TRUE;//Handlesare //(which execute
s iz e images p1.exe
i n h eritable(defaultis
and p2.exe)
and a pipe,
o f (S
F A LS E ) HANDLErh,wh;thenpasses
EC o f t h e p ip e // thepipehandlesto the
/ / Readandwritehandles "TC Yo _ u ld n 't
cUoR children.
icAfr(Te!aCtreepatipePeipe(&rh,&wh,
//
"T&R<sa<I,0)) // The
BGUetLastErroTrE( )S<< program is
)e;ndl;return (s 1a.)l; invokedas:
pSe curit yDe scri ptor pipe p1 p2
=0;
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

(nocommandlinearguments)
//******************************************************************* #include
<windows.h>
#include<iostream.h>
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

si1.hStdInput=GetStdHandle(STD_INPUT_HANDLE);
si1.hStdOutput= wh; // Stdoutputofp1isinputtothe pipe
si1.dwFlags=STARTF_USESTDHANDLES;
CreateProcess(argv[1], //Nameofthep1'simage(without ".exe."
0,0,0,
TRUE, //Eachopeninheritablehandleofthe
//parentwillbeinheritedbythechild
0,0,0,
&si1,&pi1);
CloseHandle(wh); //Pipehandlenolongerneeded
// Createthesecondchild processp2
PROCESS_INFORMATIONpi2;
STARTUPINFOsi2;
GetStartupInfo(&si2); //Getdefaultstartupstructure
si2.hStdInput=rh; //Stdinputofp2isotputfromthepipe
si2.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
si2.dwFlags=STARTF_USESTDHANDLES;
CreateProcess(0,argv[2], //Nameofthep1'simage(without".exe."
0,0,
TRUE, //Eachopeninheritablehandleofthe
//parentwillbeinheritedbythechild
0,0,0,
&si2,&pi2); WaitForSingleObject(pi1.hProcess,INFINITE);
CloseHandle(pi1.hProcess);
WaitForSingleObject(pi2.hProcess,INFINITE);
CloseHandle(pi2.hProcess);
CloseHandle(rh); return(0);
}

Comment:
Inorderto communicatetwo processes (P1 and P2) throughanonymous pipes byredirecting the standard
I/O,the processesdon't have to be awareofthe existence ofpipes, i.e.their sourcesand images don't have to
be modified.

4.8Pipeprocessing:(popen&pcloselibraryfunctions)

Theprocessofpassingdatabetweentwo programs canbedonewiththehelpofpopen() and pclose()


functions.
#include<stdio.h>
FILE*popen(constchar*command, const char
*open-mode);
intpclose(FILE*stream_to_close);

208
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

popen():
The popen function allows a program to invoke another program as a new process and either writethe
datato it orto read fromit. The parameter command is the name ofthe programto run.
Theopen_modeparameterspecifiesinwhichmode it istobe invoked,it canbeonlyeither"r"or "w". On failure
popen() returns a NULL pointer. If you want to perform bi-directional communication you have to use two
pipes.

pclose():
By using pclose(), we can close the filestream associated with popen() after the process started by it has
been finished. The pclose() will return the exit code ofthe process, which is to be
closed.Iftheprocesswasalreadyexecuteda waitstatement beforecallingpclose,theexit status willbelost
becausetheprocesshasbeenfinished.Afterclosingthefilestream,pclose()willwait for the child process to
terminate.

Messagequeue:
This is an easy way of passing message between two process. It provides a way of sending a block of data
from one process to another. The main advantage of using this is, each block of data is considered to have
a type, and a receiving process receives the blocks of data having different type values independently.

Creationandaccessingofamessage queue:
Youcancreateand accessamessagequeueusingthemsgget()
function. #include<sys/msg.h>
intmsgget(key_tkey,intmsgflg);
The first parameter is the key value, which specifies the particular message queue. Thespecial constant
IPC_PRIVATE will create a private queue. But on some Linux systems the message queue may not
actually be private.
Thesecondparameter istheflagvalue,whichtakesninepermission flags.

Addinga message:
Themsgsnd() functionallowsto addamessagetoamessage queue.
#include<sys/msg.h>
intmsgsnd(intmsqid,constvoid*msg_ptr,size_tmsg_sz,intmsgflg);

Thefirstparameteristhe messagequeue identifierreturnedfromanmsggetfunction.

Thesecondparameteristhepointertothemessageto besent.Thethirdparameteristhesizeof the message


pointed to by msg_ptr. The fourth parameter, is the flag value controls what happens if either the current
message queue is full or withinthe limit. Onsuccess, the function returns 0 and a copyof the message data
has been taken and placed on the message queue, on failure -1 is returned.

Retrievingamessage:
Thesmirch()functionretrievesmessagefromthemessagequeue.

209
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

#include<sys/msg.h>
intmsgsnd(intmsqid,constvoid*msg_ptr
,size_tmsg_sz,longintmsgtype ,intmsgflg);

Thesecondparameter isapointertothemessagetobe received.

The fourthparameter allows a simple formofreceptionpriority. If its value is 0,the first


availablemessageinthequeueisretreived.Ifit isgreaterthan0,thefirst messagetypeis retrived. If it is less
than 0,the first message that has a type the same a or less than the absolute value of msgtype is
retrieved.

On success, msgrcv returns the number on bytes placed in the receive buffer, the message is copied
intotheuser-allocatedbufferandthedataisdeletedfromthe messagequeue.Itreturns -1 on error.

Controllingthemessagequeue:
Thisisverysimilarthatofcontrolfunctionofsharedmemory.
#include<sys/msg.h>
intmsgctl(intmsgid,intcommand, struct
msqid_ds *buf);

Thesecond parametertakesthevaluesasgivenbelow:

1.) IPC_STAT- Setsthedatainthemsqid_dstoreflectthevaluesassociatedwiththemessage

210
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

queue.

2.) IPC_SET- Iftheprocesshasthepermissiontodo so,thissetsthevaluesassociatedwith the message


queue to those provided in the msgid_ds data structure.
3.) IPC_RMID-Deletesthemessagequeue.

(Note:Ifthemessagequeue isdeletedwhiletheprocess iswriting ina msgsndormsgrcv function,


the send or receive function will fail.

Client /serverExample:
//msgq1.c
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<errno.h>
#include<unistd.h>
#include<sys/
msg.h>struct
my_msg_st
{
long int my_msg_type;
charsome_text[BUFSIZ
];
};

int main()

{
intrunnin
g=
1;intmsgi
d;
structmy_msg_stsome_da
ta; long int
msg_to_receive = 0;

msgid=msgget((key_t)1234,
0666 | IPC_CREAT);
if(msgid==-1)
{
fprintf(stderr,"failedtoget:\n");
exit(EXIT_FAILURE);
}

211
J.B.INSTITUTEOFENGINEERING
ANDTECHNOLOGY
LinuxProgrammingNotes

while(running)
{
if(msgrcv(msgid,(void*)&some_data, BUFSIZ,msg_to_receive,0) == -1)
{
fprintf(stderr,"failedtoreceive:
\n");exit(EXIT_FAILURE);
}

printf("You Wrote: %s", some_data.some_text);


if(strncmp(some_data.some_text,"end",3)
== 0)
{
running= 0;

}
}
if(msgctl(msgid,IPC_RMID, 0)==-1)
{
fprintf(stderr,"failedtodelete\n");
exit(EXIT_FAILURE);
} exit(EXIT_SUCCESS);
}

//msgq2.c

#include <stdlib.h> #include


<stdio.h> #include <string.h>
#include <errno.h> #include
<unistd.h> #include
<sys/msg.h>
#defineMAX_TEXT512

structmy_msg_st
{
longintmy_msg_type;
charsome_text[MAX_TEXT];
};

int main()
{
intrunning=1;

212
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

structmy_msg_stsome_data; int
msgid;
charbuffer[BUFSIZ];

msgid=msgget((key_t)1234, 0666 |
IPC_CREAT);
if(msgid==-1)
{
fprintf(stderr,"failedtocreate:\n");
exit(EXIT_FAILURE);
}
while(running)
{
printf("Enter Some Text: "); fgets(buffer,
BUFSIZ, stdin); some_data.my_msg_type
= 1;
strcpy(some_data.some_text,buffer);

if(msgsnd(msgid,(void*)&some_data,MAX_TEXT,0)==-1)
{
fprintf(stderr,"msgsndfailed\n");
exit(EXIT_FAILURE);
}
if(strncmp(buffer,"end",3)==0)
{
running= 0;
}
} exit(EXIT_SUCCESS);
}

Themsgq1.c program will create the message queue using msgget() function.
Themsgididentifierisreturnedbythemsgget().Themessagearereceivedfrom the queue
usingmsgrcv()functionuntilthe string "end" is encountered. Then the queueis
deletedusingmsgctl()function.
Themsgq2.c program uses themsgsnd()function to sendthe enteredtext to the queue.

Semaphore:

While we are using threads in our programs in multi-user systems, multiprocessing system, or a combinationoftwo,
wemayoftendiscover critical sectionsinthecode.Thisisthesectionwhere
wehavetoensurethatasingleprocesshasexclusiveaccess totheresource.
Forthispurposethesemaphoreisused.It allowsin managing theaccesstoresource.
Toprevent theproblemofoneprogramaccessing thesharedresourcesimultaneously,weare in

213
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

need to generate and use a token which guarantees the access to only one
threadofexecutioninthecriticalsectionatatime.

It is counter variable, which takes only the positive numbers and upon which programs can only act
atomically. The positive number is the value indicating the number of units of the shared resources are
available for sharing.

Thecommonformofsemaphoreisthe binarysemaphore, whichwillcontrolasingle resource, and


its value is initialized to 0.

Creationofsemaphore:
Theshmget() functioncreatesanewsemaphoreorobtainsthesemaphorekeyofan existing
semaphore.

#include<sys/sem.h>
intshmget(key_tkey,intnum_sems, intsem_flags);

The first parameter, key, is an integral value used to allow unrelated process to access the same
semaphore. The semaphorekeyis used onlybysemget. Allothers usethe identifier returnbythe semget().
There is a special key value IPC_PRIVATE whichallows to create the semaphore and
to be accessed only by the creating process.
The second parameteristhe numberof semaphores required,it isalmost always1.
Thethirdparameter isthesetofflags.Theninebitsarethepermissionsforthe semaphore.

Onsuccessit willreturnapositive value whichisthe identifierused bytheother semaphore


functions. On error, it returns -1.

Changingthe value:
Thefunctionsemop()isusedforchangingthevalueofthe semaphore.
#include<sys/sem.h>
intsemop(intsem_id,structsembuf
*sem_ops,size_tnum-_sem_ops);

Thefirstparameteristheshmidistheidentifierreturnedbythesemget().

Thesecondparameteristhepointerto anarrayofstructure.Thestructuremaycontainat least the


following members:

struct
sembuf{ shortsem
_num; short
sem_op; short
sem_flg;
}

214
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

The first member is the semaphore number, usually0 unless it is an arrayofsemaphore. The sem_op is
the value by which the semaphore should be changed. Generally it takes-1,which isoperationto wait
forasemaphoreand+1, whichistheoperationto signaltheavailabilityof semaphore.

Thethirdparameter, isthe flagwhichisusuallysetto SET_UNDO.Iftheprocessterminates without releasing the


semaphore, this allows to release it automatically.

Controlling the semaphore:


Thesemctl() functionallowsdirectcontrolofsemaphoreinformation.

#include<sys/sem.h>
intsemctl(intsem_id,intsem_num,int
command,.../*union semun arg */);

Thethirdparameteristhecommand,whichdefinestheactionto betaken.Thereare two common


values:
1.) SETVAL:Usedforinitializingasemaphoretoaknownvalue.
2.) IPC_RMID:Deletesthesemaphoreidentifier.

Filelocking with semaphores


//sem.c
#include <unistd.h> #include
<stdlib.h> #include <stdio.h>
#include
<sys/sem.h>#include<sys/ipc.
h> #include<sys/types.h>

unionsemun
{
intval;
structsemid_ds*buf;
unsigned

short
*array;};

static void del_semvalue(void);


static int set_semvalue(void);
static int semaphore_p(void);
static int semaphore_v(void);
static int sem_id;
//

215
J.B.INSTITUTEOFENGINEERINGAND
TECHNOLOGY
LinuxProgrammingNotes

staticint set_semvalue()
{
unionsemunsem_union;
sem_union.val = 1;
if(semctl(sem_id,0,SETVAL,sem_union)==-1) return(0);
return(1);
}

//

staticvoiddel_semvalue()
{
unionsemunsem_union;
if(semctl(sem_id,0,IPC_RMID,sem_union)==-
1)fprintf(stderr,"Failedtodeletesemaphore\n");
}

//
staticint semaphore_p()
{
struct sembuf sem_b; sem_b.sem_num
= 0; sem_b.sem_op = -1; /* P() */
sem_b.sem_flg=SEM_UNDO;
if(semop(sem_id,&sem_b,1) ==-1)
{
fprintf(stderr,"semaphore_pfailed\n"); return(0);
}
return(1);
}

//
staticint semaphore_v()
{
struct sembuf sem_b; sem_b.sem_num
= 0; sem_b.sem_op = 1; /* V() */
sem_b.sem_flg=SEM_UNDO;
if(semop(sem_id, &sem_b, 1)==-1)
{ fprintf(stderr,"semaphore_vfailed\n");
return(0);
}

216
J.B.INSTITUTEOFENGINEERINGAND
TECHNOLOGY

LinuxProgrammingNotes

return(1);
}

intmain(intargc,char*argv[])
{
inti;
int pause_time;
charop_char='O';
srand((unsignedint)getpid());
sem_id=semget((key_t)1234,1,0666|IPC_CREAT); if (argc > 1)
{
if(!set_semvalue())
{
fprintf(stderr,"Failedtoinitializesemaphore\n"); exit(EXIT_FAILURE);
}
op_char='X';
sleep(2);
}

for(i=0;i<10;i++)
{
if(!semaphore_p())exit(EXIT_FAILURE);
printf("%c", op_char);
fflush(stdout);
pause_time=rand()% 3;
sleep(pause_time);
printf("%c",op_char);fflush(stdout);

if (!semaphore_v())
exit(EXIT_FAILURE);pause_time= rand() % 2;
sleep(pause_time);
}
printf("\n%d-finished\n", getpid()); if
(argc > 1)
{
sleep(10);
del_semvalue();
} exit(EXIT_SUCCESS);
}

217
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

The functionset_semvalue()initializes the semaphore using the SETVALcommand


insemctl()function.Butthis isto be done before the usage of semaphore.
The functiondel_semvalue()is used to delete the semaphore by usingthe
commandIPC_RMIDinthesemctl()function.Thefunctionsemaphore_p()changesthe semaphore value to -1, which is
used to make the process to wait.

In the function semaphore_v(),the semop member of the structure sembuf is set to 1.By this the semphore
becomes available for the other processes because it is released.

218
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

UNIT-V:
SharedMemory

Kernelsupportforsharedmemory APIs for


shared memory,
SharedMemoryexample.

Sockets Introduction to
Berkeley SocketsIPCoveranetwork
Client/server model
SocketAddressstructures(UNIXdomain&internetdomain)
cket systemcallsforconnectionorientedprotocolandconnectionlessprotocol Example-client/server
programs- single client/server connection,
Multiplesimultaneousclients
Socketoptions
setsockopt
fcntlsystem calls
ComparisionofIPCmechanisms.

219
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes
UNITV
SharedMemoryandSockets

SharedMemory:
Shared memoryis a highlyefficient wayofdatasharing betweenthe runningprograms. It allows two unrelated
processesto access the same logical memory. It is the fastest formofIPC because all processes share the
same piece of memory. It also avoidscopyingdataunnecessarily.

As kernel does not synchronize the processes, it should be handled by the user. Semaphore can also be
used to synchronize the access to shared memory.

Usageofsharedmemory:
To use the shared memory, first of all one process should allocate the segment, and then each process
desiring to access the segment should attach the segment. After accessing the segment, each process
should detach it. It is also necessary to deallocate thesegmentwithoutfail.

Allocating the shared memory causes virtual pages to be created. It is important to note that allocating the
existing segment would not create new pages, but will return theidentifierfortheexistingpages.

Alltheshared memorysegmentsareallocatedasthe integralmultiplesofthesystem'spagesize, which is the


number of bytes in a page of memory.

Unixkernelsupport forsharedmemory

Thereisasharedmemorytableinthekerneladdressspacethatkeepstrackofallshared memory regions created



in the system.

Eachentryofthetablesstorethefollowing
 data:

1. Name
2. CreatoruserIDandgroupID.
3. Assignedowner userIDandgroupID.
4. Read-writeaccesspermissionofthe region.
5. Thetimewhenthelastprocessattachedtothe region.
6. Thetimewhenthelastprocessdetachedfromthe region.
7. Thetime whenthelastprocesschangedcontroldataoftheregion.
8. Thesize,inno.ofbytesofthe region.

UNIXAPIsforsharedmemory shmget
Openandcreateashared
 memory.

220
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Function
 prototype:

#include<sys/types.h> #include<sys/ipc.h>
#include<sys/shm.h>
intshmget(key_tkey,intsize, intflag );
Functionreturnsapositivedescriptorifitsucceedsor-1ifit
 fails.
Shmat
Attachasharedmemorytoaprocessvirtualaddress
 space.
Function
 prototype:

#include<sys/types.h> #include<sys/ipc.h>
#include<sys/shm.h>
void*shmat(intshmid,void*addr,intflag);

Functionreturnsthemappedvirtualaddressofhesharedmemoryifitsucceedsor-1ifit
 fails.

Shmdt
Detachasharedmemoryfromthe processvirtualaddress
 space.
Function
 prototype:

#include<sys/types.h> #include<sys/ipc.h>
#include<sys/shm.h>int shmdt ( void
*addr );
Functionreturns0ifitsucceedsor-1ifit
 fails.
Shmctl
Queryor changecontroldataofasharedmemoryordeletethe
 memory.

221
J.B.INSTITUTEOFENGINEERINGAND
TECHNOLOGY
LinuxProgrammingNotes


Functionprototype:
#include<sys/types.h> #include<sys/ipc.h>
#include<sys/shm.h>
intshmctl(intshmid,intcmd,structshmid_ds*buf);
Functionreturns0ifitsucceedsor-1ifit
 fails.

SharedmemoryExample

//shmry1.c
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<sys/shm.h>
#defineTEXT_SZ2048
struct shared_use_st
{
intwritten_by_you;
charsome_text[TEXT_SZ];
};
int main()
{
intrunning=1;
void *shared_memory = (void
*)0; struct shared_use_st
*shared_stuff; int shmid;
srand((unsignedint)getpid(
)); shmid =
shmget( (key_t)1234,
sizeof(struct
shared_use_st), 0666 |
IPC_CREAT );
if(shmid==-1)
{
fprintf(stderr,"shmget failed\n");

222
J.B.INSTITUTEOFENGINEERING
ANDTECHNOLOGY

exit(EXIT_FAILURE);
}
shared_memory=shmat(shmid,(void*)0,0); if
(shared_memory == (void *)-1)
{
fprintf(stderr,"shmatfailed\n");
exit(EXIT_FAILURE);
}

printf("MemoryAttachedat
%x\n", (int)shared_memory);

shared_stuff=(structshared_use_st
*)shared_memory;shared_stuff-
>written_by_you=0;while(running)

{
if(shared_stuff->written_by_you)
{

printf("You Wrote: %s",


shared_stuff->some_text);

sleep(rand()%4);shared_stuff-
>written_by_you=0;

if(strncmp(shared_stuff->some_text,
"end", 3)== 0)
{
running= 0;
}
}
}

if(shmdt(shared_memory)==-1)

{
fprintf(stderr,"shmdtfailed\n");
exit(EXIT_FAILURE);
}
if(shmctl(shmid,IPC_RMID,0)==-1)
{
fprintf(stderr,"failedtodelete\n");

223
J.B.INSTITUTEOFENGINEERINGAND
TECHNOLOGY

exit(EXIT_FAILURE);
}

exit(EXIT_SUCCESS);

//shmry2.c
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>

#include<sys/shm.h>

#defineTEXT_SZ2048 struct
shared_use_st
{
intwritten_by_you;
charsome_text[TEXT_SZ];
};
int main()
{
intrunning=1
void *shared_memory = (void *)0;
struct shared_use_st *shared_stuff;
char buffer[BUFSIZ];
intshmid;

shmid=shmget((key_t)1234, sizeof(struct
shared_use_st),
0666|IPC_CREAT);
if(shmid==-1)
{
fprintf(stderr,"shmgetfailed\n");
exit(EXIT_FAILURE);
}

shared_memory=shmat(shmid,
(void *)0, 0);
if(shared_memory==(void*)-1)
{
fprintf(stderr,"shmatfailed\n");
exit(EXIT_FAILURE);

224
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

printf("Memory Attached at %x\n", (int)


shared_memory);shared_stuff=(structshared_use_st
*)shared_memory;while(running)
{
while(shared_stuff->written_by_you==1)
{
sleep(1);
printf("waitingforclient................\n");
}
printf("Enter Some Text: ");fgets
(buffer, BUFSIZ, stdin);
strncpy(shared_stuff->some_text,
buffer, TEXT_SZ); shared_stuff-
>written_by_you=1;if(strncmp(buffer, "end", 3) ==
0)
{
running= 0;
}
}
if(shmdt(shared_memory)==-1)
{
fprintf(stderr,"shmdtfailed\n");
exit(EXIT_FAILURE);
} exit(EXIT_SUCCESS);
}

The shmry1.c program will create the segment using shmget() function and returns the
identifiershmid.Thenthatsegment isattachedtoitsaddressspaceusing shmat()function.

Thestructureshare_use_stconsistsofaflag written_by_you isset to1whendataisavailable. When it is set,


programreads the text, prints it and clears it to show it has read the data. The string end is used to quit
fromthe loop. After this the segment is detached and deleted.

Theshmry2.c programgetsand attachestothesame memorysegment. This ispossiblewiththe


helpofsamekeyvalue 1234used intheshmget()function. Ifthewritten_by_youtext isset,the processwillwait
untilthepreviousprocessreads it. Whenthe flag iscleared, thedataiswritten and sets the flag. This
programtoo willuse the string "end" to terminate. Then the segment is detached.

5.2Sockets

225
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

A socket is a bidirectional communication device that can be used to communicate withanother process on
the same machine or with a process running on other machines.Sockets are the only interprocess
communication we’ll discuss in this chapter thatpermit communication between processes on different
computers. Internet programs such as Telnet, rlogin, FTP, talk, and the World Wide Web use sockets.

For example, you can obtain the WWW page from a Web server using theTelnet program because they
both use sockets for network communications.To open a connection to a WWW server at
www.codesourcery.com, use telnet www.codesourcery.com 80.The magic constant 80 specifies a
connection to the Web server programming running www.codesourcery.com instead ofsome other
process.Trytyping GET / after the connection is established.This sends a message through the socket to the
Web server, which replies by sending the home page’s HTML source and then closing the connection—for
example:

%telnetwww.codesourcery.com 80
Trying 206.168.99.1...
Connectedtomerlin.codesourcery.com(206.168.99.1). Escape
character is ‘^]’.
GET/
<html>
<head>
<metahttp-equiv=”Content-Type”content=”text/html;charset=iso-8859-1”>
...
3. Notethat only WindowsNT cancreate a named pipe;Windows9x programs can formonly client
connections.
4. Usually,you’duse telnettoconnecta Telnetserverforremote logins.Butyoucan also use telnet to
connect to a server ofa different kind and then type comments directly at it.

IntroductiontoBerkeleysockets
Berkeley sockets (or BSD sockets) is a computing library with an application programminginterface (API) for
internet sockets and Unix domain sockets, used for inter-processcommunication (IPC).
ThislistisasummaryoffunctionsormethodsprovidedbytheBerkeley sockets API library:
 socket()createsanewsocketofacertainsockettype,identifiedbyanintegernumber, and allocates system
resources to it.
 bind()istypicallyusedontheserverside,andassociatesasocketwithasocket address structure, i.e. a
specified local port number and IP address.
 listen()isusedontheserverside, andcausesaboundTCPsockettoenterlisteningstate.
 connect() is used on the client side, and assigns a free local port number to a socket.In case of a TCP
socket, it causes an attempt to establish a new TCP connection.

226
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

 accept()isused onthe server side. It acceptsa received incoming attempt to create anew TCP connection
from the remote client, and creates a new socket associated with the socket address pair of this
connection.
 send()andrecv(),orwrite()andread(),orsendto()andrecvfrom(),areusedforsending and receiving data
to/from a remote socket.
 close() causesthesystemto releaseresourcesallocatedtoasocket.IncaseofTCP,the connection is
terminated.
 gethostbyname()andgethostbyaddr()areusedtoresolvehostnamesandaddresses. IPv4 only.
 select()isusedtopend,waitingforoneormoreofaprovidedlistofsocketstobe ready to read, ready to write, or
that have errors.
 poll()is used tocheck on the state of a socketin a set of sockets. The setcan be tested to see if any socket
can be written to, read from or if an error occurred.
 getsockopt() is used toretrievethe currentvalueof a particular socketoption for the specified socket.
 setsockopt()isusedtosetaparticularsocketoptionforthespecified socket.

IPCoveranetwork
Socket Concepts
Whenyoucreateasocket, youmustspecifythree parameters:
 communicationstyle,
 namespace,
 protocol.
Acommunicationstylecontrolshowthesocket treatstransmitted dataand specifies
thenumberofcommunicationpartners.Whendataissent throughasocket,it isackaged into
chunks called packets.The communication style determines how these
packetsarehandled and howtheyareaddressedfromthesendertothe receiver.

Connection styles guarantee delivery of all packets in the order they were sent. If
packetsarelostorreorderedbyproblems inthe network,thereceiverautomatically
requests their retransmission from the sender.
Aconnection-stylesocket islikeatelephonecall:Theaddressesofthesender and
receiver are fixed at the beginning of the communication when the connection
is established.
Datagram stylesdo notguaranteedeliveryorarrivalorder.Packetsmaybe lost or
reordered in transit due to network errors or other conditions. Each packet must
be labeled with its destination and is not guaranteed to be delivered.The system
guarantees only “best effort,” so packets may disappear or arrive in a different
order than shipping.
Adatagram-stylesocketbehavesmorelikepostalmail.Thesenderspecifies the
receiver’s address for each individual message.
Asocket namespace specifies how socket addresses are written. Asocket address identifies one
endofasocket connection.Forexample,socket addressesinthe “localnamespace”areordinary

227
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

filenames. In “Internet namespace,” a socket address is composed of the Internet address (also known as
an Internet Protocol address or IP address) of a host attached to the network and aport number.The port
number distinguishes among multiple sockets on the same host.
A protocol specifies how data is transmitted. Some protocols are TCP/IP, the primary
networkingprotocolsused bytheInternet;theAppleTalknetworkprotocol;andtheUNIXlocal communication
protocol. Not all combinations of styles, namespaces,and protocols are supported.

Client-serverdatagramsocket— example
Toexperiment withdatagramsocketsintheUNIXdomainwewillwritea client/server application
where:
 theclienttakesanumberofargumentsonitscommandlineandsendthemtothe server using separate
datagrams
 for each datagram received, the server converts it touppercase and senditback tothe client
 theclientprintsserverrepliestostandardoutput
Forthisto workwewillneed tobindallinvolved socketstopathnames.

Client-serverdatagramsocketexample—protocol
#include <ctype .h> #include
<sys/un.h>
#include<sys/socket.h>
#include <unistd .h> #include
" helpers .h"
#define SRV_SOCK_PATH " /tmp/uc_srv_socket "
#defineCLI_SOCK_PATH"/tmp/uc_cli_socket.%ld " #define
MSG_LEN 10
#include"uc proto.h"
int main( int argc , char *argv [ ] )
{ structsockaddr_unsrv_addr,cli_addr; int
srv_fd , i ;
ssize_t bytes ;
socklen_tlen;
charbuf[MSG_LEN];
if( (srv_fd=socket(AF_UNIX,SOCK_DGRAM,0)) <
0)err_sys("socket error");
memset(&srv_addr,0,sizeof(structsockaddr_un)); srv_addr .
sun_family = AF_UNIX ;
strncpy(srv_addr.sun_path,SRV_SOCK_PATH, sizeof
( srv_addr . sun_path ) 1) ;
if(access(srv_addr.sun_path,F_OK)== 0) unlink ( srv_addr .
sun_path ) ;
if(bind(srv_fd,(structsockaddr*)&srv_addr, sizeof ( struct
sockaddr_un ) ) < 0)
err_sys("bind error");

228
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

for(;;){
len= sizeof(structsockaddr_un);
if((bytes=recvfrom(srv_fd,buf,MSG_LEN, 0, ( struct
sockaddr * ) &cl i_addr , &len ) ) < 1) err_sys ( " recvfrom
error " ) ;
printf( "server received%ldbytes from%s\n"
,(long)bytes,cli_addr.sun_path); for ( i = 0; i <
bytes ; i ++)
buf[i]=toupper((unsignedchar)buf[i])
;if(sendto (srv_fd ,buf,bytes,0,
( structsockaddr *)&cli_addr ,len) !=bytes
)err_sys("sendto error");
}
}
#include"uc proto.h"
int main( int argc , char *argv [ ] )
{ structsockaddr_unsrv_addr,cli_addr; int
srv_fd , i ;
size_t len ;
ssize_tbytes;
charresp [MSG_LEN]
;if(argc<2)
err_quit("Usage : uc c lientMSG...");
if( (srv_fd=socket(AF_UNIX,SOCK_DGRAM,0)) <
0) err_sys("socket error");
memset(&cli_addr,0,sizeof(structsockaddr_un)); cl i_addr .
sun_family = AF_UNIX ;
snprintf( cli_addr .sun_path, sizeof( cli_addr .sun_path)
,CLI_SOCK_PATH,(long)getpid( ));
if(bind(srv_fd,(structsockaddr*)&cli_addr, sizeof ( struct
sockaddr_un ) ) == 1)
err_sys("bind error");

Notes:
theserverispersistentandprocessesonedatagramatatime,nomattertheclientrocess,
i.e.thereisnonotionofconnectionmessageslargerthan10bytesaresilentlytruncated

Socketaddressstructures(UNIXdomain&Internetdomain) UNIX domain


Sockets:
We now want to give an example ofstreamsockets. To do so, we can longer remain in the
abstractofgeneralsockets, butweneedtopickadomain. WepicktheUNIXdomain. Inthe UNIX domain,
addresses are pathnames. The corresponding Cstructure is sockaddr_un: struct sockaddr_un {
sa_family_tsun_family;/*= AF_UNIX*/

229
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

charsun_path[108];/*socketpathname, NULL
terminated */
}
The fieldsun_pathcontainsaregularpathname,pointingto aspecialfileoftypesocket(.pipe) which will be
created at bind time.
Duringcommunicationthe filewillhaveno content,it isusedonlyasa rendez-vouspoint between
processes.

Internet-DomainSockets

UNIX-domain sockets can be used only for communication between two processes on the same computer.
Internet-domain sockets, on the other hand, may be used to connect processes on different machines
connected by a network.
Sockets connecting processes through the Internet use the Internet namespace represented by
PF_INET.The most common protocols are TCP/IP.The Internet Protocol (IP), a low-level protocol, moves
packets through the Internet, splitting and rejoining the packets, if necessary. It guarantees only “best-
effort” delivery, so packets may vanish or be reordered during transport. Every participating computer is
specified using a unique IP number.The Transmission Control Protocol (TCP), layered on top of IP, provides
reliable connection-ordered transport. It permits telephone-like connections to be established between
computers and ensures that data isdelivered reliably and inorder.

DNSNames
Because it is easier to remember names than numbers, the Domain Name Service (DNS) associates names
such as www.codesourcery.com with computers’ unique IP numbers. DNS is implemented by a worldwide
hierarchy of name servers, but you don’t need to understand DNS protocols to use Internet host names in
your programs.
Internet socket addresses contain two parts: a machine and a port number.This information is stored in a
struct sockaddr_in variable. Set the sin_family field to AF_INET to indicate that this is an Internet
namespace address.The sin_addr field stores the Internet address of the desired machine as a 32-bit
integer IP number.A port number distinguishes a given machine’s different sockets. Because different
machines store multibyte values in different byte orders, use htons to convert the port number to
network byte order. See the man page for ip for more information.To convert human-readable hostnames,
either numbers in standard dot notation (such as 10.0.0.1) or DNS names (such as www.codesourcery.com)
into 32-bit IP numbers, you can use gethostbyname.This returns a pointer to the struct hostent structure;
the h_addr field contains the host’s IP number.

SystemCalls
Socketsaremoreflexiblethanpreviouslydiscussedcommunication techniques.These are
the system calls involving sockets:

socket—Creates a socket closes


—Destroysasocket
connect—Createsaconnectionbetweentwosockets bind—Labels
a server socket with an address

230
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

listen—Configuresasockettoacceptconditionsaccept—
Acceptsaconnectionandcreatesanewsocket forthe connection Sockets
are represented by file descriptors.

CreatingandDestroying Sockets

SocketsareIPCobjectsthatallowtoexchangedatabetweenprocessesrunning: either on
the same machine (host), or on different ones over a network.
The UNIX socket API first appeared in 1983 with BSD 4.2. It has been finally standardized for the first time in
POSIX.1g (2000), but has been ubiquitous to everyUNIX implementation since the 80s.
The socket API is best discussed in a network programming course,which this one isnot. Wewill onlyaddress
enoughgeneralsocketconceptsto describe how to use a specific socket family: UNIXdomain sockets.

ConnectionOriented Protocol

231
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

ConnectionlessProtocol

Client-serversetup
Let’sconsideratypicalclient-serverapplicationscenario —no matteriftheyare locatedon the same or
different hosts.
Socketsareusedasfollows:each
application: create a socket
idea:communicationbetweenthetwoapplications will flowthroughanimaginary“pipe”that
willconnectthetwosocketstogether
server: binditssockettoawell-knownaddress
wehavedonethesametosetuprendez-vouspoints forother IPCobjects.
e.g.FIFOs
client:locateserversocket(via itswell-knownaddress)and “initiatecommunication”1withthe server.

Socketoptions:

Inordertotellthesockettogettheinformationaboutthepacket destination, weshould call


setsockopt().
setsockopt() and getsockopt() - set and get options on a
socket.Bothmethodsreturn0 onsuccessand -1 onerror.
Prototype:intsetsockopt(intsockfd,intlevel,intoptname,... There are
two levels of socket options:

232
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

TomanipulateoptionsatthesocketsAPIlevel: SOL_SOCKET
To manipulate options at a protocol level, that protocol number should be used;
forexample, forUDPit isIPPROTO_UDPorSOL_UDP(bothareequal17);see include/linux/in.h
and include/linux/socket.h
● SOL_IPis0.
● Therearecurrently19Linuxsocketoptionsandoneanotheronoptionfor BSD
compatibility.
● ThereisanoptioncalledIP_PKTINFO.

WewillsettheIP_PKTINFOoptiononasocketinthe following example. //


from /usr/include/bits/in.h
#defineIP_PKTINFO8/*bool */
/*StructureusedforIP_PKTINFO.*/ struct
in_pktinfo
{
intipi_ifindex;/*Interface index*/
structin_addripi_spec_dst;/*Routingdestinationaddress*/ struct
in_addr ipi_addr; /* Header destination address */
};
constinton=1;
sockfd=socket(AF_INET,SOCK_DGRAM,0);
if(setsockopt(sockfd,SOL_IP,IP_PKTINFO,&on, sizeof(on))<0)
perror("setsockopt");
...
...
...
When calling recvmsg(), we will parse the msghr like this: for
(cmptr=CMSG_FIRSTHDR(&msg); cmptr!
=NULL;cmptr=CMSG_NXTHDR(&msg,cmptr))
{
if(cmptr->cmsg_level== SOL_IP &&cmptr->cmsg_type ==IP_PKTINFO)
{
pktinfo =(structin_pktinfo*)CMSG_DATA(cmptr);
printf("destination=%s\n",inet_ntop(AF_INET,&pktinfo->ipi_addr,str,sizeof(str)));
}
}
Inthekernel,thiscallsip_cmsg_recv() in
net/ipv4/ip_sockglue.c.(whicheventually calls
ip_cmsg_recv_pktinfo()).
● Youcaninthiswayretrieveotherfieldsofthe ip header:
For getting the TTL:
● setsockopt(sockfd,SOL_IP,IP_RECVTTL,&on,sizeof(on))<0).
● But:cmsg_type==IP_TTL. For
getting ip_options:
● setsockopt()withIP_OPTIONS.

233
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

fcntlsystem calls
Thefcntlsystemcallprovides furtherwaystomanipulatelowlevelfiledescriptors.

Itcanperformmiscellaneousoperationsonopenfiledescriptors. The
call,

returnsanew filedescriptorwithanumericalvalueequaltoorgreaterthanthe integer newfd. The call,

returnsthefiledescriptorflagsasdefinedin fcntl.h. The


call,

isusedtosetthefiledescriptorflags,usuallyjust FD_CLOEXEC. The calls,


respectivelygetandsetthefilestatusflagsandaccessmodes.

234
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

5.9ComparisionofIPCmechanisms.
IPCmechanismsaremianly5types
1. pipes:it isrelateddataonlysend fromonepipe outputisgivingto anotherpipe inputto share resouses pipe are used drawback:itis only related process only communicated
2. messagequeues:messagequeuesareunrelatedprocessarealso communicatewith message queues.
3. sockets:socketsalsoipcitiscomunicateclientsandserver
withsocketsystemcallsconnectionorientedandconnectionlessalso
4. PIPE:Onlytwo related(eg:parent&child)processesscanbe communicated.Data reading would be first in first out manner.
NamedPIPEorFIFO:Onlytwoprocesses(canbe relatedorunrelated)cancommunicate. Data read from FIFO is first in first out manner.
5. MessageQueues: Anynumberofprocessescanread/writefrom/tothequeue. Datacan be read selectively. (need not be in FIFO manner)
6. Shared Memory: Part of process's memory is shared to other processes. other processes can read or write into this shared memory area based on the permissions. Accessing
Shared memory is faster than any other IPC mechanism as this does not involve any kernel levelswitching(Shared memory resides on user memory area).
7. Semaphore:Semaphoresareusedforprocesssynchronisation.Thiscan'tbeusedforbulk data transfer between processes.

Introduction to Linux
OperatingSystem
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
Tableofcontents
LinuxProgrammingNotes
• Operatingsystemtasks

• UNIXhistory,Linuxhistory

• Linuxdistributions

• Linuxbasicfeatures

• BuildingOSkernels

• Linuxkernelmodules

• eBPF

• Kernelreports–whatisgoingoninthekernel

• Linuxstructureandkernelfunctions

• Basicconcepts

2
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes Computersystemlayers(source:Stallings,OperatingSystems)

OperatingSystemisaprogramthatmediatesbetweentheuserandthecomputerhardware.
• Hideshardwaredetailsofthecomputersystembycreatingabstractions(virtualmachines).

• Managesresources:memory,processor(CPU),input/output,communicationports

• Otheractivities:security,jobaccounting,errordetectingtools,etc.

3
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
UNIXhistory
LinuxProgrammingNotes

• Createdin1969;authors:KenThompson,DenisRitchiefromBellLaboratories,machine:oldPDP-7;had many features of MULTICS.


(BrianKernighanparticipatedinthecreationofUnix,heisco-authorofthefirstbookaboutC).

KenThompson Denis Ritchiedied12.10.2011 BrianKernighan


• 1973:UNIXrewritteninC(languagedesignedspecificallyforthispurpose).

• 1974:presentedonACMSymposiumonOperatingSystemsandinCACM,quicklygainingpopularity.

• Forhobbyists:Unixhistory,Unix,Linux,andvarianthistory.

• TheearlydaysofUnixatBellLabs,BrianKernighan(LCA2022online).

• KenThompsoninterviewedbyBrianKernighanatVCFEast2019.

4
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

5
UnixHistoryDiagram-shortversion(source:Wikipedia)
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

6
Linuxhistory
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY Linus Torvaldsin 2024
inconversation
LinuxProgrammingNotes
LinusTorvalds, Finland, born in withDirkHohndel
thesameyearasUNIX,i.e.1969, creator of the Linux kernel atOSSVienna
and the Git version control sysem. Linus Torvalds CurrentlyhiredbytheLinuxFoundation
announcingLinux 1.0,
30.03.1994

Richard Stallman, founder of the GNU project and theFree SoftwareFoundation,co- Richard Stallmanin 2019
creatoroftheGNUGPLlicense,creator of the Emacs editor, GCC compiler, GDB debugger.

May1991,version0.01:nosupportforthenetwork,limitednumberofdevicedrivers,one file system (Minix), processes with protected address spaces


TheLinuxKernelArchives–https://www.kernel.org/
– 2025-02-21,lateststableversion6.13.4

– 2025-02-16,latestmainline6.14-rc3
Numberingofthekernelversions–seeWikipedia AndrewTanenbaumin27023
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
Linuxstatisticsandfacts
LinuxProgrammingNotes

• 100%oftheworld’stop500supercomputersrunonLinux.(Blackdown)
• Linuxpowers53.1%ofwebsiteswhoseoperatingsystemisknown.(W3Techs)
• 96.3%oftheworld’stoponemillionwebservers runonLinux.(ZDNet)
• 90%ofallcloudinfrastructureoperatesonLinux,andpracticallyallthebestcloudhostsuse it.
• 90%ofHollywood’sspecialeffectsaremadeonLinux.(Wertsa)
• 47%ofprofessionaldevelopersuseLinux-basedoperatingsystems.(Statista)

• InJuly2022,2.76%ofalldesktopoperatingsystemsworldwideranonLinux.
• InJune2024,Linuxheldamarketshareof4.03%oftheglobaldesktopmarket.(ZDNet)
• Linux,thethirdmostpopulardesktopOS,hasamarketshareof2.09%.(Statista)
• Linuxpowers85%ofsmartphones.(HaydenJames)

https://truelist.co/blog/linux-statistics/
8
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
JonathanCorbetinOct.2024Kerne lReport:

LinuxProgrammingNotes

Roughly 14% of the code is part of the "core"(arch,kernelandmmdirectories), while


60% is drivers.

Linuxkernelversions(source:Wikipedia) 9
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
Linuxdistributions
LinuxProgrammingNotes
A set of ready-to-install, precompiled packages; tools for package installation and uninstallation
(RPM:RedHatPackageManager);kernel,butalsomanyserviceprograms;toolsforfilesystems management, creation and maintenance of user accounts, network management etc.

DistroWatchisawebsitewhichprovidesnews,popularity rankings, and other general information about Linux distributions as well as other free software/open source Unix-like
operating systems.

Debianused inlabsinMIMUW

2025-02-23(10topoutof270)

10
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
Linuxbasic features
LinuxProgrammingNotes

• Multi-accesssystem(withtimesharing)andmulti-tasking.

• Multiprocesssystem,simplemechanismstocreatehierarchyofprocesses,kernel preemption.

• Availableformanyarchitectures.

• Simplestandarduserinterfacethatcanbeeasilyreplaced(shellcommand interpreter).

• Hierarchicalfilesystems.

• Filesareseenasstringsofbytes(easytowritefilters).

• Loadingprogramsondemand(forkwithcopyonwrite).

• Virtualmemorywithpaging.

• Dynamicharddiskcache.

• Sharedlibraries,loadedintomemorydynamically(onecodeusedsimultaneouslyby
manyprocesses).

• CompliancewiththePOSIX1003.1standard.

• Differentformatsofexecutablefiles.

11
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
BuildingOS kernels
LinuxProgrammingNotes

• Monolithickernel(theonlysolutionuntilthe1980s)–Linuxbelongstothiscategory.

– thewholekernelrunsinasingleaddressspace,

– communicationviadirectfunctioninvocation.

• Microkernel(e.g.Mach,MINIX).

– functionalityofthekernelisbrokendownintoseparateprocesses(servers),

– someserversruninkernelmode,butsomeinusermode–allservershaveownaddressspaces,

– communicationishandledviamessagepassing,

– modularity–failureinoneserverdoesnotbringdownanother,oneservermaybeswappedout for another,

– contextswitchandcommunicationgenerateextraoverheadsocurrentlyusermodeserversare
rarelyused.
• Macrokernelor„Hybridkernel"(e.g.theMicrosoftWindowsNTkernelthatpowersalloperating systems in the Windows NT family, up to and including Windows11 and Windows
Server 2022, and powers Windows Phone 8, Windows Phone 8.1, Windows 10 Mobile, and the Xbox One and Xbox Series consoles).

12
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

LinusTorvalds:
Structureofmonolithickernel,microkernelandhybridkernel-basedoperatingsystems(source:Wikipedia)
“Astothewhole‘hybridkernel’thing-it’sjustmarketing.It’s‘oh,thosemicrokernelshadgoodPR,howcan wetry to get goodPR for our working kernel? Oh, I know, let’s use a cool
name and try to imply that it has all the PR advantagesthat that other system has’.”
Readings

1. Tanenbaum–Torvaldsdebateonkernelarchitecture(MINIXvsLinux)
• Wikipedia
• O’Reilly

2. ComparingLinuxandMinix,February5,2007,JonathanCorbet

13
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
Linuxkernelmodules
LinuxProgrammingNotes
• Linuxborrowsmuchofthegoodfrommicrokernels:modulardesign,capabilitytopreemptitself, support for kernel threads, capability to dynamically load separate binaries
(kernel modules).
• Modules–separatelycompiled,loadedintomemoryondemandanddeletedwhentheyarenolonger needed.
• Examples:adevicedriver,afilesystem,anexecutablefileformat.

• Advantages: saving memory (occupies memory only when it is needed), the error in the module does not cat/proc/modules
suspendthesystem,butonlyremovesthemodulefrom thememory,onecanuseconflictingdriverswithoutthe
need to restart the system, etc.
• Disadvantages???
• nameofthemodule
• memorysizeofthemodule,inbytes
• howmanyinstancesofthemodulearecurrently loaded
• ifthemoduledependsuponanothermodule(s)
14
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
But–eBPFmakesachange...
LinuxProgrammingNotes

ThomasGraf:WithBPF,we'restartingtoimplementamicrokernelmodelwherewecannowdynamicallyloadprograms, we can dynamicallyreplacelogic in a safe way, we can make logic


ExtendedBPF:ANewTypeofSoftware,BrendanGreggat
composable.We're eBPF–RethinkingtheLinuxKernel,ThomasGraf,QCon
goingaway from the requirementthat every singleLinux kernel changerequiresfull consensusacross the entire industry or across the entire developmentcommunity and 2020
instead, you can define your own logic, you can define your own modules and load them safely and with the necessary efficiency.
UbuntuMastersConf2019 (presentation,transcript) 15
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

ExtendedBPF:ANewTypeofSoftware,BrendanGreggatUbuntuMastersConf2019 (presentation, slides)

16
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

ExtendedBPF:ANewType of
Software,Brendan Gregg at Ubuntu
Masters Conf 2019

(presentation,slides)
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

http://brendangregg.com 17
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
2018,newCode of Conduct
LinuxProgrammingNotes

LinuxDevelopment LinuxDevelopmen
WhatisBPF?
Highlyefficientsandboxedvirtual machine in
the Linux kernel making the Linux kernel
programmable at native execution speed.
Programmability allows to
continuouslyadapttochanging requirements
and innovate quickly.
HowtoMakeLinuxMicroservice-AwarewithCiliumandeBPF,ThomasGraf,QCon2018, (presentation, transcript)

18
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

eBPF–RethinkingtheLinux
Kernel,ThomasGraf,QCon 2020

(presentation,transcript)

The runtime accepts bytecode, verifiesit,just-in-


timecompilesit, and runs it at the requested hook point.

19
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Accessedviafiledescriptors 2

eBPF–RethinkingtheLinux
Kernel,ThomasGraf,QCon 2020

(presentation,transcript)
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
eBPF–
summary
LinuxProgrammingNotes

• eBPFisaprogramminglanguageandruntimetoextendoperatingsystems.

• eBPFislikeJavaScriptbutforkerneldevelopers.
AlexeiStarovoitov
• In-kerneljust-in-timecompiler.

• eBPFfeatures
– Secure(runtimeverification,sandboxconcept,programsigning),
– Efficient(JITcompiler,embeddedinOS,per-CPUdatastructures), TheBeginner’sGuidetoeBPF,LizaRice(live
programming+sourcecode) WhatiseBPF?–
– Portable(genericbytecode,datatypediscovery,stableAPItoOS). eBPF portal
• Manyplacestoattachprograms:packetfilters,tracepoints, BPFatFacebook,PerformanceSummit2019,Alexei
Starovoitov
securitypolicies,...
atFacebook,(slides)KernelRecipes2019,Alexei Starovoitov
• Enabletheadditionofnewfunctionality–nokernelhacking required. AthoroughintroductiontoeBPF(fourarticlesin lwn.net), Matt Fleming, December 2017.
compilercollection(BCC-ToolsforBPF-basedLinux IO analysis, networking,
• Highlyflexiblekernelconfiguration. monitoring, and more )
• eBPFiscontrolledbytheeBPFFoundation(Meta,Google, Isovalent, Microsoft, RedHat, Netflix, …)

21
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
eBPF–officialdocumentary
LinuxProgrammingNotes
https://www.youtube.com/watch?v=Wb_vD3XZYOA(30min)
In 2014,a group of engineers at Plumgrid needed to find an innovative and cost-effective solution to
handlenetworktrafficinSDNenvironments.Whattheycreatedwasalandmarkintheindustryknown as the extended Berkeley Packet Filter (or eBPF). This vital technology allows user-level
code execution inside the Linux Kernel, transforming network traffic handling for SDN environments.
Whethertheseengineersknewitornot,theyhadjustrevolutionizedtheLinuxKernel.
– GrowthofLinuxandSDN
– PLUMgrid ThomasGraf
DanielBorkmann Chris
– InitialPatchSubmission Wright
– eBPFMergedintotheLinuxKernel Liz Rice
PurviDesai(Google)
– HyperscalersAdopt eBPF
DavidMiller(networkkernelmaintainer) Alexei Starovoitov
– CiliumBringeBPFtoEndUsers BrendanGregg
– DockerCon2017eBPFTakesOff DaveThaler(Microsoft)
– eBPFExpandstoSecurity
– eBPFonWindows
– eBPFEverywhere
https://ebpfdocumentary.com/

22
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
Whatisgoingoninthekernel–kernelreports
LinuxProgrammingNotes

This talk will review recent events in the kernel development community, discussthecurrentstateofthekern
• TheKernelReport,JonathanCorbet,OpenSourceSummit2024Japan(October2024,21min)

• TheKernelReport,JonathanCorbet,OpenSourceSummit2024NorthAmerica(April2024,42 min)

• TheKernelReport,JonathanCorbet,OpenSourceSummit2023

• TheKernelReport,JonathanCorbet,OpenSourceSummit2022

• TheKernelReport,JonathanCorbet,LinuxPlumbersConference2021(startingfrom6:45)

• TheKernelReport,JonathanCorbet,LPC2020,2020edition.

• TheKernelReport,JonathanCorbet,linux.conf.au2019edition.

• LinuxWeeklyNews

– Kernelindex
JonathanCorbet,Executive Editor, LWN.net & Kernel Documentatio
– Conferenceindex

23
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
TheKernelReport2024–whattoexpectin2025?
LinuxProgrammingNotes

• Rust(CommitingtoRustinthekernel)
– Memory-safesystemsprogramming,eliminateswhole classesofbugs.
– FirstmergedinOctober2022for6.1(asanexperiment),slowdevelopment.
– ConclusionfromtheKernelMaintainersSummitin2024:Rustinthekernelisviable.
– Rustconcerns–noteasytolearn,languagestability,Rust/CAPIcorrespondence,getting abstractions upstream – if they are not used
yet.
– Whatmightbemerged(lotsifinfrastructure,Nova–NVIDIAGPUdriver,AppleGPU
driver).
• CPUscheduler creativity
– FordecadestherecouldbeonlyoneCPUscheduler.
– Sched_ext–anewschedulingclass,basedonBPF,mergedinNovember2024for6.12.
• AnybodycanwriteaCPUscheduler.
• Quickandsafeiteration.
• Focusononeusecase.

• Security
– TheproblemswithCVE(CommonVulnerabilitiesandExposure)numbers
• ManyvulnerabilitiesnevergetCVEs.
• ThekernelisnowaCNA–CertficateNumberingAuthority.
2
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
TheKernelReport2024–whattoexpectin2025?
LinuxProgrammingNotes

• Bettertools
– Thekernelcommunityhasbeenslowtoadoptnewtools.
– Patchmanagement(b4continuestoimprove).
– Bugtracking(bugzilla,bugspray–beingdeveloped,regressiontracking–currentlyunfunded).
– Testing(kernelselftestsgrowing,KernelCI,stableupdatetesting).

• Darkareas inthekernel
– Documentation.
– Buildsystem. Summary

– Manycore-kernel areas.
– Driversforolderhardware.
– Maintainers(lacksupport,burned-out,frustrated,…)

25
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
TheKernelReport2024
LinuxProgrammingNotes

• BPF
– BPFTokens(fine-grainedcapabilitiesforloadingBPFprograms)–moresecurity.
– BPFArena–mechanismforsharingmemorybetweenBPFprogramsrunninginthekernelanduser
spaceprograms.
– Fuse-BPF.
– BPFnetworkdevice. Notimefor

– Challenges(complexity,resistancelikesched_ext).

• Confidentialcomputing
– Securityinahostileenvironment.
– Howtore-establishtrust?
– Asecure,verifiedbootchain.
– CPUattestation.
– Encryptedmemory.
– Vendorsworkingonsupportingthisidea(AMDSEV+SNP,IntelTDX,ARMCCA).

Slides:https://lwn.net/talks/2024/kr-ossna.pdf

26
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
2024KernelMaintainersSummitgroupphoto
LinuxProgrammingNotes

27
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
TheKernelReport2023
LinuxProgrammingNotes
• Rust

– Hasalottooffer(astrongertypesystem,noundefinedbehavior,attractivetonewer developers).

– Whynot Rust in the kernel (a new language adds complexity, the language is still evolving –
quickly,maintainerswillneedtolearnRust,adifficultlearningcurve,lotsofgluecode,some things are hard to do in Rust, conservatism).
– InitialRustinfrastructurehasbeenmergeintoLinux6.1(October2022).

– Moresupportcodeinsubsequentkernels(accesstoexistingtypesandfunctions…butsafer).

– ApairodRustkernelmodules(NVMExpressdriver,9Pfilesystemserver)

– Nothinginaproductionkernelyet,nothingthatanybodyisactuallyusing.

– Rustsupportwasmergedasanexperiment.

– TheRustdecisionpointiscomingsoon.

Rust-for-LinuxdeveloperMiguelOjeda

28
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
TheKernelReport2023
LinuxProgrammingNotes

• Themaintainershipcrisis
– Increasingdemands.
– Understaffing.
– Lackofemployersupport(manymaintainers arenotpaidtomaintain).
– Kernelfuzzers(badqualitybugreports).
– Maintainers.
• Anunparalleleddepthofskillsand experience.
• Butalsoresistancetochange(e.g.Rust),lackofdiversity,increasinglytired single points of failure.
• Preparingforchange(sharedmaintenanceduties,documentation, investment in tools).
– Linux Kernel Contribution Maturity Model https://www.kernel.org/doc/html/latest/process/contribution-maturity-model.html
Slides:https://lwn.net/talks/2023/kr-osseu.pdf

29
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
2023KernelMaintainersSummitgroupphoto
LinuxProgrammingNotes

30
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
TheKernelReport2022
LinuxProgrammingNotes

• Io_uring
– Systemcallsslowdownyourprogram.
– Sharedmemoryarea(user,kernel).
– Whatit brings
• Asynchronousoperations.
• Submission/resultswithoutsystemcalls.
• Registeredfilesandbuffers.
• Awide rangeof commands.
• Chained operations.
When the kernel encounters a chain, it will only initiate the first operation; the next
operationinthechainwillonlyrunafterthe first completes.
– User-spaceblockdriverusingio_uring(ublk)

io_uringisanalternative,high-performanceAPIthatruns
withinthe kernel
– Isio_uring thebasisforfuturemicrokernelarchitecture?

31
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
tions Basic concepts
LinuxProgrammingNotes

• Linuxstructureandkernelfunctions
• Basicconcepts–process,usermodeandkernelmode,contextswitch,systemcalls, user stack and kernel stack, process state transitions
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
Linux–thestructureandfunctionsofthekernel
LinuxProgrammingNotes

33

Source:Wikipedia
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
Process,addressspace,context
LinuxProgrammingNotes
• Processisaprograminexecution;executionrunssequentially,accordingtotheorderof instructions in a process address space.
• Processaddressspaceisacollectionofmemoryaddresses,referencedbytheprocessduring execution.
• Processcontextisitsoperationalenvironment.Itincludescontentsofgeneralandcontrol registers of the processor, in particular:
– programcounter(PC),
– stackpointer(SP),
– processorstatusword(PSW),
– memorymanagementregisters(allowaccesstocodeanddataofa process).
• Linuxisamultiprogrammingsystem.Thekerneldynamicallyallocatesresourcesnecessaryfor processes to operate and provides security.
Forthispurpose,itneedshardwaresupport:
– processorexecutingintwomodes:usermodeandsystemmode(kernelmode),
– privilegedinstructionsandmemoryprotection,
– interruptsandexceptions.

34
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
Kerneladdressspace
LinuxProgrammingNotes

Systemaddress space or kernel space comprises code and kerneldatastructures. Access to them is only possible in system mode. The kernel has direct access to the address
space of the currentprocess.Occasionally,itcanreachuptoaddressspaceoftheotherprocessthanthecurrentone.
Kernelthreadisexecutedinkernelmode.
Thetransitiontotheexecutionofthekernelcodecanoccurasaresultofseveralevents:
– Theprocesscallsthesystemfunction(systemcall).Theuserprocessinstructsthekernelto perform certain actions (e.g. I/O operations) on its behalf.

– Theprocessorreportsexceptionwhileexecutingtheprocess,e.g.anon-existentinstruction.The kernel handles an exception on behalf of the process that caused it.

– An external device reports an interrupt to the CPU informing about the occurrence of an asynchronousevent,e.g.completionofaninput-
outputoperation.Interruptsupportishandled in the interrupt handling routine.

35
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
Contextswitching
LinuxProgrammingNotes

ContextSwitching–savingthecontextof the current process (in the


structure that is part of the process address space) and
loading the context of another process into the processor
registers.

Thecontextswitchtimeisanoverheadof the system and depends on


hardware support (can take from a few 100
nanosecondstoafewmicroseconds).
Measuringcontextswitchingandmemoryoverheads
Context switching itself has a cost in performance, due to runningthe task scheduler, TLB flushes, and
indirectlyduetosharingtheCPUcachebetweenmultipletasks.L2cachehavesubstantialimpactonthe cost of context switch.

36
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Transitionsbetweenuserandkernelmode,source:Bovet,Cesati

Interleavingofkernelcontrolpaths,source:Bovet, 37
Cesati
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
Systemfunctioncallwithint0x80
LinuxProgrammingNotes

source: Anatomyofthe Linux


kernel, M.Tim Jones

The details of the system function call depend on the architecture (the figure illustrates i386). The registereax
isusedtotransmitthenumberofthefunctionbeingcalled.Themachineinstructionint 0x80 calls the program interrupt 0x80 (decimal 128) –context switching and calling the kernel
functionsystem_call.The function transfers control to the proper system function (uses system_call_table with eax treated as an index).
Afterreturningfromthesystemfunction,thesyscall_exitfunctionisexecuted,theresume_userspace
38
functioncallreturnsthecontrolbacktotheuserspace.
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
Systemcallandprocessstacks
LinuxProgrammingNotes
Eachprocessusestwostacks:
– userstack–usedinusermode(growsdynamicallyduringprogramexecution),

– kernelstack–inkernelmode(hasafixed,small size);isusuallyallocatedinaddressspaceofthe process, but it can not be accessed in the user mode.

system_call()startsbysavingthe registers in the


kernelstack. After checking other things such as
validating parameters, it will call the respective
system call.

39
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
Systemcall–sequenceofsteps
LinuxProgrammingNotes
System calls: https://linux-kernel-labs.github.io/refs/heads/master/lectures/syscalls.htmlThis is what happens during a system call:

1. Theapplicationissettingupthesystemcallnumberandparametersanditissuesatrap
instruction.

2. Theexecutionmodeswitchesfromusertokernel;theCPUswitchestoakernelstack;theuser stack and the return address to user space is saved on the kernel stack.

3. Thekernelentrypointsavesregistersonthekernelstack.

4. Thesystemcalldispatcheridentifiesthesystemcallfunctionandrunsit.

5. Theuserspaceregistersarerestoredandexecutionisswitchedbacktouser(e.g.calling IRET).

6. Theuserspaceapplicationresumes.

Seealso:Shadowstacksforuserspace,Jonathan CorbetFebruary21,2022
Whenever a function is called, the return address is pushed onto both the regular stack and the shadow
stack.Whenthatfunctionreturns,thereturnaddressesarepoppedoffbothstacksandcompared;ifthey
failtomatch,thesystemgoesintoredalertandkillstheprocessinvolved. 40
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
Systemcallconventions
LinuxProgrammingNotes
DefinitionofthesystemfunctionfromtheClevel(fileinclude/linux/syscalls.h):
asmlinkagelongsys_exit(interror_code);
asmlinkagetellscompilertolookonthekernelstackforthefunctionparameters,insteadofregisters.
Inarchitecturex86theregisters ebx,ecx,edx,esiandediareusedtopassthefirstfiveparameters.If there are more parameters, it is throughone register that a pointer to the user's address
space is transferred, where all parameters are placed.
Thevaluepassedfromthesystemfunctionisplacedintheeaxregister.
Otherregistersareusedin64-bitarchitecture:
– x64Architecture,registers,callingconventions,addressingmodes
– syscallnumbers
Copyingdatabetweenthekernelspaceandtheuserspaceis done using copy_to_user() and copy_from_user().
Whenexecutingthesystemfunction,thekernelworksinthe contextof theprocess (thevariablecurrentpointstothe
currentprocess). 41
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
Sysenterandsysexit
LinuxProgrammingNotes
Machineinstructionssysenterand sysexitwereaddedtox86processors(newer
thanPentiumII).Theyallowafastertransition(return)tothekernelmodetoperformasystemfunctionthanusingtheintstatement.Supportforthis mechanism has been added to the Linux
kernel (SysenterBased System Call Mechanism in Linux 2.6).
Callingthex86 function
– 64-bitversion–defined inthe filearch/x86/entry/entry_64.S
– 32-bitversion–defined inthe filearch/x86/entry/entry_32.S
Contentofthesystemfunctiontable
– 64-bitversion–defined inthe filearch/x86/entry/syscalls/syscall_64.tbl
– 32-bitversion–defined inthe filearch/x86/entry/syscalls/syscall_32.tbl

Thisisthe beginning

Inotheroperatingsystems,therearemanymorefunctionsthan435inLinux5.6(32-bit). 42
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
Processandsystemcontext
LinuxProgrammingNotes
Contextofexecution–summary:
– usercodeisexecutedinusermodeandinprocesscontext,canonlyreachtheaddress space of the process,

– systemfunctionsandexceptions(e.g.dividingbyzeroorviolationofmemoryprotection) are supported in system mode, but in context of the process, they have access to the
process and system address space.
Thekernelactsonbehalfofthecurrentprocess(e.g.byexecutingasystemfunction),itcan reference the address space of the process and the process stack. It can also block the current
process if it has to wait for resources.
– interruptsarehandledinsystemmodeinthecontextofthesystemwithaccessonlytothe
systemaddressspace.
System-wide operations, such as recalculating priorities or handling an external interrupt. Notperformedonbehalfofanyparticularprocessandthereforetakeplaceinthecontextof the
system. The kernel does not reach to the address space or the stack of the current process, also it can not block.
43
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

Processstatetransitions
TheLinuxkernelispreemptableandre-entrant,itcansupportdifferentprocessesconcurrently. The process during execution changes
state.
Thebasicstatesoftheprocess are:
– new:theprocesshasbeencreated,

– ready:theprocessiswaitingforthe
processortobeallocated,
– executed(mor
eprecisely:executedin
usermodeorexecutedinsyste
mmode): process
instructions are executed,
– waiting:th
eprocessiswaitingforan
event to occur,
– fin
ished:theprocess
completed
execution.

Processstatesandstatetransitions,source:U.Vahalia,UNIXInternals:TheNewFrontiers
INTRODUCTION TO LINUXOPERATINGSYSTEM

ThirdSchoolonLHCPhysics
TaimoorKhurshid
ExpHighEnergyPhysicsGroup National Center for Physics
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
--------------------------------------------
LinuxProgrammingNotes
Asanillustrationofthewaythattheshellandthe
kernel work together, suppose a user types rm
myfile (which has the effect of removing the file
LINUXOPERATINGSYSTEM myfile). The shell searches the filestore for
LinuxoperatingsystemconsistsofKernel,ShellandFileSystem: thefilecontainingtheprogramrm,andthenrequest
Thekernel s the kernel, through system calls, to execute

 KernelisheartofLinuxOS
the program rm on myfile. When the process
rm

 ItmanagesresourceofLinuxOS
myfilehasfinishedrunning,theshellthenreturns
the UNIX prompt % to the user, indicating that

 Resourcesmeansfacilitiesavailablein Linux. For e.g. Facility


 Tostoredata,
 Printdataonprinter,
 Memory
 File management
 Kerneldecideswhowilluseresources,forhowlongand when.

 Itrunsyourprograms(orsetuptoexecutebinaryfiles).
 Thekernelactsasanintermediary betweenthecomputer hardware and various programs/application/shell.
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

LINUXOPERATINGSYSTEM
LinuxoperatingsystemconsistsofKernel,ShellandFileSystem:
TheShell
 Theshellisaprogramthatactsasaninterfacebetweenusersand kernel
 Itisacommandinterpreterandalsohasprogrammingcapabilityof its own.
 ShellTypes
 BourneShell(sh)(FirstshellbyStephenBourne)
 CShell(sh)
 KornShell(ksh)
 BourneAgainShell(bash)
 FilenameCompletionorTABcompletion
 History-Theshellkeepsalistofthecommandsyouhavetypedin
FileSystem
 Linuxtreatseverythingasafileincludinghardwaredevices. Arranged as a directory hierarchy.
 Thetopleveldirectoryisknownas“root(/)”.
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes
DIFFERENT SHELLS AVAILABLEINLINUX

Program Name
Shell Description

TheoriginalshellfromAT&T,availableonall UNIX machines


Bourneshell sh

Cshell csh ShelldevelopedaspartofBSD UNIX

Kornshell ksh AT&TimprovementoftheBourneshell

Bourneagain shell ShelldistributedwithLinux,versionofBourne shell that includes command line editing


bash and other nice things
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
--------------------------------------------
LinuxProgrammingNotes
Program which loaded on RAM is called a
Process.
FILESANDPROCESSES
 EverythinginLINUXiseitherafileoraprocess Program stored on a HD is called
 Aprocessisanexecutingprogramidentifiedbyaunique PID (process identifier). a file.
 Afileisacollectionofdata.Theyarecreatedbyusersusing text editors, running compilers etc.
 Examplesoffiles:
 Adocument(report,essayetc.)
 Aprogramtext(high-levelprogramminglanguage)
 Instructions:
 comprehensibledirectlytothemachine
 incomprehensibletoacasualuser
 forexample,acollectionofbinarydigits(anexecutableorbinary file);
 Adirectory,containingmixtureofotherdirectoriesandordinary files.
J.B.INSTITUTEOFENGINEERINGANDTECHNOLOGY
LinuxProgrammingNotes

DIRECTORYSTRUCTURE

 Allthefilesaregroupedtogetherinadirectory structure.
 Thefile-systemisarrangedinahierarchical structure, like an inverted tree.
 Thetopofthehierarchyistraditionallycalled
root(writtenasaslash/)
 Thefullpathtothefilereport.docis

"/home/its/ug1/ee51vn/report.doc"
DIRECTORIESINLINUX
Directory:/bin
/bincontainsthebinarieswhichareneededtorunLINUX. Directory: /boot
/boothasallthefilesrequiredforbootingLINUXonsystem.
Directory:/dev
/devhasthedevicesforallthefiles.
Directory:/etc
/etccontainstheconfigurationfilesofthevarioussoftware.
Normallynoonetouchthisdirectory.
Directory:/home
/homeislikeMyDocumentsinWindows.
Thiscontainstheusernameasthesubdirectory.
Directory:/lib
/libcontainsthesharedlibrariesrequiredforthesystemfiles.
DIRECTORIESINLINUX
Directory:/lost+found
/lost+foundcontainsthefileswhicharedamagedorwhichare not linked to any directory.
Thesedamagesareduetotheincorrectshutdown.
Directory:/mnt
Thisisthedirectoryinwhichwemountthedevices andother
file systems. Directory:/opt
Heretheoptionalsoftwaresareinstalled.
Directory:/root
Thedirectoryfortheuserroot
LINUXCOMMANDS
Commandstelltheoperatingsystemtoperformsetofoperations.
Thesyntaxformofthecommandsare
Commandoptions arguments
WecandivideLinuxcommandsintofollowingcategories

 FileHandling Archival
 TextProcessing Network
 SystemAdministration FileSystems
 ProcessManagement viCommands
LINUXCOMMANDS
 Primary–man(manual)pages.

 man<command>

showsallinformationaboutthecommand
 <command>--help

showstheavailableoptionsforthatcommand
 Secondary–Booksand Internet
FILEHANDLING
mkdir:
makedirectories
Usage:mkdir[OPTION]DIRECTORY...
eg.mkdirLHC_School
ls: list directory contents Usage:ls[OPTION]...[FILE]…
eg.ls,ls-l,lsLHC_School
changes directories Usage:cd[DIRECTORY]
cd: eg.cdLHC_School
FILEHANDLING
pwd: printsthenameofcurrentworkingdirectories Usage: pwd
eg.mkdirLHC_School
ViImproved,aprogrammerstexteditor Usage: vim [OPTION] [file]...
vim: eg.vimfile1.txt
copyfilesanddirectories
Usage:cp[OPTION]...SOURCE/DEST
cp: eg.cpsample.txtsample_copy.txt cp sample_copy.txt target_dir
FILEHANDLING
mv: move(rename)files
Usage:mv[OPTION]...SOURCE/DEST
eg.mvsource.txttarget_dir mv old.txt new.txt
remove files or directories Usage:rm[OPTION]…[file]...
rm: eg.rmfile1.txt,
rm-rfsome_dir
FILEHANDLING
find: searchforfilesinadirectoryhierarchy Usage:find[OPTION] [path] [pattern]
eg.findfile1.txt
find-namefile1.txt

history:
printsrecentlyusedcommands Usage: history
PATTERN
APatternisanexpressionthatdescribesasetofstrings which is used to give a concise description of a set, without having to list all elements.
Example:
ab*cdmatchesanythingthatstartswithaband ends with cd etc.
ls*.txt–printsalltextfiles
rm*.obj–removesallobjectfiles
TEXTPROCESSING
cat: concatenatefilesandprintonthestandard output…
Usage:cat [OPTION] [FILE]… eg.catfile1.txtfile2.txt
cat-nfile1.txt
displayalineoftext
Usage:echo[OPTION][string]... eg. echo I love Pakistan
echo: echo$HOME
--------------------------------------------

wc: word count

TEXTPROCESSING
grep: printlinesmatchingapattern
Usage:grep[OPTION]PATTERN[FILE]...
eg.grep-iapplesample.txt
wc: printthenumberofnewlines,words,andbytes in files…
Usage:wc[OPTION]...[FILE]...
eg.wc file1.txt wc-Lfile1.txt
TEXTPROCESSING
sort: sortlinesoftextfiles
Usage:sort[OPTION]...[FILE]...
eg. sort file1.txt sort-rfile1.txt
LINUXFILEPERMISSIONS
 3typesoffilepermissions–read,write,execute
 10bitformatfrom'ls-l'command

1 234 567 8910

filetype owner group others

eg. drwxrw-r-- means owner has all three permissions, grouphasreadandwrite,othershaveonlyreadpermission


readpermission–4,write–2,execute-1 eg. rwxrw-r-- = 764
673 = rw-rwx-wx
SYSTEMADMINISTRATIO
chmod:

N
changefileaccesspermissions
Usage:chmod[OPTION][MODE][FILE]
eg.chmod744calculate.sh
chown:
changefileownerandgroup
Usage:chown[OPTION]...OWNER[:[GROUP]]FILE...
eg.chownremomyfile.txt
su: changeuserIDorbecomesuper-user Usage: su [OPTION] [LOGIN]
eg.suremo,su
SYSTEMADMINISTRATIO
passwd:

N
updateauser’sauthenticationtokens(s) Usage:passwd [OPTION]
eg.passwd
who: showwhoisloggedon Usage: who [OPTION]
eg.who,who-b,who-q
PROCESSMANAGEMENT
ps:
reportasnapshotofthecurrentprocesses Usage:ps [OPTION]
eg.ps,ps-el
kill: tokillaprocess(usingsignalmechanism)
Usage:kill[OPTION]pid eg. kill -9 2275
ARCHIVAL

tar: toarchiveafile
Usage:tar[OPTION]DESTSOURCE
tar-cvf/home/archive.tar/home/original tar -xvf /home/archive.tar
packageandcompress(archive)files Usage: zip [OPTION] DEST SOURSE
zip: eg.ziporiginal.ziporiginal

list,testandextractcompressedfilesinaZIParchive
unzip: Usage:unzipfilename
eg.unziporiginal.zip
NETWORK

SSH: SSHclient(remoteloginprogram)
“sshisaprogramforloggingintoaremotemach
ineandforexecutingcommandsonaremotemachine”
:ssh[options][user]@hostname eg. ssh -Y guest@10.105.11.20
scp:
securecopy(remotefilecopyprogram)
“scpcopiesfilesbetweenhostsonanetwork”
Usage:scp[options][[user]@host1:file1][[user]@host2:file2]
eg.scpfile1.txtguest@10.105.11.20:~/Desktop/
FILESYSTEM
fdisk: partition manipulator eg.sudofdisk-l
mount:
mountafilesystem
Usage:mount-ttypedevicedir
eg.mount/dev/sda5/media/target
umount:
unmountfilesystems
:umount[OPTIONS]dir|device... eg.umount /media/target
FILESYSTEM
du: estimate file space usage Usage:du[OPTION]...[FILE]...
eg.du
reportfilesystemdiskspaceusage Usage:df [OPTION]... [FILE]...
df: eg.df
quota:
displaydiskusageandlimits Usage: quota [OPTION]
eg.quota-v
EDITORCOMMANDS

vi: ViImproved,aprogrammerstexteditor Usage: vim [OPTION] [file]...


e.g.vihello.c
gedit: AtextEditor.Usedtocreateandeditfiles. Usage: gedit [OPTION] [FILE]...
eg.gedit
Simpleandveryeasytousetexteditor
pico: Usage:pico[OPTION] eg. Pico
USINGALIASES

Aliases provide command-substitution functionality. They can be used to createnewcommandsormodifythedefaultbehaviourofexistingcommands


Syntax: alias<stringenteredbyuser>=<stringsubstitutedbytheshell>The alias command is used to view and create aliases
 calledwithnoarguments,itprintsoutthecurrentaliases
 aliasname=value createsanewalias
 customuseraliases arestoredin.bashrcor.cshrc

Examples:
aliasrm='rm-i' (changethebehaviourofrmtoconfirmdeletes)
alias ll ='ls-l| more' (createanewcommandforfriendlyfile listings)
ENVIRONMENTVARIABLE
S
Environment variables refers to global settings that control the function of theshellandotherLinuxprograms.Theyaresometimescalledglobalshell
variables
orinsimplewords
Theydefinetheuserenvironmentandarereadfrominitializationfileseach time a user logs in…
Toviewthevalueofavariable,type:
printenvVARNAME OR echo$VARNAME
Tocheckyourenvironment,type
printenv OR env
ToSetEnvironmentVariable
setenvEDITOR“vim”
Somecommonenvironmentvariables:
HOME: Yourhomedirectory(oftenbeabbreviatedas“~”)
PWD: Currentworking directory
EDITOR: User’spreferredtexteditor
ENVIRONMENTVARIABLE
S
Somecommonenvironmentvariables:
Setstheeditortobeusedbyprogramssuchasmail clients
PATH: Specifiesdirectoriestobesearchedforexecutables
SHELL: Thedefaultlogin shell
USER: Currentloggedinuser’sname
Thetypeofterminalyouarerunning(forexamplevt100,xterm, and ANSI)
Itisacolonseperatedsetofdirectorieswhere libraries should be searched for

Toreloadanyinitializationfilewithouthavingtologoutandloginagain,type
source<filename>
e.g.source~/.bashrc source ~/.tcshrc

Profilefiles:sessionstartupfilesarehiddenfiles,findthemviacommand“ls–a”….

.tcshrc .cshrc .bashrc etc…


USEFULVI EDITOR COMMANDS

Arrowkeys Movecursor ^G showcurrentfileandline


hjkl Sameasarrowkeys ^F forwardscreen
insert/i Inserttext ^B backwardscreen
x deleteacharacter ^D scrolldownhalfscreen
dw deletea word ^U scrolluphalf screen
dd deletea line go to the beginning of the specifiedline(enddefault), where n
3dd deletes3lines is a line number
u undopreviouschange searchpat(nextlinematching pat)
ZZ exitvi,savingchanges ^E scrollwindow downoneline
end insert or incompletecommand ^Y scrollwindowuponeline H top line on
(deleteorrubout) interrupts screen
eraselastcharacter (backspace)
lastlineon screen
^W eraselastword
middlelineon screen
Good Luck
OSS:(OpenSourceSoftware)

Open source software are user friendly and are available as commercial and free licenced
software.Therefore,theseareeasytousebyanyone,anywhere.Opensourceiseasilymodifiable as its core
code is publicly accessible.
OS(OperatingSystem)

Anoperatingsystem(OS)isacollectionofsoftwarethatmanagescomputerhardwareresources and provides


common services for computer programs. The operating system is a vital component of the system
software in a computer system.

LinuxoperatingSystem
Linux is a free open-source operating system based on Unix. Linux was originally created by Linus
Torvalds with the assistance of developers from around the globe. Linux is free to download, edit and
distribute. Linux is a very powerful operating system and it is gradually becoming popular throughout
the world.

AdvantagesofLinux:
Low cost: There is no need to spend time and huge amount money to obtain licenses since Linux and
much of it's software come with the GNU General Public License. There is no need to worry about any
software's that you use in Linux.
Stability: Linux has high stability compared with other operating systems. There is no need to reboot
the Linux system to maintain performance levels. Rarely it freeze up or slow down. It has a continuous
up-times of hundreds of days or more.
Performance: Linux provides high performance on various networks. It has the ability to handle large
numbers of users simultaneously.
Networking: Linux provides a strong support for network functionality; client and serversystems can be
easily set up on any computer running Linux. It can perform tasks like network backup more faster than
other operating systems.
Flexibility: Linux is very flexible. Linux can be used for high performance server applications, desktop
applications, andembeddedsystems.Youcaninstallonly theneededcomponentsfora particular use. You
can also restrict the use of specific computers.
Compatibility: It runs all common Unix software packages and can process all common file formats.
Wider Choice: There is a large number of Linux distributions which gives you a wider choice.
Eachorganization developandsupportdifferentdistribution.Youcan picktheoneyou likebest; the core
function's are the same.
Better use ofhard disk: Linux uses its resourceswell enough evenwhen the hard disk is almost full.

Multitasking: Linux is a multitasking operating system. It can handle many things at the same time.
Security: Linux is one of the most secure operating systems. File ownership and permissions make linux more
secure.

Opensource:LinuxisanOpensourceoperatingsystems.Youcaneasilygetthesourcecodefor linux and edit it to


develop your personal operating system.

ComponentsofLinux System

LinuxOperatingSystemhasprimarilythreecomponents
Kernel − Kernel is the core part of Linux. It is responsible for all major activities of this operating system. It
consists of various modules and it interacts directly with the underlying hardware. Kernel provides the required
abstraction to hide low level hardware details to system or application programs.
System Library − System libraries are special functions or programs using which application programs or system
utilities accesses Kernel's features. These libraries implement most of the functionalities of the operating
system and do not requires kernel module's code access rights.
SystemUtility−SystemUtilityprogramsareresponsibletodospecialized,individuallevel
tasks.

KernelModevsUserMo
de
Kernel component code executes in a special privileged mode called kernel mode with full access to all
resources of the computer. This code represents a single process, executes insingle address space and do not
require any context switch and hence is very efficient and fast. Kernel runs each processes and provides system
services to processes, provides protected access to hardware to processes.

Support code which is not required to run in kernel mode is in System Library. User programs and other system
programs works in User Mode which has no access to system hardware and kernel code. User programs/
utilities use System libraries to access Kernel functions to get system's low level tasks.

BasicFeatures

FollowingaresomeoftheimportantfeaturesofLinuxOperatingSystem.

Portable − Portability means software can works on different types of hardware in same way. Linux kernel and
application programs supports their installation on any kind of hardware platform.
Open Source − Linux source code is freely available and it is community based development project. Multiple
teams work in collaboration to enhance the capability of Linux operatingsystem and it is continuously evolving.

Multi-User − Linux is a multiuser system means multiple users can access system resources like memory/ ram/
application programs at same time.

Multiprogramming−Linuxisamultiprogrammingsystemmeansmultipleapplicationscanrun
at sametime.

Hierarchical File System − Linux provides a standard file structure in which system files/ user files are arranged.

Shell − Linux provides a special interpreter program which can be used to execute commandsof the operating
system. It can be used to do various types of operations, call application programs. etc.

Security − Linux provides user security using authentication features like password protection/ controlled
access to specific files/ encryption of data.

Architectu
re
ThefollowingillustrationshowsthearchitectureofaLinuxsystem−

ThearchitectureofaLinuxSystemconsistsofthefollowing layers

Hardwarelayer−Hardwareconsistsofallperipheraldevices(RAM/HDD/CPUetc).
Kernel−ItisthecorecomponentofOperatingSystem,interactsdirectlywithhardware,
provideslowlevelservicestoupperlayercomponents.
Shell−Aninterfacetokernel,hidingcomplexityofkernel'sfunctionsfromusers.Theshell takes
commandsfromtheuserandexecuteskernel'sfunctions.
Utilities−Utilityprogramsthatprovidetheusermostofthefunctionalitiesofanoperating systems.
KernelMode
In Kernel mode, the executing code has complete and unrestricted access to the underlying
hardware.ItcanexecuteanyCPUinstruction andreference any memoryaddress. Kernel modeis generally reserved
for the lowest-level, most trusted functions of the operating system. Crashes in kernel mode are catastrophic;
they will halt the entire PC.
User Mode
In User mode, the executing code has no ability to directly access hardware or reference memory. Code
running in user mode must delegate to system APIs to access hardware or memory. Due to the protection
afforded by this sort of isolation, crashes in user mode arealways recoverable. Most of the code running on
your computer will execute in user mode.

WindowsVs.LinuxFileSyst
em
In Microsoft Windows, files are stored in folders on different data drives like C: D: E:
But,inLinux,filesareorderedinatreestructurestartingwiththerootdirectory.
This root directory can be considered as the start of the file system, and it further branches out various other
subdirectories. The root is denoted with a forward slash '/'.
AgeneraltreefilesystemonyourUNIXmaylooklikethis.

TypesofFiles
In Linux and UNIX, everything is a file. Directories are files, files are files, and devices like Printer, mouse, keyboard
etc.are files.
Let'slookintotheFiletypesinmore detail.
GeneralFiles
GeneralFilesalsocalledasOrdinary files.Theycancontainimage,video, programor simplytext. They can be in ASCII
ora Binary format. These are the most commonly used files by Linux Users.
DirectoryFiles
These files are a warehouse for other file types. You can have a directory file within a directory(sub-
directory).You can take them as 'Folders' found in Windows operating system.

DeviceFiles:
In MS Windows, devices like Printers, CD-ROM, and hard drives are represented as drive letters
likeG:H:.InLinux,therearerepresentedasfiles.Forexample,ifthefirstSATAharddrivehad
threeprimarypartitions,theywouldbenamedandnumberedas/dev/sda1,/dev/sda2and
/dev/sda3.
Note:Alldevicefilesresideinthedirectory /dev/
All the above file types (including devices) have permissions, which allow a user to read, edit or execute (run)
them. This is a powerful Linux/Unix feature. Access restrictions can be applied for different kinds of users, by
changing permissions.
WindowsVs.Linux:Users
Thereare3typesofusersinLinux.
1. Regular
2. Administrative(root)
3. Service
RegularUser
A regular user account is created for you when you install Ubuntu on your system. All your files and folders are
stored in /home/which is your home directory. As a regular user, you do not have access to directories of other
users.
Root User
Other than your regular account another user account called root is created at the time of installation. The root
account is asuperuserwho can access restricted files, install software and has administrative privileges.
Whenever you want to install software, make changes to system files or perform any administrative task on
Linux; you need to log in as a root user.
Otherwise,forgeneraltaskslikeplayingmusicandbrowsingtheinternet,youcanuseyourregularaccount.
Serviceuser
Linux is widely used as a Server Operating System. Services such as Apache, Squid, email, etc. have their
ownindividualservice accounts.Having service accounts increases the security of your computer. Linux can allow
or deny access to various resources depending on the service.

InWindows,thereare4typesofuseraccounttypes.
1. Administrator
2. Standard
3. Child
4. Guest
WindowsVs.Linux:FileName Convention
In Windows, you cannot have 2 files with the same name in the same folder. While in Linux, you can
have 2 files with the same name in the same directory, provided they use different cases.
WindowsVs.Linux:HOMEDirectory
ForeveryuserinLinux,adirectoryiscreatedas/home/
Consider, a regular user account "Tom". He can store his personal files and directories in the
directory"/home/tom".Hecan'tsavefilesoutsidehisuserdirectoryanddoesnothaveaccessto directories of
otherusers. For instance,he cannotaccess directory "/home/jerry" of another user account"Jerry".
TheconceptissimilartoC:\DocumentsandSettingsinWindows.
WhenyouboottheLinuxoperatingsystem,youruserdirectory(fromtheaboveexample
/home/tom) is thedefault working directory. Hence the directory "/home/tom is also called the Home
directory which is a misnomer.
WindowsVs.Linux:KeyDifferences
Windows Linux

WindowsusesdifferentdatadriveslikeC:D:E Unix/Linuxusesatreelikeahierarchicalfilesystem.
to stored files and folders.

WindowshasdifferentdriveslikeC:D:E TherearenodrivesinLinux

Harddrives,CD- Peripheralslikeharddrives,CD-ROMs,printersarealso
ROMs,printersareconsidered as devices considered files in Linux/Unix

There are 4 types of user account types 1) Thereare3typesofuseraccounttypes1)Regular,2)Root


Administrator,2)Standard,3)Child,4)Guest and 3) Service Account

Administratoruserhasalladministrative Rootuseristhesuperuserandhasalladministrative
privileges of computers. privileges.

InWindows,youcannothave2fileswiththe Linuxfilenamingconventioniscasesensitive.Thus,sample
same name in the same folder and SAMPLE are 2 different files in Linux/Unix operating
system.
Inwindows,MyDocumentsisdefaulthome Foreveryuser/home/usernamedirectoryiscreatedwhichis
directory. called his home directory.
LinuxCommandLineTutorial:ManipulateTerminalwithCDCommands
The most frequent tasks that you perform on your PC is creating, moving or deleting Files. Let's look at various
options for File Management.
Tomanageyourfiles,youcaneitheruse
1. Terminal(CommandLineInterface-CLI)
2. Filemanager(GraphicalUserInterface-GUI)
WhylearnCommandLineInterface?
Eventhoughthe worldismovingtoGUIbased systems, CLIhasitsspecificuses andis widely used in scripting and
server administration. Let's look at it some compelling uses -
 Comparatively, Commands offer more options &are flexible. Pipingand stdin/stdout are immensely powerful
are not available in GUI
 Some configurations in GUI are up to 5 screens deep while in a CLIit's just a single command
 Moving, renaming 1000's of the file in GUI will be time-consuming (Using Control /Shift to select multiple files),
while in CLI, using regular expressions so can do the same task with a single command.
 CLI load fast and do not consume RAM compared to GUI. In crunch scenarios this matters.
Both GUI and CLI have their specific uses.For example,in GUI, performance monitoring graphsgiveinstant
visual feedbackonsystem health, while seeing hundreds of linesof logs in CLI is an eyesore.

Filesanddirectoryrelatedcommands
Command Meaning
cddirectory changetonameddirectory
cd changetohome-directory
cd~ changetohome-directory
cd.. changetoparentdirectory
pwd displaythepathofthecurrentdirector

Command Description

ls Listsallfilesanddirectoriesinthepresent working
directory

ls-R Listsfilesinsub-directoriesaswell
ls -a Listshiddenfilesaswell

ls -al Listsfilesanddirectorieswithdetailedinformation like


permissions, size, owner, etc.

cat>filename Createsanew file

catfilename Displaysthefilecontent

catfilefile2> file3 Joinstwofiles(file1,file2)andstorestheoutputin a new file


(file3)

mvfile"newfile path" Movesthefilestothe new location

mv filename Renamesthefiletoanew filename


new_file_name

sudo Allowsregularuserstorunprogramswiththe security


privileges of the superuser or root

rm Deletesa file

man Giveshelpinformationonacommand

Givesalistofallpastcommandstypedinthe current
terminal session
history

clear Clearstheterminal

mkdir Createsanewdirectoryinthepresentworking directory

mkdir Createanewdirectoryatthespecified path

rmdir Deletesa directory

mv Renamesadirectory

pr-x Dividesthefileintoxcolumns

pr-h Assignsaheadertothe file

pr-n DenotesthefilewithLineNumbers

lp-nc lpr Prints"c"copiesofthe File


c
lp-dlp-P Specifiesnameoftheprinter

apt-get Commandusedtoinstallandupdatepackages

mail -s 'subject' -c 'cc- Commandtosendemail


address' -b 'bcc-
address''to-address'

Command Meaning
lessfile displayafileapageatatime
headfile displaythefirstfewlinesofafile
tailfile displaythelastfewlinesofafile
grep'keyword'file searchafilefor keywords
wcfile countnumberoflines/words/charactersinfile

Command Meaning
command>file redirectstandardoutputtoa file
command>>file appendstandardoutputtoa file
command<file redirectstandardinputfroma file
command1|command2 pipetheoutputofcommand1totheinputof command2

cat file1 file2>file0 concatenatefile1andfile2tofile0

sort sortdata
who listuserscurrentlyloggedin

FilePermissionsinLinux/UnixwithExample
Linux is a clone of UNIX, themulti-user operating systemwhich can be accessed by manyusers simultaneously.
Linux can also be used in mainframes and servers without any modifications. But this raises security concerns
as an unsolicited or malign usercancorrupt, change or remove crucial data. For effective security, Linux
divides authorization into 2 levels.
1. Ownership
2. Permission
Theconceptof permissions andownershipiscrucialinLinux.Here,wewilldiscussbothof them. Let us start with the
Ownership.
OwnershipofLinuxfiles
EveryfileanddirectoryonyourUnix/Linuxsystemisassigned3typesofowner,givenbelow.
User
Auseristheownerofthefile.Bydefault,thepersonwhocreatedafilebecomesitsowner. Hence, a user is also sometimes
called an owner.
Group
A user- group can contain multiple users. All users belonging to a group will have the same access permissions
to the file. Suppose you have a project where a number of people require access to a file. Instead of manually
assigning permissions to each user, you could add all users to a group, and assign group permission to file such
that only this group members and no one else can read or modify the files.
Other
Any other user who has access to a file. This person has neither created the file, nor he belongs toa
usergroupwhocouldownthefile.Practically, itmeans everybody else. Hence,whenyou set the permission for
others, it is also referred as set permissions for the world.
Now, the big question arises how does Linux distinguishbetween these three user types sothat a user 'A'
cannot affect a file which contains some other user 'B's' vital information/data. Itis like you do not wantyour
colleague, whoworks on your Linux computer, to view your images. This is where Permissions set in, and they
define user behavior.
LetusunderstandthePermissionsystemon Linux.
Permissions
EveryfileanddirectoryinyourUNIX/Linuxsystemhasfollowing 3permissionsdefinedforall the 3 owners discussed
above.
 Read:Thispermissiongiveyoutheauthoritytoopenandreadafile.Readpermissionon a directory gives you the
ability to lists its content.
 Write:The right permission gives you the authority to modify the contents of a file. The write permission on a
directory gives you the authority to add, remove and rename files stored in the directory. Consider a scenario
where you have to write permission on file but do not have write permission on the directory where the file is
stored. You will be able to modify the file contents. But you will not be able to rename, move or remove the file
from the directory.
 Execute:In Windows, an executable program usually has an extension ".exe" and which you can easily run. In
Unix/Linux, you cannot run a program unless the execute permission is set. If the execute permission is not set,
you might still be able to see/modify the program code(provided read & write permissions are set), but not run
it.
Let'sseethisinaction ls - l on
terminal gives
ls- l

Here, we have highlighted'-rw-rw-r--'and this weird looking code is the one that tells us about the
permissions given to the owner, user group and the world.
Here,thefirst'-'impliesthatwehaveselectedafile.p>

Else,ifitwereadirectory,dwouldhavebeen shown.

Thecharactersareprettyeasyto remember.
r = readpermission
w=writepermission
x=executepermission
-= nopermission
Letuslookatitthisway.
Thefirstpartofthecodeis'rw-'.Thissuggeststhattheowner'Home'can:

 Readthefile
 Writeoreditthefile
 Hecannotexecutethefilesincetheexecutebitissetto'-'.
By design, many Linux distributions like Fedora, CentOS, Ubuntu, etc. will add users to a group
ofthesamegroupnameastheusername.Thus,auser'tom'isaddedtoagroupnamed'tom'.
Thesecondpartis'rw-'.Itfortheusergroup'Home'andgroup-members can:
 Readthefile
 Writeoreditthefile
Thethirdpartisfortheworldwhichmeansanyuser.Itsays 'r--'.Thismeanstheusercan only:
 Readthefile

Changingfile/directorypermissionswith'chmod'command
Sayyoudonotwantyourcolleaguetoseeyourpersonalimages.Thiscanbeachievedby changing file permissions.
Wecanusethe'chmod'commandwhichstandsfor'changemode'.Usingthecommand,we can set permissions
(read, write, execute) on a file/directory for the owner, group and the world. Syntax:
chmod permissions filename
There are 2 ways to use the command -
1. Absolutemode
2. Symbolicmode
Absolute(Numeric)Mode
Inthismode,filepermissionsarenotrepresentedascharactersbutathree-digitoctal number.
Thetablebelowgivesnumbersforallforpermissionstypes.

Number PermissionType Symbol

0 No Permission ---

1 Execute --x

2 Write -w-

3 Execute+ Write -wx

4 Read r--

5 Read+ Execute r-x


6 Read+Write rw-

7 Read+Write +Execute rwx

Let'sseethechmodcommandin action.

Intheabove-giventerminalwindow,wehavechangedthepermissionsofthefile'sampleto '764'.

'764'absolutecodesaysthefollowing:
 Ownercanread,writeandexecute
 Usergroupcan readandwrite
 Worldcanonly read
Thisisshownas'-rwxrw-r-
Thisishowyoucanchangethepermissionsonfilebyassigninganabsolutenumber.

SymbolicMode
In the Absolute mode, you change permissions for all 3 owners. In the symbolic mode, you can modify
permissions of a specific owner. It makes use of mathematical symbols to modify the file permissions.
Operator Description

+ Addsapermissiontoafileor directory

- Removesthepermission

= Setsthepermissionandoverridesthepermissionssetearlier.
Thevariousownersarerepresentedas-
User Denotations

u user/owner

g group

o other

a all

Wewillnotbeusingpermissionsinnumberslike755butcharacterslikerwx.Let'slookintoan example

ViEditor:
Vi is a command line text editor. As you would be quite aware now, the command line is quite a different
environment to your GUI. It's a single window with text input and output only. Vi has
beendesignedtoworkwithintheselimitationsandmanywouldargue,isactuallyquitepowerful as a result. Vi is
intended as a plain text editor (similar to Notepad on Windows, or Textedit on Mac) as opposed to a word
processing suite such as Word or Pages. It does, however have a lot more power compared to Notepad or
Textedit.

Asa resultyouhaveto ditchthemouse.EverythinginViisdoneviathekeyboard. Thereare two modes in Vi. Insert


(or Input) mode and Edit mode. In input mode you may input or enter content into the file. In edit mode you
can move around the file, perform actions such as deleting, copying, search and replace, saving etc. A
common mistake is to start entering commands without first going back into edit mode or to start typing input
without first going into insert mode. If you do either of these it is generally easy to recover so don't worry
toomuch.
When we run vi we normally issue it with a single command line argument which is the file you would like to
edit
>vifile name
PROCESSES:

Aprocess refers to aprogram in execution; it’s a running instance of a program. It is made up of the program
instruction, data read from files, other programs orinput from a system user.
Types of Processes

init
It is the first process executed by the kernel during the booting of a system. It is a
daemonprocesswhichrunstillthesystemisshutdown.Thatis why,itis theparent ofalltheprocesses.Firstofall,init
readsthescriptstoredinthefile/etc/inittab.Commandinit readstheinitialconfigurationscriptwhich basically take
care of everything that a system do at the time of systeminitialization like setting the clock, initializing the
serial port and so on.
Foreground processes (also referred to as interactive processes) – these are initialized and controlled through
a terminal session. In other words, there has tobe a user connected to the system to start such processes;
they haven’t started automatically as part of the system functions/services.

Backgroundprocesses(alsoreferredtoasnon-interactive/automaticprocesses)
–areprocessesnotconnectedtoaterminal;theydon’texpectanyuserinput.

Batchprocess
ProcesseswhichareinqueueorstackexecutesonebyoneinFIFOorderarecalled batch process.

Daemons

These are special types of background processes that start at system startup and keep running forever as a
service; they don’t die. They are started as system tasks (run as services), spontaneously. However, they can
be controlled by a user via the init process.

Whatisazombieprocess?

When a process finishes execution, it will have an exit status to report to its parent
process. Because of this last little bit of information, the process will remain in the
operating system’s process table as azombie process, indicating that it is not to be
scheduled for further execution, but that it cannot be completely removed (and its process
ID cannot be reused) until it has been determined that the exit status is no longer needed.

Whenachildexits,theparentprocesswillreceiveaSIGCHLDsignaltoindicate that
oneofitschildrenhasfinishedexecuting;theparentprocesswilltypicallycall thewait()system call
exitstatus,andwillcausethechildtobe reaped,orremovedfromtheprocess table.

ProcessStates:

As a process executes it changesstateaccording to its circumstances. Linux processes have thefollowing states:

Running
Theprocessiseitherrunning(itisthecurrentprocessinthesystem)oritisreadytorun(itis waiting to be assigned to one
of the system's CPUs).

Waiting
The process is waiting for an event or for a resource. Linux differentiates between two types of waiting
process;interruptibleanduninterruptible. Interruptible waiting processes can be interrupted by signals whereas
uninterruptible waitingprocesses are waiting directly on hardware conditions and cannot be interrupted under
any circumstances.
Stopped
Theprocesshasbeenstopped,usuallybyreceivingasignal.Aprocess thatisbeingdebuggedcan be in a stopped state.

Zombie
Thisisahaltedprocesswhich,forsomereason,stillhasa task_structdatastructurein the task vector. It is what it sounds
like, a dead process.

Linux/UnixProcessManagement:ps,kill,top,df,free,niceCommands What is a Process?


AninstanceofaprogramiscalledaProcess.Insimpleterms,anycommandthatyougiveto your Linux machine starts a
new process.

RunningaForegroundProcess
Tostartaforegroundprocess,youcaneitherrunitfromthedashboard,oryoucanrunitfrom the terminal.
WhenusingtheTerminal,youwillhavetowait,untiltheforegroundprocess runs.

RunningaBackgroundprocess
Ifyoustartaforegroundprogram/processfromtheterminal,thenyoucannotworkonthe terminal, till the program is up
and running.
Particular,data-intensivetaskstakelotsofprocessingpowerandmayeventakehoursto complete. You do not want your
terminal to be held up for such a long time.
Toavoidsuchasituation,youcanruntheprogramandsendittothebackgroundsothat terminal remains available to you.
Let's learn how to do this -
Fg
Youcanusethecommand"fg"tocontinueaprogramwhichwasstoppedandbringittothe foreground.
Thesimplesyntaxforthisutilityis:
fg jobname

Example
1. Launch'banshee'musicplayer
2. Stopitwiththe'ctrl+z' command
3. Continueitwiththe'fg'utility.

Let'slookatotherimportantcommandstomanageprocesses-
Top
ThisutilitytellstheuseraboutalltherunningprocessesontheLinuxmachine.

Press'q'onthekeyboardtomoveoutoftheprocessdisplay. The terminology


follows:
Field Description Example1 Example2

PID TheprocessID ofeach task 1525 961

User Theusernameoftask owner Home Root


PR PriorityCanbe20(highest)or-20(lowest) 20 20

NI Thenicevalueofa task 0 0

VIRT Virtualmemoryused(kb) 1775 75972

RES Physicalmemoryused(kb) 100 51

SHR Sharedmemoryused(kb) 28 7952

S Status S R

%CPU %of CPUtime 1.7 1.0

%MEM Physicalmemoryused 10 5.1

TIME+ TotalCPUtime 5:05.34 2:23.42

Command Commandname Photoshop.exe Xorg

PS
This command stands for 'Process Status'. It is similar to the "Task Manager" that pop-ups in a Windows
Machine when we use Cntrl+Alt+Del. This command is similar to 'top' command but the information displayed
is different.
Tocheckalltheprocessesrunningunderauser,usethecommand-
psux

Youcanalsochecktheprocessstatusofasingleprocess,usethesyntax -
psPID

Kill
ThiscommandterminatesrunningprocessesonaLinuxmachine.
TousetheseutilitiesyouneedtoknowthePID(processid)oftheprocessyouwanttokill
Syntax –
kill PID
To find the PID of a process simply type
pidofProcessname

Letustry itwithanexample.

CreationofProcess:

Thebelowgivenprogramshowshow tocreateaprocess:

#include<errno.h>
#include<stdio.h>
#include<unistd.h> Main()
{
pid_tpid
pid=fork();//this will create a new process if(pid==-1) //if the
process is not created
perror(“fork”);//printingtheerrormessage else if(pid==0)
printf(“thisisachildprocesswithpid:%d\n”,pid);
else
printf(“thisisaparentprocesswithpid:%d\n”,pid);
}

Compilingfileprocess.c
$gccprocess.c

Executingthecompiled file

$./a.out
Theoutputgeneratedbythisprogramis:
Thisisachildprocesswithpid:0
Thisisaparentprocesswithpid:5335

Fork()function:

System callfork()is used to create processes. It takes no arguments and returns a process ID. The purpose
offork()is to create anewprocess, which becomes thechildprocess of the caller. After a new child process is
created, bothprocesses will execute the next instruction following thefork()system call. Therefore, we have to
distinguish the parent from the child. This can be done by testing the returned value of fork():
 Iffork()returnsanegativevalue,thecreationofachildprocesswas unsuccessful.
 fork()returnsazerotothenewlycreatedchildprocess.
 fork()returns a positive value, theprocess IDof the child process, to the parent. The returned process ID is of
typepid_tdefined insys/types.h. Normally, the process ID isan integer. Moreover, a process can use function
getpid()to retrieve the process ID assigned to this process.
 the child process will have a parent process ID (PPID) which is same as the PID of the process that created it.
 Thechildprocesswillhaveauniqueprocessidentifier(PID),likeallotherprocessesin the system.
 Thechildprocessdoesnothavethepossibilitytoinheritanytimersfromits parent.
 ResourceutilizationandCPUtimerswillberesettozerointhechildprocess.
After the fork function completes its work, there exist two processes. Each process continues its execution from the
position, where fork() returns.
Syntaxoffork()function:
#include<sys/types.h>
#include<unistd.h>Pid_t
fork(void);

Vfork()function:

It is used for creating new processes without copying the page tables belonging to the
parentprocess.Vfork()isfasterthanafork().Itdoesnotmakeanycopyoftheparentprocessaddress
space, rather it will borrow the parents memory and thread of the control, until a call to exit or execve() is
occurred. The execve() executes the program pointed by specified filename. Whenever a new process is
created by using vfork(), the parent process is suspendedtemporarily and the child process will proceed by
borrowing the parent proess address space. This will be continued, until the child process calls execve() or exits
at which the parent process will be continued.
Vfork()functionsyntax:

#include<sys/types.h>
#include<vunistd.h>Pid_t vfork();

getpid()andgetppid()functions:
getpid(): the child process can acquire its own process ID by using getpid() function.
getppid():thechildprocesscanacquireitsparentprocessIDbyusinggetppid()function.

Wait()function:
Aprocessissaidtobeinwaitingstate,ifitneedssomeresourceforitsexecutionorsomeevent to occur.
Syntaxofwait()function:
#include<sys/wait.h>Int
wait(status)

Example:

#include<sys/wait.h>
#include<stdio.h>
#include<sys/wait.h> Main()
{
Int statuspr,pid,cpid;
Pid=fork();
If(pid!=0)
{
Printf(“processid%d”,pid);
Cpid=wait(&statuspr);
Printf(“childprocessisinwaitstate”);
}
Else
{
Printf(“processid%d”,getpid());
Exit()
}
Printf(“pid%disgoingtobe terminated:”,pid);
}
Reasonsforfailureofcreatinganewprocess

Thefollowingarethepossiblereasonsforthefailureofcreationofnew processes:
 TheresourcelimitonthenumberofprocessespermittedtoaparticularuserIDhasbeen exceeded.
 Thesystemwidelimitonthenumberofprocessesthatcanbecreatedhasbeen reached.

Scheduling
The scheduler is the component of the kernel that selects which process to run next. The scheduler (or process
scheduler, as it is sometimes called) can be viewed as the code thatdivides the finite resource of processor time
between the runnable processes on a system. The scheduler is the basis of a multitasking operating system
such as Linux. By deciding whatprocess can run, the scheduler is responsible for best utilizing the system and
giving the impression that multiple processes are simultaneously executing.

The idea behind the scheduler is simple. To best utilize processor time, assuming there are runnable processes,
a process should always be running. If there are more processes than processors in a system, some processes
will not always be running. These processes are waiting to run. Deciding what process runs next, given a set of
runnable processes, is a fundamental decision the scheduler must make.
Objectivesofscheduling:

Schedulingpolicydetermineswhentoswitchandwhatprocessto choose.Thefollowingare some of the scheduling


objectives:
 Toavoidprocess starvation
 Toachievegoodthroughputforbackgroundjobs
 Toimprovesystem performance
 Toenforce priorities
 Tominimisethewastedresources overhead
 Toachieveabalancebetweenaresponseand utilization
 Tosupportforsoftrealtime processes
Processesrunningforalongtimehavetheirprioritiesdecreased,whereastheprocesseswhich are waiting for a long
time will have their priorities increased dynamically.

CategoriesofProcesses:
I/Oboundprocesses:theprocesseswhichuseI/Odevices,andwaitforalongtimeforI/O operations to
complete, can be treated as I/O bound processes.

CPUboundProcesses:theprocesseswhichrequirealotofCPUtime,canbetreatedasCPU bound processes.


ProcessPriority
A common type of scheduling algorithm is priority-based scheduling. The idea is to rank
processesbasedontheirworthandneedforprocessortime.Processeswithahigherpriority will run before those with
a lower priority, while processes with the same priority are scheduled round-robin (one after the next,
repeating).
Static Priority: The users assign this this priority to real-time processes ranging from 1 to 99. It is not possible
for the scheduler to change this static priority.
DynamicPriority:itissumofbaseprioritytimeandtheCPUtimeleftforremainingprocess.
The static priority is always higher than dynamic priority. When there is no real time process in running
state, then only the scheduler will prefers to run conventional processes.
SchedulingPolicies
SCHED_FIFO:Firstin-firstoutscheduling
SCHED_FIFO can be used only with static priorities higher than 0, which means that whena SCHED_FIFO
threads becomes runnable, it will always immediately preempt any currently running
SCHED_OTHER,SCHED_BATCH, or SCHED_IDLE thread. SCHED_FIFO is a simple scheduling algorithm without
time slicing

SCHED_RR:roundrobinscheduling

SCHED_RRisasimpleenhancementofSCHED_FIFO.Everythingdescribedabovefor SCHED_FIFO also


applies to SCHED_RR, except that each thread is allowed to run only for a maximum time quantum.
SCHED_OTHER:DefaultLinuxtime-sharingscheduling
SCHED_OTHER can be used at only static priority 0 (i.e., threads under real-time policies always have
priority over SCHED_OTHER processes).SCHED_OTHER is the standard Linux time-sharing scheduler that is
intended for all threads that do not require the special real-time mechanisms.

SchedulinginMultiprocessorSystems
In a multiprocessor system hopefully all of the processors are busily running processes.Eachwill run the
scheduler separately as its current process exhausts its time-slice or has to wait for a system resource. The first
thing to notice about an SMP system is that there is not just one idle
processinthesystem.Inasingleprocessorsystemtheidleprocessisthefirsttaskin
thetaskvector, in an SMP system there is one idle process per CPU as you could have more
thanoneidleCPU.Additionally thereisonecurrentprocessperCPU,soSMP systemsmustkeep track of the current
and idle processes for each processor.

Personalities
Name
personality-settheprocessexecutiondomain
Synopsis
#include<sys/personality.h>
intpersonality(unsignedlongpersona);

Description

Linux supports different execution domains, or personalities, for each process. Among other things, execution
domains tell Linux how to map signal numbers into signal actions. The execution domain system allows Linux to
provide limited support for binaries compiled under other UNIX-like operating systems.
Thisfunctionwillreturnthecurrent personality()whenpersonaequals0xffffffff.Otherwise,it will make the
execution domain referenced by personathe new execution domain of the calling process.
Return Value
Onsuccess,thepreviouspersonaisreturned.Onerror,-1isreturned,and errnoisset appropriately.

Clonning

NAME
clone- createa childprocess

SYNOPSIS
#define_GNU_SOURCE #include
<sched.h>
intclone(int(*fn)(void*),void*child_stack, int flags, void *arg, ...
/*pid_t*ptid,void*newtls,pid_t*ctid*/);

/*Fortheprototypeoftherawsystemcall,seeNOTES*/
DESCRIPTION
clone()createsanewprocess,inamannersimilartofork(2).

Thispagedescribesboththeglibc clone()wrapperfunctionandtheunderlyingsystemcall on which it is


based.The main text describes the wrapper function; the differences for the raw system call are described
toward the end of this page.
Unlike fork(2),clone() allows the child process to share parts of its execution context with the calling
process, suchas the virtualaddress space, thetable of file descriptors, and the table of signal handlers.
One use of clone() isto implement threads:multiple flows ofcontrol in a program that run concurrently in a
shared address space.
Signals
Signalis a notification, a message sent by either operating system or some application to our
program.Signalsare a mechanismfor one-wayasynchronousnotifications.Asignalmay besent from the kernel to a
process, from a process to another process, or from a process to itself. Signal typically alert a process to some
event, such as a segmentation fault, or the user pressing Ctrl-C.
Linux kernel implements about 30 signals. Each signal identified by a number, from 1 to 31.
Signalsdon'tcarryanyargumentandtheirnamesaremostlyselfexplanatory.For
instanceSIGKILLorsignalnumber9tellstheprogramthatsomeonetriestokillit, andSIGHUPused to signal that a
terminal hangup has occurred, and it has a value of 1on the i386 architecture.
With the exception ofSIGKILLandSIGSTOPwhich always terminates the process or stops the process,
respectively, processes may control what happens when they receive a signal. They can
1. accept the default action, which may be to terminate the process, terminate and coredump the process, stop
the process, or do nothing, depending on the signal.
2. Or,processescanelecttoexplicitlyignoreorhandlesignals.
1. Ignoredsignalsaresilentlydropped.
2. Handled signalscause the execution of a user-suppliedsignal handlerfunction. The program jumps to this
function as soon as the signal is received, and the control of the program resumes at the previously interrupted
instructions.

ignal Name Description

SIGHUP 1 Hangup (POSIX)


SIGINT 2 Terminalinterrupt(ANSI)
SIGQUIT 3 Terminalquit(POSIX)
SIGKILL 9 Kill(can'tbecaughtorignored) (POSIX)
SIGALRM 14 Alarmclock(POSIX)
SIGCHLD 17 Childprocesshasstoppedorexited,changed(POSIX)
SIGTERM 15 Termination(ANSI)

Note that, we cannot ignore SIGSTOP and SIGKILL signals, because these signals provide a way for the kernel
or root user to stop or kill process in any circumstances. The default action for these two signals is to
terminate the process. These two signals can neither be caught nor be ignored.

SendingandReceivingSignals:
The termraise is used to indicate the generation of a signal, and the term catchis used to indicate the receipt
of a signal.
Signals are raisedby error conditions, andthey are generatedby the shelland terminal handlers to cause
interrupts and can also be sent from one process to another to pass information or to modify the behavior.
Signalscanbe:
1. Raised
2. Caught
3. Actedupon
4. Ignored
If a process receives signals such as SIGFPE,SIGKILL, etc., the process will be terminated immediately, and
acore dumpfile is created. Thecorefile is an image of the process, and we can use it to debug.
Here is an example of the common situation when we use a signal: when we type the interrupt character
(Ctrl+C), theISGINTsignal will be sent to theforeground process(the program currently running). This will cause
the program to terminate unless it has some arrangement for catching the signal.
The commandkillcan be used to send a signal to a process other than the current foreground process.

DevelopmentwithLINUX:
Everyone has a favorite development platform. With Windows becoming less popular, is Linux getting the
breakthrough it needs? The answer, on the surface, is “Yes.”If you haven’t yet experimented with the
operating system yourself, now’s the time to give it a try.
According to theStack Overflow 2016 survey, desktop developers now constitute just 6.9 percent of all
developers (and that also includes Mac Desktops). Over half of programming jobs are now for Web
developers, and that has opened up development on alternative platformssuch as Linux and Mac. That’s why,
after 20 years of focusing on building Windows applications,I decided to learn Linux, specifically Ubuntu.
SoWhy Switch?
Here’swhyyoumightpreferLinuxtoMacorWindows.
 Itoffersgreaterbreadthanddepthofopen-sourcesoftware.
 It’slessfiddlyrunningopen-sourcesoftwareonLinux.
 Itrunsonanything,especiallyanoldWindowsPC.
 Onceyou’velearnedtheterminalcommands,youcanbeextremelyefficientand productive.
 RebuildingaWindowsDevelopmentPCafteramajorcrashcantakehoursordaysto reinstall everything. Linux, by
contrast, is a lot quicker and also easier to containerize.
 Thedevelopmentenvironmentissimilartoproduction.It’salsolikelytostaystable
longer,asthere’slesscommercialpressuretoreleasenewOS versions.
 Intheworldofservers,it reignssupreme.It’salsoamajorplayerinmobile,thanksto
Android.

Let’slookatacoupleofthesepoints:
TerminalCommands

Linux at heart is a command-line operating system with many commands for controlling and configuring the
system, running applications, and so on. You can control everything from the command line.
This might be a bit of a controversial statement, but I’ve not seen any Linux GUIs that are quite as good as
Windows. To be fair to those GUis, they are far more user-friendly than a terminal, and let you run multiple
terminals at once; you can also browse around the file system far more easily than issuing commands in a
terminal. (To be a Linux developer, you should feel at home with terminal commands, particularly for installing
and updating software.)
Irrespective of the GUI used, if you are familiar with the terminal commands and one of the shells, you can
find your way around any Linux deployment. There are many popular shells, though everyone knows Bash
(a.k.a. Bourne-again Shell); they differ in features such as history, saving commands as scripts, command line
completion and the like.
Shell scripts are not unlike Windows batch files for controlling the system, but a lot more powerful. They
constitute a “mini-programming language,” albeit with many more commands, and include constants, string
and integer variables; if, case, for, while and until loops; as well as job control, shell functions and aliases (and
lots more).
RebuildingAfteraMajorCrash
If you’ve been developing on Windows for a couple of years, you’ve likely experienced a catastrophic failure at
some point, or had to move all your dev tools to a new version of Windows.

Windows 10 is perhaps better at handling crashes than previous versions, but I’ve had to reload my entire
development package on Windows 95, 2000, XP and 7. None of these were total disk crashes, and I had
backups, but each wasted a day or two before I could get back to my pre- crash state.

There are probably less than 20 pieces of development software that I need on a PC, but thatstill means a lot of
time spent reacquiring and reinstalling.
You can have the same issues with Linux, except most Linux upgrades don’t require application reinstalls (and
I’ve neverexperienced a catastrophic crashwhile working with Linux). In the event of a total implosion, much of
the software can be reinstalled with batch files made up ofmultiple sudo apt install statements. It’s just far
quicker.

Gcc:
The GNU compiler collection(gcc) is a command line compiler on linux systems. It is also c and c++ compiler
developed by the GNU project. For example, if one had written a program whose filename is ‘add’, the
compilation procedure is as follows:
 The primaryway ofcompiling that file ‘add.c’ into an executable filecalled ‘add’ is gcc -o add add.c.
 Iftheprogramcompileswithoutanyerrors,itcanbeexecutedbytyping‘./add’

Gdb:
Thegdbwillstepthroughthesourcecodelinebylineorinstructionbyinstruction.Itisalso possible to know the value of any
variable at run time.

Gnat:
It is an acronym for GNU NYU ada translator (GNAT). It is a free software compiler for the programming
language ‘ada’ which is part of the GNU compiler collection. The gcc compiler is
havingthecapabilityofcompilingprogramswritteninseverallanguagesincludingada95, andc. if the file extension is
either ‘.ads’ or ‘.adb’, it assumes that the given program has been writtenin ada and, then it will call the GNAT
compiler to compile the particular specified file.
WhatisMySQL
MySQL is a fast, easy to use relational database. It is currently the most popular open- source database.
It is very commonly used in conjunction with PHP scripts to create powerful and dynamic server-side
applications.

MySQL is used for many small and big businesses. It is developed, marketed and supported by MySQL
AB, a Swedish company. It is written in C and C++.

Reasonsofpopularity
MySQLisbecomingsopopularbecauseofthesefollowingreasons:

o MySQLisanopen-sourcedatabasesoyoudon'thavetopayasinglepennytouseit.
o MySQL is a very powerful program so it can handle a large set of functionality of the most expensive
and powerful database packages.
o MySQLiscustomizablebecauseitisanopensourcedatabaseandtheopen-sourceGPL license facilitates
programmers to modify the SQL software according to their own specific environment.
o MySQL is quicker than other databases so it can work well even with the large data set.
o MySQL supports many operating systems with many languages like PHP, PERL, C, C++, JAVA, etc.
o MySQLusesastandardformofthewell-knownSQLdatalanguage.
o MySQLisveryfriendlywithPHP,themostpopularlanguageforwebdevelopment.
o MySQLsupportslargedatabases,upto50millionrowsormoreinatable.Thedefault
filesizelimitforatableis4GB,butyoucanincreasethis(ifyouroperatingsystemcan handle it) to a theoretical
limit of 8 million terabytes (TB).

HistoryofMySQL
MySQL is an open source database product that was created by MySQL AB, a company founded in 1995
in Sweden. In 2008, MySQL AB announced that it had agreed to be acquired by Sun Microsystems for
approximately $1 billion.

InitialEfforts
The project of MySQL was started in 1979, when MySQL's inventor, Michael Widenius developed an in-
house database tool called UNIREG for managing databases. After that UNIREG has been rewritten in
several different languages and extended to handle big databases. After some time Michael Widenius
contacted David Hughes, the author of mSQL, to see if Hughes would be interested in connecting mSQL
to UNIREG's B+ ISAM handler to provide indexing to mSQL. That's the way MySQL came in existence.

MySQLisnamedafterthedaughterofMichaelWideniuswhosenameis"My".
MySQLFeature
s
o Relational Database Management System (RDBMS): MySQL is a relational database management
system.
o Easytouse:MySQLiseasytouse.YouhavetogetonlythebasicknowledgeofSQL. You can build and interact
with MySQL with only a few simple SQL statements.
o It issecure: MySQL consistofa soliddatasecuritylayerthatprotects sensitivedata from intruders.
Passwords are encrypted in MySQL.
o Client/ServerArchitecture: MySQLfollowsaclient/serverarchitecture.Thereisa database server (MySQL)
and arbitrarily many clients (application programs), which communicate with the server; that is, they
query data, save changes, etc.
o Freetodownload:MySQLisfreetouseandyoucandownloaditfromMySQLofficial website.
o It is scalable: MySQL can handle almost any amount of data, up to as much as 50 million rows or more.
The default file size limit is about 4 GB. However, you can increase this number to a theoretical limit of
8 TB of data.
o Compatibale on many operating systems: MySQL is compatible to run on many operating systems, like
Novell NetWare, Windows* Linux*, many varieties of UNIX* (such as Sun* Solaris*, AIX, and DEC*
UNIX), OS/2, FreeBSD*, and others. MySQL
alsoprovidesafacilitythattheclientscanrunonthesamecomputerastheserveror on another computer
(communication via a local network or the Internet).
o Allows roll-back: MySQL allows transactions to be rolled back, commit and crash recovery.
o HighPerformance:MySQLisfaster,morereliableandcheaperbecauseofitsunique storage engine
architecture.
o High Flexibility: MySQL supports a large number of embedded applications which makes MySQL very
flexible.
o High Productivity: MySQL uses Triggers, Stored proceduresand viewswhich allows the developer to give
a higher productivity.

Disadvantages/DrawbackofMySQL:
FollowingarethefewdisadvantagesofMySQL:

o MySQLversionlessthan5.0doesn'tsupportROLE,COMMITandstoredprocedure.
o MySQLdoesnotsupportaverylargedatabasesizeasefficiently.
o MySQLdoesn'thandletransactionsvery efficientlyanditispronetodatacorruption.
o MySQLisaccusedthatitdoesn'thaveagooddevelopinganddebuggingtoolcompared to paid databases.
o MySQLdoesn'tsupportSQLcheckconstraints.

MySQLData Types
A Data Type specifies a particular type of data, like integer, floating points, Boolean etc. It also identifies
the possible values for that type, the operations that can be performed on that type and the way the
values of that type are stored.

MySQL supports a lot number of SQL standard data types in various categories. It uses many different
data types broken into mainly three categories: numeric, date and time, and string types.
NumericDataTyp
e
DataType Description
Syntax

INT Anormal-sizedintegerthatcanbesignedorunsigned.Ifsigned,theallowablerangeisfrom
-
2147483648to2147483647.Ifunsigned,theallowablerangeisfrom0to4294967295.You
can specify a width of up to 11 digits.
TINYINT A very small integer that can be signed or unsigned. If signed, the allowable range
is from - 128 to 127. If unsigned, the allowable range is from 0 to 255. You can
specify a width of up to 4 digits.
SMALLINT Asmallintegerthatcanbesignedorunsigned.Ifsigned,theallowablerangeisfrom -32768
to32767.If unsigned,theallowablerange isfrom0to65535.Youcanspecifyawidthofup
to 5 digits.
MEDIUMINT Amedium-sizedintegerthatcanbesignedorunsigned.Ifsigned,theallowablerange isfrom
-8388608to8388607.Ifunsigned,theallowablerangeisfrom0to16777215.Youcan
specify a width of up to 9 digits.
BIGINT A large integer that can be signed or unsigned. If signed, the allowable range is
from -
9223372036854775808to9223372036854775807.Ifunsigned,theallowablerangeisfr
om 0 to 18446744073709551615. You can specify a width of up to 20 digits.
FLOAT(m,d) Afloating-
pointnumberthatcannotbeunsigned.Youcandefinethedisplaylength(m)and the
number of decimals (d). This is not required and will default to 10,2, where 2 is the
number of decimals and 10 is the total number of digits (including decimals).
Decimal precision can go to 24 places for a float.
DOUBLE(m,d) A double precision floating-point number that cannot be unsigned. You can define
the display length (m) and the number of decimals (d). This is not required and will
default to
16,4,where4isthenumberofdecimals.Decimalprecisioncangoto53placesforadouble.
Real is a synonym for double.
DECIMAL(m,d) An unpacked floating-point number that cannot be unsigned. In unpacked decimals,
each
decimalcorrespondstoonebyte.Definingthedisplaylength(m)andthenumberofdecimals
(d)isrequired.Numericisasynonymfordecimal.
DateandTimeDataType
:
DataType MaximumSize Explanation
Syntax

DATE Valuesrangefrom'1000-01-01'to'9999-12-31'. Displayedas'yyyy-mm-dd'.

DATETIME Valuesrangefrom'1000-01-0100:00:00'to'9999-12- Displayed as 'yyyy-mm-


3123:59:59'. dd hh:mm:ss'.

TIMESTAMP(m) Valuesrangefrom'1970-01-0100:00:01'UTCto'2038- Displayed as 'YYYY-MM-


01-1903:14:07'TC. DD HH:MM:SS'.

TIME Valuesrangefrom'-838:59:59'to'838:59:59'. Displayedas'HH:MM:SS'.

YEAR[(2|4)] Yearvalueas2digitsor4digits. Defaultis4digits.

StringDataTypes:

DataTypeSyntax MaximumSize Explanation

CHAR(size) Maximum size of Where size is the number of characters to store.


255 Fixed- length strings. Space padded on right to
characters. equal size characters.

VARCHAR(size) Maximum size of Wheresizeisthenumberofcharacterstostore.Variabl


255 e-length string.
characters.
TINYTEXT(size) Maximum size of Wheresizeisthenumberofcharacterstostore.
255
characters.
TEXT(size) Maximumsizeof65,535 Wheresizeisthenumberofcharacterstostore.
characters.

MEDIUMTEXT(size) Maximumsizeof16,777,215 Wheresizeisthenumberofcharacterstostore.


characters.

LONGTEXT(size) Maximumsizeof4GBor Wheresizeisthenumberofcharacterstostore.


4,294,967,295 characters.

BINARY(size) Maximum size of Where size is the number of binary characters to


255 store. Fixed-
characters. lengthstrings.Spacepaddedonrighttoequalsize
characters.
(introducedinMySQL4.1.2)
VARBINARY(size) Maximum size of Wheresizeisthenumberofcharacterstostore.Variabl
255 e-length string.
characters. (introducedinMySQL4.1.2)
LargeObjectDataTypes(LOB)DataTypes
:
DataTypeSyntax MaximumSize

TINYBLOB Maximumsizeof255bytes.

BLOB(size) Maximumsizeof65,535bytes.

MEDIUMBLOB Maximumsizeof16,777,215bytes.

LONGTEXT Maximumsizeof4gbor4,294,967,295characters.

HowtoinstallMySQL
Download MySQL Follow
these steps:
o GotoMySQLofficialwebsitehttp://www.mysql.com/downloads/
o ChoosetheversionnumberforMySQLcommunityserverwhichyouwant.

InstallingMySQLonWindows

Your downloaded MySQL is neatly packaged with an installer. Download the installer package, unzip it
anywhere and run setup.exe.

Bydefault,thisprocesswillinstalleverythingunderC:\mysql.

VerifyMySQLinstallation

OnceMySQLhasbeensuccessfullyinstalled,thebasetableshavebeeninitialized,andthe server has been


started, you can verify its working via some simple tests.

Open yourMySQL Command LineClient, it should beappeared with a mysql> prompt. If you have set
any password, write your password here. Now, you are connected to the MySQL server and you can
execute all the SQL command at mysql> prompt as follows:

Forexample:Checkthealreadycreateddatabaseswithshowdatabasescommand:
MysqlUserCreation:SettingUpaNewMySQLUserAccount

HowdoI createauseraccounton MySQLdatabaseserver?

When you try to access MySQL database server from client such as mysql or even programming
language such asphporperl youneedauseraccount.MySQLhassophisticatedusermanagement system that
controls who can access server and from which client system. It uses special tables in mysql database.
In order to create a new user account you need a MySQL root account password. You need to use the
GRANT SQL command to set up the MySQL user account. Finally, use the account’s name and password
to make connections to the MySQL server.

Pleasenotethat MySQL rootuseraccountisdifferentfromUNIX/Linuxrootloginaccount. For example, the


MySQL root user and the Linux/Unix root user are separate and have nothing to do with each other,
even though the username is the same in each case.
Setuparoot user password
Tosetuprootpasswordforfirsttime,usemysqladmincommandatshellpromptasfollows:

$mysqladmin-urootpassword NEWPASSWO
Ifyouwanttochangeorupdatearootuserpassword,thenyouneedtousethefollowing command:
$mysqladmin-uroot-p'oldpassword'passwordnewpass

ProcedureforsettingupaMySQLuser account
Logininasmysqlrootuser.Atshellprompttypethefollowing command:
$mysql-uroot-p OR
$mysql-uroot-hyour-mysql-server-host-name-p
Createanewmysqldatabasecalleddemo.Typethefollowingcommandat mysql>prompt: mysql>CREATE
DATABASE demo;
Createanewusercalleduser1fordatabasecalleddemo:

mysql>GRANTALLONdemo.*TOuser1@localhostIDENTIFIEDBY'mypassword';
HowdoIconnecttoMySQLdatabasedemousinguser1 account?
Useruser1canconnecttodemodatabaseusingthefollowingshellcommand:
$mysql-uuser1-pdemo OR
$mysql-uuser1-hyour-mysql-server-host-name-here-pdemo
Where,
 -uuser1:MySQL Username
 -h:MySQL servername(defaultislocalhost)
 -p:Promptforpassword
 demo:demoisnameofmysqldatabase(optional)
StartingandTerminatingmysql

Problem
Youwanttostartandstopthemysqlprogram.

Solution
Invoke mysql from your command prompt to start it, specifying any connection parameters
that may be necessary. To leave mysql, use a QUIT statement.
Discussion
Tostartthemysqlprogram,tryjusttypingitsnameatyourcommand-lineprompt.Ifmysqlstarts
upcorrectly,you’llseeashortmessage,followedbyamysql>promptthatindicatestheprogramis
ready to accept queries. To illustrate, here’s what the welcome message looks like
%mysql
Welcome to the MySQL monitor.Commands end with ; or \g. YourMySQLconnectionidis18427toserverversion:3.23.51-log
Type'help;'or'\h'forhelp.Type'\c'toclearthebuffer. mysql>

Ifmysqltriestostartbutexitsimmediatelywithan“accessdenied”message,you’llneedtospecify
connectionparameters.Themostcommonlyneededparametersarethehosttoconnectto(thehost
where
%mysql the MySQL cbuser
-hlocalhost-p-u server runs), your MySQL username, and a password. For example:
Enterpassword:cbpass

Ingeneral,I’llshowmysqlcommandsinexampleswithnoconnectionparameteroptions.Iassume
that you’ll supply any parameters that you need, either on the command line, or in an option
file (Recipe 1.5) so that you don’t have to type them each time you invoke mysql.
Ifyoudon’thaveaMySQLusernameandpassword,youneedtoobtainpermissiontousetheMySQL
server,
Thesyntaxanddefaultvaluesfortheconnectionparameteroptionsareshowninthefollowingtable.
These options have both a single-dash short form and a double-dash long form.

Parametertype Optionsyntaxforms Defaultvalue

Hostname -hhostname--host=hostname localhost

Username -uusername--user=username Yourloginname

Password -p--password None

As the
table indicates,there is nodefault password.To supplyone,use --password or-p,then enter your password when
mysql prompts you for it:
%mysql-pEnterpassword:←enteryourpassword here
If you like, you can specify the password directly on the command line by using either -p password (note
that there is no space after the -p) or --password=password. I don’t recommend doing this on a
multiple-user machine, because the password may be visible momentarily to other users who are
running tools such as ps that report process information.

Ifyou getan errormessagethatmysqlcannotbefoundorisan invalidcommandwhenyou tryto


invokeit,thatmeansyourcommandinterpreterdoesn’tknowwheremysql
mysql>QUIT isinstalled. To
terminate a mysql session, issue a QUIT statement:
Youcanalsoterminatethesessionbyissuingan EXITstatementor(underUnix)bytypingCtrl-D.
Thewayyouspecifyconnectionparametersfor mysql alsoappliestootherMySQLprogramssuch as
mysqldump and mysqladmin. For example, some of the actions that mysqladmin can perform are
available onlyto the MySQL root account,so you need to specifyname and password options for that
user:
%mysqladmin-p-urootshutdown
Enterpassword:

MySQLCreate Database
YoucancreateaMySQLdatabasebyusingMySQL CommandLineClient.

OpentheMySQLconsoleandwritedownpassword,ifyousetonewhileinstallation.Youwillgetthe following:

Nowyou are readyto createdatabase.

Syntax:

CREATEDATABASEdatabase_name;

Example:

Let'stakeanexampletocreateadatabasename"employees"

CREATEDATABASEemployees;
Itwilllooklikethis:

Youcancheckthecreateddatabasebythefollowingquery:

SHOWDATABASES;

Output

Here,you cansee theall createddatabases.

MySQLSELECTDatabase

SELECT Database isused in MySQLto select aparticulardatabase to workwith.Thisqueryisused when


multiple databases are available with MySQL Server.

YoucanuseSQLcommand USEtoselectaparticular database.

Syntax:

USEdatabase_name;

Example:

Let'stakeanexampletouseadatabasename"customers". USE
customers;
Itwilllooklikethis:

Note:Allthedatabasenames,tablenamesandtablefieldsnamearecasesensitive.Youmusthave to use
proper names while giving any SQL command.

MySQLDropDatabase

You can drop/delete/remove a MySQL database easily with the MySQL command. You should
becarefulwhiledeletinganydatabasebecauseyouwillloseyourallthedataavailableinyourdatabase.

Syntax:

DROPDATABASEdatabase_name;

Example:

Let'stakeanexampleto dropadatabasename"employees"

DROPDATABASEemployees; It will
look like this:

Nowyoucancheckthateitheryourdatabaseisremovedbyexecutingthefollowing query:
SHOWDATABASES;

Output:

Here,youcanseethatthedatabase"employees"isremoved.

MySQLCREATETABLE

TheMySQLCREATETABLEcommandisusedtocreateanewtableintothedatabase.Atablecreation command requires


three things:

o Nameofthe table
o Namesof fields
o Definitionsforeachfield

Syntax:

FollowingisagenericsyntaxforcreatingaMySQLtableinthe database.

CREATETABLEtable_name (column_name column_type...);

Example:

Here,wewill createatablenamed"cus_tbl"in thedatabase"customers".

CREATETABLEcus_tbl(
cus_idINT NOTNULLAUTO_INCREMENT,
cus_firstnameVARCHAR(100)NOTNULL,
cus_surname VARCHAR(100) NOT NULL,
PRIMARY KEY ( cus_id )
);

Note:

1. Here,NOTNULLisafieldattributeanditisusedbecausewedon'twantthisfieldtobeNULL.Ifyou will try to


create a record with NULL value, then MySQL will raise an error.
2. The field attribute AUTO_INCREMENT specifies MySQL to go ahead and add the next available
numbertotheidfield.PRIMARYKEYisusedtodefineacolumnasprimarykey.Youcanusemultiple columns
separated by comma to define a primary key.
VisualrepresentationofcreatingaMySQLtable:

Seethecreatedtable:

Usethefollowingcommandtoseethetablealreadycreated:

1. SHOWtables;

Seethetablestructure:

Usethefollowingcommandtoseethetablealreadycreated:

1. DESCRIBEcus_tbl;
MySQLALTERTable

MySQL ALTER statement is used when you want to change the name of your table or any table
field. It is also used to add or delete an existing column in a table.

TheALTERstatementisalwaysusedwith"ADD","DROP"and"MODIFY"commandsaccordingto the
situation.

1) ADDacolumninthetable

Syntax:

ALTERTABLEtable_name
ADDnew_column_namecolumn_definitio
n [ FIRST | AFTER column_name ];

Parameters

table_name:Itspecifiesthenameofthetablethatyouwanttomodify.

new_column_name:Itspecifiesthenameofthenewcolumnthatyouwanttoaddtothetable.

column_definition:Itspecifiesthedatatypeanddefinitionofthecolumn(NULLorNOTNULL, etc).

FIRST | AFTER column_name: It is optional. It tells MySQL where in the table to create the
column.Ifthisparameterisnotspecified,thenewcolumnwillbeaddedtotheendofthetable.

Example:

Inthisexample,weaddanewcolumn"cus_age"intheexistingtable"cus_tbl". Use the


following query to do this:
ALTERTABLEcus_tbl
ADDcus_agevarchar(40)NOTNULL;

Output:
Seetherecentlyaddedcolumn:

1.SELECT*FROM cus_tbl;

Output:

2) Addmultiplecolumnsinthetable

Syntax:
ALTERTABLEtable_name
ADDnew_column_namecolumn_definition [
FIRST | AFTER column_name ],
ADDnew_column_namecolumn_definition [
FIRST | AFTER column_name ],
...;

Example:

In this example, we add two new columns "cus_address", and cus_salary in the existing table
"cus_tbl".cus_addressisaddedaftercus_surnamecolumnandcus_salaryisaddedaftercus_age column.
Usethefollowingquerytodothis: ALTER TABLE
cus_tbl
ADDcus_addressvarchar(100)NOTNULL
AFTERcus_surname,
ADDcus_salaryint(100)NOTNULL
AFTERcus_age;
Seetherecentlyaddedcolumns:

SELECT*FROMcus_tbl;

3) MODIFYcolumninthetable

TheMODIFYcommandisusedtochangethecolumndefinitionofthe table.

Syntax:

ALTERTABLEtable_name
MODIFYcolumn_namecolumn_definition [ FIRST
| AFTER column_name ];

Example:

Inthisexample,wemodifythecolumncus_surnametobeadatatypeofvarchar(50)andforce the column to


allow NULL values.

Usethefollowingquerytodothis:

ALTERTABLEcus_tbl

MODIFYcus_surnamevarchar(50)NULL;
Seethetablestructure:

4) DROPcolumn in table

Syntax:

ALTERTABLEtable_name
DROP COLUMNcolumn_name;
Let'stakeanexampletodropthecolumnname"cus_address"fromthetable"cus_tbl".

Usethefollowingquerytodothis:

ALTERTABLEcus_tbl
DROP COLUMNcus_address;

Output:
Seethetablestructure:

5) RENAMEcolumnintable

Syntax:

ALTERTABLEtable_name
CHANGECOLUMNold_namenew_name column_definition
[FIRST|AFTERcolumn_name ]

Example:

Inthisexample,wewillchangethecolumnname"cus_surname"to"cus_title".
Usethefollowingquerytodothis: ALTER
TABLEcus_tbl
CHANGECOLUMNcus_surname cus_title
varchar(20)NOTNULL;

Output:
6) RENAMEtable

Syntax:

1. ALTERTABLEtable_name
2. RENAMETOnew_table_name;

Example:

Inthisexample,thetablenamecus_tbl isrenamedas cus_table.

ALTER TABLE cus_tbl


RENAMETOcus_table;

Output:

Seetherenamed table:
MySQLTRUNCATETable
MYSQLTRUNCATEstatementremovesthecompletedatawithoutremovingitsstructure.

The TRUNCATE TABLE statement is used when you want to delete the complete data from a table
without removing the table structure.

Syntax:

TRUNCATETABLEtable_name;

Example:

Thisexamplespecifieshowtotruncateatable.Inthisexample,wetruncatethetable"cus_tbl".

TRUNCATETABLEcus_tbl;

Output:

Seethetable:

1. SELECT*FROMcus_tbl;

Output:
MySQLDROPTable

MYSQLDROPtablestatementremovesthecompletedatawithstructure.

Syntax:

DROPTABLEtable_name;

Example:

Thisexamplespecifieshowtodropatable.Inthisexample,wearedroppingthetable"cus_tbl".

DROPTABLEcus_tbl;

MySQLTRUNCATETablevsDROPTable

You can also use DROPTABLEcommand to delete complete table but it will remove complete table data
and structure both. You need to re-create the table again if you have to store some data. But in the
case of TRUNCATE TABLE, it removes only table data not structure. You don't need to re- create the
table again because the table structure already exists.

MySQLView
InMySQL,Viewisavirtualtablecreatedbyaquerybyjoiningoneormoretables. MySQL Create
VIEW
AVIEWiscreatedbySELECTstatements.SELECTstatementsareusedtotakedatafromthesource table to make
a VIEW.

Syntax:

CREATE[ORREPLACE]VIEW view_nameAS
SELECT columns FROM
tables
[WHEREconditions];

Parameters:

OR REPLACE: Itisoptional.ItisusedwhenaVIEW alreadyexist.Ifyoudonotspecifythisclause and the VIEW


already exists, the CREATE VIEW statement will return an error.

view_name:ItspecifiesthenameoftheVIEWthatyouwanttocreateinMySQL.

WHEREconditions:Itisalsooptional.Itspecifiestheconditionsthatmustbemetfortherecords to be included
in the VIEW.

ThefollowingexamplewillcreateaVIEWname"trainer".Thisisavirtualtablemadebytakingdata from the


table "courses".

CREATEVIEW trainerAS
SELECT course_name,course_trainer
FROMcourses;
Tosee thecreatedVIEW:

Syntax:

SELECT*FROM view_name;

Let'sseehowitlooksthecreated VIEW:

SELECT*FROM trainer;

MySQLUpdateVIEW

InMYSQL,theALTERVIEWstatementisusedtomodifyorupdatethealreadycreatedVIEWwithout dropping it.

Syntax:

ALTERVIEWview_nameAS SELECT
columns
FROM table
WHEREconditions;

Example:

ThefollowingexamplewillalterthealreadycreatedVIEWname"trainer"byaddinganewcolumn.
ALTERVIEWtrainerAS
SELECTcourse_name,course_trainer, course_id

FROMcourses;

ToseethealteredVIEW:

SELECT*FROMtrainer;

MySQLDropVIEW

YoucandroptheVIEWbyusingtheDROPVIEW statement.

Syntax:

DROPVIEW[IFEXISTS]view_name; Parameters:
view_name:ItspecifiesthenameoftheVIEWthatyouwanttodrop.

IF EXISTS: It is optional. If you do not specifythis clause and the VIEW doesn't exist, the DROPVIEW
statement will return an error.

Example:

DROPVIEWtrainer;
MySQLQueries
A list of commonly used MySQL queries to create database, use database, create table, insert record,
update record, delete record, select record, truncate table and drop table are given below.

1) MySQLCreate Database

MySQLcreatedatabaseisused tocreatedatabase.Forexample

createdatabasedb1;

2) MySQLSelect/UseDatabase

MySQLusedatabaseisusedtoselectdatabase.Forexample use db1;


3) MySQLCreateQuery

MySQLcreatequeryisusedtocreateatable,view,procedureandfunction.Forexample:

CREATETABLEcustomers (id
int(10),
name varchar(50), city
varchar(50),
PRIMARYKEY(id));

4) MySQLAlterQuery

MySQLalterqueryisusedtoadd,modify,deleteordropcolumsofatable.Let'sseeaquerytoadd column in
customers table:

ALTERTABLEcustomers
ADDagevarchar(50);

5) MySQLInsertQuery

MySQLinsertqueryisusedtoinsertrecordsintotable.For example:

insertintocustomersvalues(101,'rahul','delhi');
6) MySQLUpdateQuery

MySQLupdatequeryisusedtoupdaterecordsofatable.Forexample:

updatecustomerssetname='bob',city='london'whereid=101;

7) MySQLDeleteQuery

MySQLupdatequeryisusedtodeleterecordsofatablefromdatabase.Forexample:

deletefromcustomerswhereid=101;

8) MySQLSelectQuery

Oracleselectqueryisusedtofetchrecordsfromdatabase.For example:

SELECT*fromcustomers;

9) MySQLTruncateTable Query

MySQL update queryis used to truncate or remove records ofa table.It doesn't remove structure. For
example:

truncatetablecustomers;

10) MySQLDrop Query

MySQL drop query is used to drop a table, view ordatabase.It removes structure and data of atable if
you drop table. For example:

droptablecustomers;

MySQLINSERTStatement

MySQLINSERTstatementis usedtoinsertdata inMySQLtable withinthe database. We caninsert


singleormultiplerecordsusingasinglequeryinMySQL.

Syntax:

TheSQLINSERTINTOcommandisusedtoinsertdatainMySQLtable.Followingisagenericsyntax:

INSERTINTOtable_name(field1,field2,...fieldN)
VALUES

Fieldnameisoptional.Ifyouwanttospecifypartialvalues,fieldnameis mandatory.

(value1,value2,...valueN);

Syntaxforallfields:

INSERTINTOtable_nameVALUES(value1,value2,...valueN);
MySQLINSERTExample1:forallfields

Ifyouhavetostoreallthefieldvalues,eitherspecifyallfieldnameordon'tspecifyanyfield.

Example:

INSERTINTO empVALUES(7,'Sonoo', 40000);

Or,

INSERTINTOemp(id,name,salary)VALUES(7,'Sonoo',40000); MySQL INSERT


Example 2: for partial fields
In such case, it is mandatory to specify field names.
INSERTINTOemp(id,name)VALUES(7,'Sonoo');
MySQLINSERTExample3:insertingmultiple records
Here,wearegoingtoinsertrecordinthe"cus_tbl"tableof"customers"database.

INSERTINTOcus_tbl
(cus_id,cus_firstname,cus_surname)
VALUES
(5,'Ajeet','Maurya'),
(6,'Deepika','Chopra'),
(7,'Vimal','Jaiswal');

Visual Representation:

SeethedatawithinthetablebyusingtheSELECT command:
MySQLUPDATE Query

MySQLUPDATEstatementisusedtoupdatedataoftheMySQLtablewithinthedatabase.Itisused when you


need to modify the table.

Syntax:

FollowingisagenericsyntaxofUPDATEcommandtomodifydataintotheMySQLtable:

UPDATEtable_nameSETfield1=new-value1,field2=new-value2 [WHERE
Clause]

Note:

o Oneormorefieldcanbeupdatedaltogether.
o AnyconditioncanbespecifiedbyusingWHEREclause.
o Youcanupdatevaluesinasingletableatatime.
o WHEREclauseisusedtoupdateselectedrowsinatable.

Example:

Here, we have a table "cus_tbl" within the database"customers". We are goingto updatethe data within
the table "cus_tbl".

Thisquerywillupdatecus_surnamefieldforarecordhavingcus_idas5.

UPDATEcus_tbl
SET cus_surname ='Ambani'
WHEREcus_id=5;
Visual Representation:

OutputbySELECT query:

1. SELECT*FROM cus_tbl;

Here,youcanseethatthetableisupdatedasperyourconditions. MySQL DELETE


Statement
MySQLDELETEstatementisusedtodeletedatafromtheMySQLtablewithinthedatabase.Byusing delete
statement, we can delete records on the basis of conditions.

Syntax:

DELETEFROMtable_name
WHERE
(Conditionspecified);

Example:

DELETEFROMcus_tbl
WHEREcus_id=6;
Output:

MySQLSELECTStatement

TheMySQLSELECTstatementisusedto fetch datafromtheoneormoretablesin MySQL.Wecan retrieve


records of all fields or specified fields.

Syntaxforspecified fields:

SELECT expressions
FROM tables
[WHEREconditions];

Syntaxforallfields:

SELECT*FROMtables[WHEREconditions];
MySQLSELECTExample1:forspecifiedfields
Insuchcase,itismandatorytospecifyfield names.

Example:

SELECTofficer_name,address

FROMofficers

MySQLSELECTExample2:forall fields

Insuchcase,wecanspecifyeitherallfieldsor*(asterisk)symbol.
SELECT*FROM officers

MySQLSELECTExample3:frommultipletables

MySQLWHEREClause

MySQLWHEREClauseisusedwithSELECT,INSERT,UPDATEandDELETEclausetofiltertheresults. It specifies a
specific position where you have to do the operation.

Syntax:

WHEREconditions;

Parameter:

conditions:Itspecifiestheconditionsthatmustbefulfilledforrecordstobeselected. MySQL
WHERE Clause with single condition
Let'stakeanexampletoretrievedatafromatable"officers".

Table structure:
Executethisquery:

SELECT*
FROMofficers
WHEREaddress='Mau';

Output:

MySQLWHEREClausewithAND condition

Inthisexample,weareretrievingdatafromthetable"officers"withAND condition.

Executethefollowingquery:

SELECT*
FROMofficers
WHEREaddress='Lucknow'AND
officer_id < 5;

Output:

WHEREClausewithORcondition
Executethefollowingquery:

SELECT*
FROMofficers
WHEREaddress='Lucknow'OR
address = 'Mau';

Output:

MySQLWHEREClausewithcombinationofAND&ORconditions

YoucanalsousetheAND&ORconditionsaltogetherwiththeWHEREclause.

Seethisexample:

Executethefollowingquery:

SELECT*
FROMofficers
WHERE(address='Mau'ANDofficer_name='Ajeet') OR
(officer_id < 5);

Output:
MySQLDistinct Clause

MySQLDISTINCTclauseisusedtoremoveduplicaterecordsfromthetableandfetchonlytheunique records.
The DISTINCT clause is only used with the SELECT statement.

Syntax:

SELECTDISTINCTexpressions
FROM tables
[WHEREconditions];

Parameters

expressions:specifythecolumnsorcalculationsthatyouwanttoretrieve.

tables:specifythenameofthetablesfromwhereyouretrieverecords.Theremustbeatleastone table listed in


the FROM clause.

WHERE conditions: It is optional. It specifies the conditions that must be met for the records to be
selected.

Note:

o IfyouputonlyoneexpressionintheDISTINCTclause,thequerywillreturntheunique values for that


expression.
o Ifyouputmorethanoneexpressioninthe DISTINCTclause,thequerywillretrieveunique combinations for the
expressions listed.
o InMySQL,theDISTINCTclausedoesn'tignoreNULLvalues.Soifyouareusingthe
DISTINCTclauseinyourSQLstatement,yourresultsetwillincludeNULLasadistinctvalue.

MySQLDISTINCTClausewithsingleexpression

IfyouuseasingleexpressionthentheMySQLDISTINCTclausewillreturnasinglefieldwithunique records (no


duplicate record).

Seethetable:
Usethefollowingquery:

SELECTDISTINCTaddress

FROMofficers;

MySQLDISTINCTClausewithmultipleexpressions

If you use multiple expressions with DISTINCT Clause then MySQL DISTINCT clause will
removeduplicates from more than one field in your SELECT statement.

Usethefollowingquery:

SELECT DISTINCTofficer_name,address

FROMofficers;
MySQLFROMClause

TheMySQLFROMClauseisusedtoselectsomerecordsfromatable.Itcanalsobeusedtoretrieve records from


multiple tables using JOIN condition.

Syntax:

FROMtable1
[{INNER JOIN|LEFT[OUTER]JOIN| RIGHT[OUTER]JOIN} table2
ONtable1.column1=table2.column1]
Parameters

table1 and table2: specify tables used in the MySQL statement. The two tables are joined based on
table1.column1 = table2.column1.

Note:

o If you are using the FROM clause in a MySQL statement then at least one table must have been
selected.
o If you are using two or more tables in the MySQL FROM clause, these tables are generally joined using
INNER or OUTER joins.

MySQLFROMClause:Retrievedatafromone table

Thefollowingqueryspecifieshowtoretrievedatafromasingle table.

UsethefollowingQuery:

SELECT*
FROMofficers

WHEREofficer_id<=3;

MySQL FROM Clause: Retrieve data from two tables with inner join
MySQLFROMClause:Retrievedatafromtwotablesusingouter join MySQL
ORDER BY Clause
TheMYSQLORDERBYClauseisusedtosorttherecordsinascendingordescending order.

Syntax:

SELECTexpressions
FROM tables
[WHEREconditions]
ORDERBYexpression[ASC|DESC];

Parameters

expressions:Itspecifiesthecolumnsthatyouwanttoretrieve.
tables:Itspecifiesthetables,fromwhereyouwanttoretrieverecords.Theremustbeatleastone table listed in
the FROM clause.

WHEREconditions:Itisoptional.Itspecifiesconditionsthatmustbefulfilledfortherecordstobe selected.

ASC:Itisoptional.Itsortstheresultsetinascendingorderbyexpression(default,ifnomodifieris provider).

DESC:Itisalsooptional.Itsortstheresultsetindescendingorderbyexpression.

Note: You can use MySQL ORDER BY clause in a SELECT statement, SELECT LIMIT statement, and DELETE LIMIT statement.

MySQLORDERBY:withoutusingASC/DESCattribute

If you use MySQL ORDER BY clause without specifying the ASC and DESC modifier then by default you
will get the result in ascending order.

Executethefollowingquery:

SELECT*
FROMofficers
WHEREaddress='Lucknow'
ORDERBYofficer_name;

Output:

MySQLORDERBY:withASCattribute

Let'stakeanexampletoretrievethedatainascending order.

Executethefollowingquery:

SELECT*
FROMofficers
WHEREaddress='Lucknow'
ORDER BYofficer_nameASC;
Output:

MySQLORDERBY:withDESCattribute

SELECT*
FROMofficers
WHEREaddress='Lucknow'

ORDERBYofficer_nameDESC;

MySQLORDERBY:usingbothASCandDESCattributes
Executethefollowingquery: SELECT
officer_name, address
FROMofficers
WHEREofficer_id<5
ORDERBYofficer_nameDESC,addressASC; Output:
MySQLGROUPBY Clause

The MYSQL GROUP BY Clause is used to collect data from multiple records and group the result by one
or more column. It is generally used in a SELECT statement.

You can also use some aggregate functions like COUNT, SUM, MIN, MAX, AVG etc. on the grouped
column.

Syntax:

SELECTexpression1,expression2,...expression_n,
aggregate_function (expression)
FROM tables
[WHEREconditions]
GROUPBYexpression1,expression2,...expression_n;

Parameters

expression1,expression2,...expression_n:Itspecifiestheexpressionsthatarenot encapsulated within an


aggregate function and must be included in the GROUP BY clause.

aggregate_function: It specifies a function such as SUM, COUNT, MIN, MAX, or AVG etc. tables:
Itspecifiesthetables,fromwhereyouwanttoretrievetherecords.Theremustbeatleastonetable listed in the
FROM clause.

WHERE conditions: It is optional. It specifies the conditions that must be fulfilled for the records to be
selected.

(i) MySQLGROUPBYClausewithCOUNTfunction

Consideratablenamed"officers"table,havingthefollowingrecords.

Now,let'scountrepetitivenumberofcitiesinthecolumnaddress.
Executethefollowingquery: SELECT
address, COUNT(*)
FROMofficers
GROUP BY address;
Output:

(ii) MySQLGROUPBYClausewithSUMfunction

Let'stakeatable"employees"table,havingthefollowingdata.

Now,thefollowingquerywillGROUPBYtheexampleusingtheSUMfunctionandreturnthe emp_name and total


working hours of each employee.

Executethefollowingquery:

SELECTemp_name,SUM(working_hours)AS"Totalworking hours"
FROMemployees
GROUP BY emp_name;

Output:
(iii) MySQLGROUPBYClausewithMIN function

Thefollowingexamplespecifiestheminimumworkinghoursoftheemployeesformthetable "employees".

Executethefollowingquery:

SELECTemp_name,MIN(working_hours)AS"Minimumworking hour"
FROMemployees
GROUP BY emp_name;

Output:

(iv) MySQLGROUPBYClausewithMAXfunction

Thefollowingexamplespecifiesthemaximumworkinghoursoftheemployeesformthetable "employees".

Executethefollowingquery:

SELECTemp_name,MAX(working_hours)AS"Minimumworking hour"
FROMemployees
GROUP BY emp_name;

Output:
(v) MySQLGROUPBYClausewithAVGfunction

Thefollowingexamplespecifiestheaverageworkinghoursoftheemployeesformthetable "employees".

Executethefollowingquery:

SELECTemp_name,AVG(working_hours)AS"Averageworking hour"
FROMemployees
GROUP BY emp_name;

Output:

MySQLHAVING Clause

MySQLHAVINGClauseisusedwithGROUPBYclause.Italwaysreturnstherowswhereconditionis TRUE.

Syntax:

SELECTexpression1,expression2,...expression_n,
aggregate_function (expression)
FROM tables
[WHEREconditions]
GROUPBYexpression1,expression2,...expression_n
HAVINGcondition;

Parameters

aggregate_function: It specifies any one of the aggregate function such as SUM, COUNT, MIN, MAX, or
AVG.

expression1,expression2,...expression_n:Itspecifiestheexpressionsthatarenot encapsulated within an


aggregate function and must be included in the GROUP BY clause.

WHEREconditions:Itisoptional.Itspecifiestheconditionsfortherecordstobe selected.

HAVING condition: It is used to restrict the groups of returned rows. It shows only those groups in
result set whose conditions are TRUE.

HAVINGClausewithSUMfunction

Consideratable"employees"tablehavingthefollowingdata.
Here, we use the SUM function with the HAVING Clause to return the emp_name and sum of their
working hours.

Executethefollowingquery:

SELECTemp_name,SUM(working_hours)AS"Totalworking hours"
FROMemployees
GROUP BY emp_name

HAVINGSUM(working_hours)> 5;

Simply,itcanalsobeusedwithCOUNT,MIN,MAXandAVGfunctions.

MySQLConditions
MySQLANDMySQLORMySQLANDORMySQLLIKEMySQLINMySQLNOTMySQLISNULLMySQLIS NOT
NULLMySQL BETWEEN
MySQL Join
MySQLJOINS
MySQLJOINSareusedwithSELECTstatement.Itisusedtoretrievedatafrommultipletables.Itis performed whenever
you need to fetch records from two or more tables.

TherearethreetypesofMySQLjoins:

o MySQLINNERJOIN(orsometimescalledsimplejoin)
o MySQLLEFTOUTERJOIN(orsometimescalledLEFTJOIN)
o MySQLRIGHTOUTERJOIN(orsometimescalledRIGHTJOIN)
MySQL Inner JOIN (Simple Join)
The MySQL INNER JOIN is used to return all rows from multiple tables where the join condition is
satisfied. It is the most common type of join.
Syntax:

SELECT columns FROM


table1
INNERJOINtable2
ONtable1.column=table2.column;

Imagerepresentation:

Let'stakean example:

Considertwotables"officers"and"students",havingthefollowing data.

Executethefollowingquery:

SELECTofficers.officer_name,officers.address,students.course_name
FROMofficers
INNERJOINstudents
ONofficers.officer_id=students.student_id;

Output:
MySQLLeftOuterJoin

The LEFT OUTER JOIN returns all rows from the left hand table specified in the ON condition and only
those rows from the other table where the join condition is fulfilled.

Syntax:

SELECTcolumns
FROMtable1
LEFT[OUTER]JOINtable2
ONtable1.column=table2.column;

Imagerepresentation:

Let'stakean example:

Considertwotables"officers"and"students",havingthefollowing data.

Executethefollowingquery:

SELECTofficers.officer_name,officers.address,students.course_name
FROM
officersLEFTJOINstude
nts
ONofficers.officer_id=students.student_id;

Output:
MySQLRightOuterJoin

TheMySQLRightOuterJoinreturnsallrowsfromtheRIGHT-handtablespecifiedintheONcondition and only


those rows from the other table where he join condition is fulfilled.

Syntax:

SELECTcolumns
FROMtable1
RIGHT[OUTER]JOINtable2
ONtable1.column=table2.column;

Imagerepresentation:

Let'stakean example:

Considertwotables"officers"and"students",havingthefollowing data.

Executethefollowingquery:

SELECTofficers.officer_name,officers.address,students.course_name,students.student_name
FROM
officersRIGHTJOINstude
nts
ONofficers.officer_id=students.student_id;
Output:

AggregateFunctions
MySQLcount()MySQLsum()MySQLavg()MySQLmin()MySQLmax()MySQLfirst()MySQL last()

StringFunctions:

S.No. Function Example

1 CHAR_LENGTH(str) mysql>SELECTCHAR_LENGTH("text");
+ +
Returns the length of the string str, | CHAR_LENGTH("text") |
measured in characters.Amulti- +------------------------------------------------+
bytecharactercountsasasingle character. | 4 |
This means that for a string containing five +------------------------------------------------+
two-byte characters, LENGTH() returns 10, 1rowinset (0.00 sec)
whereas CHAR_LENGTH() returns 5.
2 CONCAT(str1,str2,...)
Returns the string that results from mysql>SELECTCONCAT('My','S','QL');
concatenating the arguments. May have +------------------------------------------------+
one or more arguments. Ifall | CONCAT('My','S','QL') |
argumentsarenon- +------------------------------------------------+
binarystrings,theresultis a non-binary | MySQL |
string. If the arguments include any binary +------------------------------------------------+
strings,theresultis abinary string.Anumeric 1rowinset (0.00 sec)
argument is converted to its equivalent
binary
stringform;ifyouwanttoavoidthat,youcanu
se
anexplicittypecast,asinthis example:
3 BIT_LENGTH(str) mysql>SELECTBIT_LENGTH('text');
Returnsthelengthofthestringstrinbits. +------------------------------------------------+
| BIT_LENGTH('text') |
+ +
| 32 |
+ +
1rowinset (0.00 sec)
4 CONCAT_WS(separator,str1,str2,...) mysql>SELECTCONCAT_WS(',','Firstname','Last
CONCAT_WS() stands for Concatenate Name'
With Separator and is a special form of );
CONCAT(). The first argument is the +------------------------------------------------+
separator for the rest of the arguments. | CONCAT_WS(',','Firstname','LastName')
The separator is added between the |
strings to be concatenated. The separator +------------------------------------------------+
can be a string, as can the rest of the | Firstname,LastName |
arguments. If the separator is NULL, the +------------------------------------------------+
result is NULL. 1rowinset (0.00 sec)
5 FORMAT(X,D) mysql>SELECTFORMAT(12332.123456,4);
Formats the number X to a format like +------------------------------------------------+
'#,###,###.##', rounded to D decimal | FORMAT(12332.123456, 4) |
places, and +------------------------------------------------+
returnstheresultasastring.IfDis0,theresulth | 12,332.1235 |
as no decimal point or fractional part. + +
1rowinset (0.00 sec)
6 INSERT(str,pos,len,newstr) mysql>SELECTINSERT('Quadratic',3,4,'What');
Returns the string str, with the substring +------------------------------------------------+
beginning at | INSERT('Quadratic',3,4,'What') |
positionposandlencharacterslongreplaced +------------------------------------------------+
by the string newstr. Returns the original | QuWhattic |
string if pos is not within the length of the +------------------------------------------------+
string. Replaces the rest of the string from 1rowinset (0.00 sec)
position pos if len is not within the length
of the rest of the string. Returns NULL if
any argument is NULL.
7 INSTR(str,substr) mysql>SELECTINSTR('foobarbar','bar');
Returns the position of the first +------------------------------------------------+
occurrence |of INSTR('foobarbar','bar') |
substringsubstrinstringstr.Thisisthesameas+------------------------------------------------+
the two-argument form of LOCATE(), | 4 |
except that the order of the arguments is + +
reversed. 1rowinset (0.00 sec)
8 LOWER(str) mysql>SELECTLOWER('QUADRATICALLY');
Returnsthestringstrwithallcharacterschang +------------------------------------------------+
edto lowercase according to the current | LOWER('QUADRATICALLY') |
character set mapping. +------------------------------------------------+
| quadratically |
+ +
1rowinset (0.00 sec)
9 LTRIM(str) mysql>SELECTLTRIM('barbar');
Returnsthestringstrwithleadingspacecharac +------------------------------------------------+
ters removed. | LTRIM('barbar') |
+ +
| barbar |
+ +
1rowinset (0.00 sec)
DateandTimeFunctions

S.No. Function Example

1 CURDATE() mysql>SELECTCURDATE();
+ +
Returns the current date as a value in | CURDATE() |
'YYYY-MM- DD' or YYYYMMDD format, +----------------------------------------------------------+
depending on whether the function is | 1997-12-15 |
used in a string or numeric context. + +
1rowinset(0.00sec)

mysql>SELECTCURDATE()+ 0;
+ +
| CURDATE()+0 |
+ +
| 19971215 |
+ +
1rowinset(0.00sec)
2 CURTIME() mysql>SELECTCURTIME();
+ +
Returns the current time as a value in | CURTIME() |
'HH:MM:SS' or HHMMSS format, +----------------------------------------------------------+
depending on whether the function is | 23:50:26 |
usedin a string or numeric context.The + +
value is expressed in the current time 1rowinset(0.00sec)
zone.
mysql>SELECTCURTIME()+0;
+ +
| CURTIME()+0 |
+ +
| 235026 |
+ +
1rowinset(0.00sec)
3 DATE(expr) mysql>SELECTDATE('2003-12-3101:02:03');
+ +
Extractsthedatepartofthedateordatetime | DATE('2003-12-3101:02:03')
expression expr. |
+ +
| 2003-12-31 |
+ +
1rowinset(0.00sec)
4 DATEDIFF(expr1,expr2) mysql>SELECTDATEDIFF('1997-12-31
23:59:59','1997-12-30');
DATEDIFF() returns expr1 . expr2 +----------------------------------------------------------+
expressed as a | DATEDIFF('199712-3123:59:59','1997-
valueindaysfromonedatetotheother.expr1 12-30') |
and expr2 are date or date-and-time +----------------------------------------------------------+
expressions. Only the date parts of the | 1 |
values are used in the calculation. + +
1rowinset(0.00sec)
METADATA
ObtainingDatabaseMetadata
MySQLprovidesseveralwaystoobtaindatabasemetadata—thatis,informationaboutdatabasesandthe
objects in them:
 SHOWstatementssuchasSHOWDATABASESorSHOWTABLES
 TablesintheINFORMATION_SCHEMAdatabase
 Command-lineprogramssuchasmysqlshowormysqldump

Thefollowingsectionsdescribehowtouseeachoftheseinformationsourcestoaccessmetadata.

ObtainingMetadatawithSHOW
MySQL provides a SHOWstatement that displays many types of database metadata. SHOWis helpful
for
keepingtrackofthecontentsofyourdatabasesandremindingyourselfaboutthestructureofyourtables.The
following examples demonstrate a few uses for SHOWstatements.
Listthedatabasesyoucanaccess:
SHOW DATABASES;
DisplaytheCREATEDATABASEstatementforadatabase:
SHOWCREATEDATABASEdb_name;

Listthetablesinthedefaultdatabaseoragivendatabase:
SHOWTABLES;
SHOWTABLESFROMdb_name;
SHOWTABLESdoesn’tshowTEMPORARYtables. Display the
CREATE TABLEstatement for a table:
SHOWCREATETABLEtbl_name;
Displayinformationaboutcolumnsorindexesinatable:
SHOWCOLUMNSFROMtbl_name; SHOW
INDEX FROM tbl_name;
TheDESCRIBEtbl_nameandEXPLAINtbl_namestatementsaresynonymouswithSHOW COLUMNS
FROMtbl_name.
Displaydescriptiveinformationabouttablesinthedefaultdatabaseorinagivendatabase:
SHOWTABLESTATUS;
SHOWTABLESTATUSFROMdb_name;
SeveralformsoftheSHOWstatementtakea LIKE'pattern'clausepermittingapatterntobegiventhat limits
the scope of the output. MySQL interprets 'pattern' as an SQL pattern that may include the ‘%’ and ‘_’
wildcard characters. For example, this statement displays the names of columns in the studenttable
that begin with ‘s’:
mysql>SHOWCOLUMNSFROMstudentLIKE's%';

+------------+------------------+------+-----+---------+-----------------+

|Field |Type |Null|Key |Default |Extra |

+------------+------------------+------+-----+---------+-----------------+

|sex | enum('F','M') |NO| | NULL | |


TomatchaliteralinstanceofawildcardcharacterinaLIKEpattern,precedeitwithaback-slash.Thisis
commonlydonetomatchaliteral‘_’,whichoccursfrequentlyindatabase,table,andcolumnnames.
AnySHOWstatementthatsupportsaLIKEclausecanalsobewrittentouseaWHEREclause.Thestatement
displaysthesamecolumns, but WHEREprovides more flexibility about specifying which rows to return.
The WHEREclauseshouldrefertotheSHOWstatementcolumnnames.Ifthecolumnnameisareservedwordsuch
as KEY, specify it as a quoted identifier. This statement determines which column in thestudenttable is
theprimarykey:
mysql>SHOWCOLUMNSFROMstudentWHERE`Key`= `PRI`;
+------------+------------------+------+-----+---------+---------------------------------------+
|Field | Type |Null|Key |Default |Extra |

|student_id|int(10)unsigned|NO|PRI|NULL |auto_increment|
+------------+------------------+------+-----+---------+---------------------------------------+

MySQL:Sequences(AUTO_INCREMENT)
This MySQL tutorial explains how to create sequences using the AUTO_INCREMENT attribute in MySQL
with syntax and examples.
Description
In MySQL, you can create a column that contains a sequence of numbers (1, 2, 3, and so on) by using
the AUTO_INCREMENT attribute. The AUTO_INCREMENT attribute is used when you need to create a
unique number to act as a primary key in a table.
Syntax
Thesyntaxtocreateasequence(orusetheAUTO_INCREMENTattribute)inMySQLis:

CREATETABLEtable_name (
AUTO_INCREMENT
TheattributetousewhenyouwantMySQLtoassignasequenceofnumbersautomaticallytoafield (in essence,
column1datatypeNOTNULLAUTO_INCREMENT,
creating an autonumber field). column2 datatype
NULL orNOT NULL
[ NULL | NOT NULL ],
Each column should be defined as NULL or NOT NULL. If this parameter is omitted, the database
assumes ...NULL as the default.
);
Note
You can use the LAST_INSERT_IDfunction to find last value assigned by the AUTO_INCREMENTfield.

Example
Let'slookatanexampleofhowto useasequenceortheAUTO_INCREMENTattributeinMySQL. For example:

CREATETABLE contacts

(contact_idINT(11)NOTNULL AUTO_INCREMENT,

last_nameVARCHAR(30)NOTNULL, first_name
VARCHAR(25),

This MySQL AUTO_INCREMENT example creates a table called contacts which has 4 columns and one
primary key:
 The first column is called contact_id which is created as an INT datatype (maximum 11 digits in length)
and can not contain NULL values. It is set as an AUTO_INCREMENT field which means that it is an
autonumber field (starting at 1, and incrementing by 1, unless otherwise specified.)
 The second column is called last_name which is a VARCHAR datatype (maximum 30 characters in
length) and can not contain NULL values.
 The third column is called first_name which is a VARCHAR datatype (maximum 25 characters in length)
and can contain NULL values.
 ThefourthcolumniscalledbirthdaywhichisaDATEdatatypeandcancontainNULL values.
 Theprimarykeyiscalled contacts_pkandissettothe contact_idcolumn.
SetAUTO_INCREMENTstartingvalue
Now that you've created a table using the AUTO_INCREMENT attribute, how can you change the
starting value for the AUTO_INCREMENT field if you don't want to start at 1?
You can use the ALTER TABLE statement to change or set the next value assigned by the
AUTO_INCREMENT.

Syntax
InMySQL,thesyntaxtochangethestartingvalueforanAUTO_INCREMENTcolumnusingtheALTER TABLE
statement is:

ALTERTABLEtable_nameAUTO_INCREMENT= start_value;
table_name
ThenameofthetablewhoseAUTO_INCREMENT valueyou wish to change.Sinceatablein MySQL can only
contain one AUTO_INCREMENT column, you are only required to specify the table name that contains
the sequence. You do not need to specify the name of the column that contains the AUTO_INCREMENT
value.

start_value
ThenextvalueinthesequencetoassignintheAUTO_INCREMENT column.

Example
Let'slookatanexampleofhowtochangethestartingvaluefortheAUTO_INCREMENTcolumnina table in
MySQL.
Forexample:

ALTERTABLEcontactsAUTO_INCREMENT=50;
ThisMySQLAUTO_INCREMENTexamplewouldchangethenextvalueintheAUTO_INCREMENTfield (ie: next
value in the sequence) to 50 for the contact_id field in the contacts table.
PYTHON

Python is a general-purpose interpreted, interactive, object-oriented, and high- level programming


language. It was created by Guido van Rossum during 1985-
1990.LikePerl,PythonsourcecodeisalsoavailableundertheGNUGeneralPublic License (GPL). It has
become famous because of its apparent and easily understandable syntax, portability and easy to learn.

FactsAboutPython

 PythonisderivedfromprogramminglanguagessuchasABC,Modula3,small talk, Algol-68.


 Pythonpageisafilewitha.pyextensionthatcontainscouldbethe combination of HTML Tags and Python
scripts.
InDecember1989thecreatordevelopedthe1stpythoninterpreterasa
andthenon16October2000,Python2.0wasreleasedwithmany
hobb
newfeatures.
 On3rdDecember2008, includes new wasreleasedwithmoretestingand
features. Python3.0
 Pythonisanopensourcescriptinglanguage.
 Pythonisfreetodownloadanduse.
 PythonisoneoftheofficiallanguagesatGoogle.

Featuresof Python

 Interpreted Language: Python is processed at runtime by


Python Interpreter.
 Object-Oriented Language: It supports object-oriented
features and techniques of programming.
 Interactive Programming Language: Users can interact with the python interpreter directly for writing
programs.
 Easylanguage:Pythoniseasytolearnlanguageespeciallyforbeginners.
 StraightforwardSyntax: Theformationofpythonsyntaxissimpleand straightforward which also makes it
popular.
 Easytoread:Pythonsource-codeisclearlydefinedandvisibletothe eyes.
 Portable: Python codescanberunonawidevariety ofhardwareplatforms having the same interface.
 Extendable:Userscanaddlowlevel-modulestoPython interpreter.
 Scalable:Pythonprovidesanimprovedstructureforsupportinglarge programs then shell-scripts.
Pythonisusedtocreatewebanddesktopapplications,andsomeofthemost
popularwebapplicationslikeInstagram,YouTube, Spoti allhasbeendeveloped
inPython,andyoucanalsodevelopnextbigthingbyusing Python.

PYTHONInstallation:

PythonsourcecodeisavailableundertheGNUGeneralPublicLicense(GPL).

Pythoninterpreterisfree,anddownloadsareavailableforallmajorplatforms (Windows, Mac OS, and Linux )


in the form of source and binary. You can download it from the Python Website: python.org.

Python GUI
TherearevariousGUIbasedPythonIDEthatpythonprogrammerscanuse for better coding experience.
NamesofsomePythoninterpreters are:

 PyCharm
 PythonIDLE
 ThePythonBundle
 pyGUI
 SublimeTextetc.

Interpreter:

Interpretercanbetermedassystemsoftwarewhichhasthecapabilitytoread and execute the program,


rather you can say interpret programs. This interpretation includes the source code of high-level
language, programs that arepre-compiledaswellasscripts.Itistobenotedthat,interpreterinterprets
programline-by-line, which means it translates one statement at a single go. This feature makes easy for
programmers to check any particular line at the time of debugging, but slowsdown the overall time of
execution of the entire program.

BasicsofPYTHON

Pythonisaninterpretedprogramminglanguage.Pythonsourcecodeis
compiledtobytecodeasa .py file,andthisbytecodecanbeinterpreted.

TherearetwomodesforusingthePythoninterpreter:

1. InteractiveMode
2. ScriptMode
InteractiveMode
Without passing python script file to the interpreter, directly execute code to Python prompt.
Example:

>>>2+6
Output:

8
Thechevronatthebeginningofthe1stline,i.e.,thesymbol>>>isaprompt the python interpreter uses to

indicate that it is ready. If the programmer types 2+6, the interpreter replies 8.

ScriptMode

Alternatively, programmers can store Python script source code in a file with the .py extension, and use
the interpreter to execute the contents of the file. To execute the script by the interpreter, you have to
tell the interpreter the name ofthefile. Forexample, ifyouhaveascriptname MyFile.pyandyou're working
on Unix, to run the script you have to type:

pythonMyFile.py

Working with the interactive mode is better when Python programmers deal
withsmallpiecesofcodeasyoucantypeandexecutethemimmediately, but when the code is more than 2-4
lines, using the script for coding can help to modify and use the code in future.

Python-VariableTypes

Variables are nothing but reserved memory locations to store values. This means that when you create
a variable you reserve some space in memory.
Based on the data type of a variable, the interpreter allocates memory and decideswhatcanbestored
inthereserved memory.Therefore,byassigning different data types to variables, you can store integers,
decimals or characters in these variables.
AssigningValuestoVariables
Python variables do not need explicit declaration to reserve memory space.
Thedeclarationhappensautomaticallywhenyouassignavaluetoavariable. The equal sign (=) is used to
assign values to variables.
The operandtotheleft ofthe= operatoristhename ofthevariableandthe operandtotherightofthe=
operatoristhevaluestoredinthevariable.For example −

Here,100,1000.0and"John"arethevaluesassignedtocounter,
#!/usr/bin/python miles,and
namevariables,respectively.Thisproducesthefollowingresult−
counter = 100 #Anintegerassignment miles
100
MultipleAssignment
= 1000.0 # A floating point
1000.0
Pythonallowsyoutoassignasinglevaluetoseveralvariablessimultaneously.
Forexample−
name = "John" #Astring
Here,anintegerobjectiscreatedwiththevalue1,andallthreevariablesare
a =b=c=1 assigned to the same memory
print counter
location. You can also assign multiple objects to multiple variables. For example −

a,b,c=1,2,"john"
printmiles
Here,twointegerobjectswithvalues1and2areassignedtovariablesaand b respectively, and one string
object with the value "john" isassigned to the variable c.
StandardDataTypes
The data stored in memory can be of many types. For example, a person's age is stored as a numeric
value and his or her address is stored as alphanumeric characters. Python has various standard data
types that are used to define the operations possible on them and the storage method for each of
them.
Pythonhasfivestandarddatatypes−

o Numbers
o String
o List
o Tuple
o Dictionary

PythonNumbers
Number data types store numeric values. Number objects are created when you assign a value to
them. For example –

var1=1
Youcanalsodeletethereferencetoanumberobjectbyusingthedel statement. The syntax of the del statement is –
var2=10

delvar1[,var2[,var3[................,varN]]]]
Youcandeleteasingleobjectormultipleobjectsbyusingthedelstatement.
Forexample−

Pythonsupportsfourdifferentnumericaltypes−
delvar

 delvar_a,var_b
int(signedintegers)
 long(longintegers,theycanalsoberepresentedinoctaland hexadecimal)
 float(floatingpointrealvalues)
 complex(complexnumbers)
Examples
 Herearesomeexamplesofnumbers−

int long float complex

10 51924361L 0.0 3.14j

100 -0x19323L 15.20 45.j

-786 0122L -21.9 9.322e-36j

080 0xDEFABCECBDAECBFBAEl 32.3+e18 .876j

-0490 535633629843L -90. -.6545+0J

-0x260 -052318172735L -32.54e100 3e+26J

0x69 -4721885298529L 70.2-E12 4.53e-7j

 Pythonallowsyoutousealowercaselwithlong,butitisrecommended that you use only an uppercase L to


avoid confusion with the number
1. PythondisplayslongintegerswithanuppercaseL.
 A complex number consists of an ordered pair of real floating-point numbers denoted byx + yj, where x
andy are the real numbers and j is the imaginary unit.

PythonStrings
Strings in Python are identified as a contiguous set of characters represented in the quotation marks. Python
allows for either pairs of single or double quotes.
Subsetsofstringscanbetakenusingthesliceoperator([]and[:])withindexes starting at 0 in the beginning of the
string and working their way from -1 at the end.
Theplus(+)signisthestringconcatenationoperatorandtheasterisk(*)isthe
repetitionoperator.Forexample−

#!/usr/bin/python str='HelloWorld!'
print str#Printscompletestring
print str[0]#Prints firstcharacterofthe string
print str[2:5]#Printscharactersstartingfrom3rdto5th
print str[2:] #Printsstringstartingfrom3rd character
print str*2 #Printsstringtwo times

printstr+"TEST"#Printsconcatenatedstring
Thiswillproducethefollowingresult−

HelloWorld!
PythonLists
ListsarethemostversatileofPython'scompounddatatypes.Alistcontainsitems
H separated by commasand
enclosed within squarebrackets([]). To someextent, lists are similar to arrays in C. One difference between
them isllo
that all the items belonging to a list can be of different data type.
The values stored in a list can be accessed using the slice operator ([ ] and [:])
withindexesstartingat0inthebeginningofthelistandworkingtheirwaytoend
lloWorld!
-1.Theplus(+)signisthelistconcatenationoperator,andtheasterisk(*)isthe
repetitionoperator.Forexample−

Thisproducethefollowingresult−
#!/usr/bin/python
['abcd',786,2.23,'john',70.200000000000003]
list=['abcd',786,2.23,'john',70.2] tinylist = [123,
abcd
[786, 2.23]
'john']

print list #Printscompletelist

print list[0] #Printsfirstelementofthelist

print list[1:3] # Prints elements starting from 2nd till 3rd print

list[2:] #Printselementsstartingfrom3rdelement print tinylist

* 2# Prints list two times


[2.23,'john', 70.200000000000003]
[123,'john',123,'john']
['abcd',786,2.23,'john',70.200000000000003,123,'john']

PythonTuples

Atupleisanothersequencedatatypethatissimilartothelist.Atupleconsistsof a number of values separated by


commas. Unlike lists, however, tuples are enclosed within parentheses.
The main differences between lists and tuples are: Lists are enclosed in brackets ( [ ] ) and their elements
and size can be changed, while tuples are enclosed in
parentheses(())andcannotbeupdated.Tuplescanbethoughtofasread-only lists. For example −

Thisproducethefollowingresult−
#!/usr/bin/python

Thefollowingcodeisinvalidwithtuple,becauseweattemptedtoupdateatuple,
('abcd',786,2.23,'john',70.200000000000003) which is not allowed. Similar case is
possible with lists –
abcd
tuple=('abcd',786,2.23,'john',70.2)
(786, 2.23) tinytuple = (123,

'john')
(2.23,'john', 70.200000000000003)

print tuple #Printscomplete list

print tuple[0] #Printsfirst elementofthe list

print tuple[1:3] # Prints elements starting from 2nd till 3rd print

tuple[2:] #Printselementsstartingfrom3rdelement print

tinytuple * 2 # Prints list two times


#!/usr/bin/python

tuple=('abcd',786, 2.23,'john', 70.2)


list = [ 'abcd', 786 , 2.23, 'john', 70.2] tuple[2] = 1000#Invalidsyntaxwithtuple

list[2]=1000 #Validsyntaxwithlist

PythonDictionary
Python'sdictionariesarekindofhashtabletype.Theyworklikeassociativearrays or hashes found in Perl and
consist of key-value pairs. A dictionary key can be
almostanyPythontype,butareusuallynumbersorstrings.Values,ontheother hand, can be any arbitrary Python
object.
Dictionariesareenclosedbycurlybraces({})andvaluescanbeassignedand
accessedusingsquarebraces([]).Forexample−

#!/usr/bin/python dict = {}
dict['one']= "Thisis one"

dict[2] ="This istwo"

tinydict={'name':'john','code':6734,'dept':'sales'}

printdict['one'] print dict[2]


#Printsvaluefor'one'key # Prints value for 2 key
print tinydict #Printscompletedictionary

print tinydict.keys()#Printsallthekeys
printtinydict.values()#Printsallthevalues

Thisproducethefollowingresult−

Thisisone
This is two

{'dept':'sales','code':6734,'name':'john'} ['dept', 'code',


'name']
Dictionaries havenoconcept of orderamong elements. It is incorrectto say that the elements are "out of
order"; they are simply unordered.

Python-BasicOperators
Operatorsaretheconstructswhichcanmanipulatethevalueof operands.
Consider the expression 4 + 5 = 9. Here, 4 and 5 are called operandsand+ is called operator.

TypesofOperator
Pythonlanguagesupportsthefollowingtypesofoperators.

o ArithmeticOperators
o Comparison(Relational)Operators
o AssignmentOperators
o LogicalOperators
o BitwiseOperators
o MembershipOperators
o IdentityOperators
Python-DecisionMaking

Decisions inaprogram areusedwhenthe programhasconditionalchoicesto execute code block.Let's take


an example of traffic lights, where different
colorsoflightslitupatdifferentsituationsbasedontheconditionsoftheroad or any specific rule.

Itisthepredictionofconditionsthatoccurwhileexecutingaprogramtospecifyactions.
MultipleexpressionsgetevaluatedwithanoutcomeofeitherTRUEorFALSE.Theseare logicaldecisions, and Python
alsoprovides decision-making statements that tomake
decisionswithinaprogramforanapplicationbasedontheuserrequirement.
Pythonprovidesvarioustypesofconditionalstatements:

Statement Description

if Statements ItconsistsofaBooleanexpressionwhichresultsiseitherTRUEorFALSE
followed by one or more statements.

ifelse Statements It also contains a Boolean expression. The if statement is followed by an


optional else statement & if the expression results in FALSE, then else
statement gets executed. It is also called alternative execution in which
there are two possibilities of the condition determined in which any one
of them will get executed.
Nested Statements Wecanimplementifstatementandorif-elsestatementinsideanother iforif-
elsestatement.Heremorethanoneifconditionsareapplied& there can be
more than one if within elif.

if Statement
Thedecision-makingstructurescanberecognizedandunderstoodusing flowcharts.
Figure-IfconditionFlowchart:

Syntax:

ifexpression:

Example:

a=15

ifa>10:

Output:

aisgreater

ifelseStatements

Figure-IfelseconditionFlowchart:
Syntax:

if expression:

#executeyourcode

else:

Example:

a=15

b=20

ifa>b:

print("aisgreater") else:

Output:

bis greater

elifStatements

elif-isakeywordusedinPythonreplacementofelseiftoplaceanothercondition in the program. This is called


chained conditional.
Figure-elifconditionFlowchart:
Syntax:

if expression:

#executeyourcode

elif expression:

#executeyourcode

else:

#executeyourcode

Example:

a=15

b=15

ifa>b:

print("aisgreater")

elif a == b:

print("bothareequal") else:

print("bisgreater")

Output:

bothareequal
SingleStatementCondition

If the block of an executable statement of if -clause contains only a single line, programmers can write it on the
same line as a header statement.
Example:

a=15

if(a==15):print("Thevalueofais15")

PHYTHONLOOPS:
In programming, loops are a sequence of instructions that does a specific set of instructions or tasks
based on some conditions and continue the tasks until it reaches certain conditions.
It is seen that in programming, sometimes we need to write a set of instructions repeatedly -which is a
tedious task and the processing also takes time. So in programming, we use iteration technique to
repeat the same or similar type of tasks based on the specified condition.

Statements are executed sequentially, but there sometimes occur such cases where programmers need
to execute a block of code several times. The control
structuresofprogramminglanguagesallowustoexecuteastatementorblockof statement repeatedly.

TypesofLoopsinPython

Pythonprovidesthreetypesofloopingtechniques:

Loop Description

forLoop Thisistraditionallyusedwhenprogrammershadapieceof code and wanted to


repeat that 'n' number of times.

whileLoop The loop gets repeated until the specific Boolean condition is met.

NestedLoops Programmers can use one loop inside another; i.e., they can use for loop
inside while or vice -versa or for loop inside for loop or while inside while.

forLoop

Thegraphicalrepresentationofthelogicbehindforloopingisshown below:

Figure-forloop Flowchart:
Syntax:

foriterating_varinsequence:

Example01:

forxinrange(0,3):

Output:

Loopexecution0

Loopexecution1

Example02:

forletterin'TutorialsCloud':

Output:
Currentletteris:T Currentletteris:u Current letter is : t Currentletteris:o Current letteris: r Current letter is : i Currentletteris:a Current lett
Currentletteris:s Currentletteris:C Current letter is : l Currentletteris:o Currentletteris:u
Currentletteris:d

whileLoop

Thegraphicalrepresentationofthelogicbehindwhileloopingisshown below:

Figure-whileloopFlowchart:

Syntax:

whileexpression:

Example:

#initializecountvariableto1 count =1

whilecount<6: print

(count) count+=1

#theabovelinemeanscount=count+1

Output:
1

2
3

NestedLoops
Syntax:

for iterating_var in sequence:

foriterating_varinsequence:

#executeyourcode

Example:

for g in range(1, 6):

forkinrange(1,3):

print("%d*%d=%d"%(g,k,g*k))
Output:

1*1=1

1*2=2

2*1=2

2*2=4

3*1=3

3*2=6

LoopControlStatements

Thesestatementsareusedtochangeexecutionfromitsnormalsequence. Python supports three


types of loop control statements:
PythonLoopControlStatements

ControlStatements Description

Breakstatement It is used to exit a while loop or a for loop. It terminates the


looping&transfersexecutiontothestatementnexttotheloop.

Continuestatement Itcausestheloopingtoskiptherestpartofitsbody&startre- testing its


condition.

Passstatement It is used in Python to when a statement is required


syntactically,andtheprogrammerdoesnotwanttoexecute any code block
or command.

Breakstatement
Syntax:

break

Example:

count=0

whilecount<=100:print(count)count+=1ifcount>=3: break

Output:

Continuestatement
Syntax:

continue

Example:

forxin range(10):

#checkwhetherxiseven if x % 2

== 0:

continue
Output:

PassStatement
Syntax:

pass

Example:

forletterin'TutorialsCloud': if
letter == 'C':

pass

Output:

Currentletteris:T
Currentletteris:u Current
letter is : t
Currentletteris:o Current
letteris: r Current letter
is : i Currentletteris:a
Current letter is : l
Currentletteris:s Pass
block

Currentletteris:C Current
letter is : l
Currentletteris:o
Currentletteris:u
PYTHONFUCNTIONS:
Afunctionisablockoforganized,reusablecodethat isusedtoperform asingle,related
action.Functionsprovidebettermodularityforyourapplicationandahighdegreeofcode reusing.
As you already know, Python gives you many built-in functions like print(), etc. but you can also create your
own functions. These functions are called user-defined functions.
DefiningaFunction
You can define functions to provide the required functionality. Here are simple rules to define a function in
Python.
 Function blocks begin with the keyword def followed by the function name and parentheses ( ( ) ).
 Any input parameters or arguments should be placed within these parentheses. You can also define
parameters inside these parentheses.
 The first statement of a function can be an optional statement - the documentationstring of the function or
docstring.
 Thecodeblockwithineveryfunctionstartswithacolon(:)andisindented.
 The statement return [expression] exits a function, optionally passing back an expression to the caller. A
return statement with no arguments is the same as return None.

Syntax
By default, parameters have a positional behavior and you need to inform them in thesame order
deffunctionname(parameters):
that they were defined.
Example "function_docstring"
function_suite
Thefollowingfunctiontakesastringasinputparameterandprintsitonstandardscreen.

CallingaFunction
defprintme(str ):
Definingafunctiononlygivesitaname,specifiestheparametersthataretobeincluded in the function and
"Thisprintsapassedstringintothisfunction"
structures the blocks of code.
print str structure of a function is finalized, you can execute it by calling it from another
Once the basic
function or directly from the Python prompt. Following is the example to call printme() function −
Whentheabovecodeisexecuted,itproducesthefollowingresult−
I'mfirstcalltouserdefinedfunction!
Again second call to the same
#!/usr/bin/python

#Functiondefinitionishere
def printme( str ):

"Thisprintsapassedstringintothisfunction"
print str

return;
Passbyreferencevsvalue
All parameters (arguments) in thePython languagearepassed by reference. It means if
youchangewhataparameterreferstowithinafunction,thechangealsoreflectsbackin the calling function. For
example −
Here,wearemaintainingreferenceofthepassedobjectandappendingvaluesinthe
sameobject.So,thiswouldproducethefollowingresult−
#!/usr/bin/python
Thereisonemoreexamplewhereargumentisbeingpassedbyreferenceandthe reference is being overwritten inside
Valuesinsidethefunction:[10, 20,30,[1,2,3,4]]
the called function.
#Functiondefinitionishere
def changeme( mylist ):
Valuesoutsidethefunction:[10,20,30,[1,2,3,4]]
#!/usr/bin/python
"Thischangesapassedlistintothisfunction"mylist.append(
#Functiondefinitionishere
[1,2,3,4]);
def changeme( mylist ):
print"Valuesinsidethefunction:",mylist
"Thischangesapassedlistintothisfunction"
return
mylist=[1,2,3,4];#Thiswouldassignewreferenceinmylist
print "Values inside the function: ", mylist

return

#Nowyoucancallchangemefunction
The parameter mylist is local to the function changeme. Changing mylist within the function does not affect
mylist. The function accomplishes nothing and finally this would produce the following result −

FunctionArguments
Valuesinsidethefunction:[1,2,3,4]
Youcancallafunctionbyusingthefollowingtypesofformalarguments−
Valuesoutsidethefunction:[10,20,30]
o Requiredarguments
o Keywordarguments
o Defaultarguments
o Variable-lengtharguments
Requiredarguments
Required arguments are the arguments passed to a function in correct positional order.
Here,thenumberofargumentsinthefunctioncallshouldmatchexactlywiththefunction definition.
Tocallthefunctionprintme(),youdefinitelyneedtopassoneargument,otherwiseit
givesasyntaxerrorasfollows−

Whentheabovecodeisexecuted,itproducesthefollowingresult−
#!/usr/bin/python

#Functiondefinitionishere
Keywordarguments
Traceback(mostrecentcalllast):
def printme(
Keyword str are
arguments ): related to the function calls. When you use keyword arguments in a
File"test.py",line11,in<module>printme
function call, the caller identifies the arguments by the parameter name.
"Thisprintsapassedstringintothisfunction"
();
This allows you to skip arguments or place them out of order because the Python interpreter is able
print str
to use the keywords provided to match the values with parameters. You can also make keyword
calls to the printme() function in the following ways −
Whentheabovecodeisexecuted,itproducesthefollowingresult−

The following example gives more clear picture. Note that the order of parameters does not matter.
#!/usr/bin/python
My string
#!/usr/bin/python
#Functiondefinitionishere
#Functiondefinitionishere def printinfo( name, age ):
"Thisprintsapassedinfointothisfunction"
def printme( str ): print "Name: ", name
print"Age",age return;
"Thisprintsapassedstringintothisfunction"
print str
#Nowyoucancallprintinfofunction printinfo( age=50, name="miki" )

Whentheabovecodeisexecuted,itproducesthefollowingresult−
Name:mik
i Age50
Defaultarguments
Adefaultargumentisanargumentthatassumesadefaultvalueifavalueisnotprovided in the function call for that
argument. The following example gives an idea on default arguments, it prints default age if it is not passed

Whentheabovecodeisexecuted,itproducesthefollowingresult−

Name:mik
#!/usr/bin/python
i Age50
Name:mik
Variable-lengtharguments
i
# Age35
Function definition is
Youmayneedtoprocessafunctionformoreargumentsthanyouspecifiedwhiledefining the function. These
hereare called variable-length arguments and are not named in the function definition, unlike
arguments
requireddefprintinfo(name,age=35):
and default arguments.
Syntaxforafunctionwithnon-keywordvariableargumentsisthis−
"Thisprintsapassedinfointothisfunction"
print "Name: ", name
Anasterisk(*)isplacedbeforethevariablenamethatholdsthevaluesofallnonkeyword variable arguments. This
deffunctionname([formal_args,]*var_args_tuple):
tuple remains empty if no additional arguments are specified during the function call. Following is a simple
print"Age",age
"function_docstring"
example − return;
#!/usr/bin/python
function_suite
#Functiondefinitionishere
defprintinfo(arg1,*vartuple):
"Thisprintsavariablepassedarguments" print "Output is: "
printarg1
forvarinvartuple: print var
return;
#Nowyoucancallprintinfofunction printinfo( 10 )
printinfo(70,60,50)

Whentheabovecodeisexecuted,itproducesthefollowingresult−
Outputis
: 10

Outputis
: 70
TheAnonymousFunctions
These functions are called anonymous because they are not declared in the standard manner by using the
def keyword. You can use the lambda keyword to create small anonymous functions.
 Lambdaformscantakeanynumberofargumentsbutreturnjustonevalueintheform of an expression. They
cannot contain commands or multiple expressions.
 An anonymous function cannot be a direct call to print because lambda requires an expression
 Lambda functions have their own local namespace and cannot access variables other than those in their
parameter list and those in the global namespace.
 Although it appears that lambda's are a one-line version of a function, they are not equivalent to inline
statements in C or C++, whose purpose is by passing function stack allocation during invocation for
performance reasons.
Syntax
Thesyntaxoflambdafunctionscontainsonlyasinglestatement,whichisasfollows−

Followingistheexampletoshowhowlambdaformoffunctionworks−
lambda[arg1[,arg2,. . . .argn]]:expression

#!/usr/bin/python
Whentheabovecodeisexecuted,itproducesthefollowingresult–
#Functiondefinitionishere
Valueoftotal:30
sum=lambdaarg1,arg2:arg1+ arg2;
Valueoftotal:40

# Now you can call sum as a function


ThereturnStatement
Thestatementreturn[expression]exitsafunction,optionallypassingbackanexpression to the caller. A return
statement with no arguments is the same as return None.
Alltheaboveexamplesarenotreturninganyvalue.Youcanreturnavaluefromafunction
asfollows−

Whentheabovecodeisexecuted,itproducesthefollowingresult−
#!/usr/bin/python

ScopeofVariables
Insidethefunction:30
#Functiondefinitionishere
Allvariablesinaprogrammaynotbeaccessibleatalllocationsinthatprogram.This depends on where you have
declareddef
a sum( arg1, arg2 ):
variable.
Outsidethefunction:30
Thescopeofavariabledeterminestheportionoftheprogramwhereyoucanaccessa
#Addboththeparametersandreturnthem."
particularidentifier.TherearetwobasicscopesofvariablesinPython−
total = arg1 + arg2

o Globalvariables
print"Insidethefunction:",total
o Local variables
return total;
Globalvs.Localvariables
Variables that are defined inside a function body have a local scope, and those defined outside have a global
scope.
Thismeansthatlocalvariablescanbeaccessedonlyinsidethefunctioninwhichtheyare declared, whereas global
variables can be accessed throughout the program body by all
functions.Whenyoucallafunction,thevariablesdeclaredinsideitarebroughtintoscope. Following is a simple
example −

#!/usr/bin/python
total=0;#Thisisglobalvariable. # Function definition is here
defsum(arg1,arg2):
#Addboththeparametersandreturnthem."
total=arg1+arg2;#Heretotalislocalvariable. print "Inside the function local total : ", t
#Nowyoucancallsumfunction sum( 10, 20 );
print"Outsidethefunctionglobaltotal:",total

Whentheabovecodeisexecuted,itproducesthefollowingresult−
Inside the function local total :30
Outsidethefunctionglobaltotal:0

PYTHON–MODULES:
AmoduleallowsyoutologicallyorganizeyourPythoncode.Groupingrelated code into a module makes the
code easier to understand and use. A module is a Python object with arbitrarily named attributes that
you can bind and reference.
Simply, a module is a file consisting of Python code. A module can define functions, classes and
variables. A module can also include runnable code.

Example
ThePythoncodeforamodulenamedanamenormallyresidesinafilenamed
aname.py.Here'sanexampleofasimplemodule, support.py

def print_func( par


TheimportStatement
):
You can use any Python source file as a module by executing an import statement in some other
print"Hello:",par
Python source file. The import has the following syntax −
Whentheinterpreterencountersanimportstatement,it importsthemodule
ifthemoduleispresentinthesearchpath.Asearchpathisalistofdirectories that the interpreter searches
before importing a module. For example, to
importthemodulesupport.py,youneedtoputthefollowingcommandatthe top of the script −
importmodule1[,module2[,...moduleN]
#!/usr/bin/python

#Importmodulesupport
import support

Whentheabovecodeisexecuted,itproducesthefollowingresult−

Hello:Zara
Amoduleisloadedonlyonce,regardlessofthenumberoftimesitisimported. This prevents the module
execution from happening over and over again if multiple imports occur.

Thefrom...importStatement
Python'sfromstatementletsyouimportspecificattributesfromamoduleinto the current namespace. The
from...import has the following syntax −
Forexample,toimportthefunctionfibonaccifromthemodulefib,usethe
followingstatement−
frommodnameimportname1[,name2[,... nameN]]
This fromfibimport
statement does not import the entire module fib into the current
fibonacci
namespace;itjustintroducestheitemfibonaccifromthemodulefibintothe global symbol table of the
importing module.

Thefrom...import*Statement
Itisalsopossibletoimportallnamesfromamoduleintothecurrent
namespacebyusingthefollowingimportstatement−

This provides an easy way to import all the items from a module into the current namespace; however,
frommodnameimport*
this statement should be used sparingly.

PYTHON–FILESI/O

PrintingtotheScreen
Thesimplestwaytoproduceoutputisusingtheprintstatementwhereyoucanpasszero or more expressions
separated by commas. This function converts the expressions you pass into a string and writes the result to
standard output as follows −

#!/usr/bin/python
Thisproducesthefollowingresultonyourstandardscreen−

Pythonisreallyagreatlanguage,isn'tit?
ReadingKeyboardInput
Pythonprovidestwobuilt-infunctionstoreadalineoftextfromstandardinput,whichby
defaultcomesfromthekeyboard.Thesefunctionsare−

o raw_input
o input
o
Theraw_inputFunction
The raw_input([prompt]) function reads oneline from standard input and returns it asa string (removing the
trailing newline).
Thispromptsyoutoenteranystringanditwoulddisplaysamestringonthescreen.When
Ityped"HelloPython!",itsoutputislikethis−
#!/usr/bin/python
TheinputFunction
Enteryourinput:Hello Python
Theinput([prompt])functionisequivalenttoraw_input,exceptthatitassumestheinput is a valid Python
str=raw_input("Enteryourinput:");
expression and returns the
Receivedinput evaluated
is:Hello result to you.
Python
Thiswouldproducethefollowingresultagainsttheenteredinput−
Enteryourinput:[x*5forxinrange(2,10,2)]
#!/usr/bin/python
Recieved input is :[10, 20, 30, 40]
OpeningandClosingFiles
str=input("Enteryourinput:");
Untilnow,youhavebeenreadingandwritingtothestandardinputandoutput.Now,we will see how to use actual
data files.
Python provides basic functions and methods necessary to manipulate files by default. You can do most of
the file manipulation using a file object.
TheopenFunction
Before you can read or write a file, you have to open it using Python's built-in open() function. This
functioncreatesa file object,which wouldbe utilized to call other support methods associated with it.
Syntax

fileobject=open(file_name[,access_mode][,buffering])
Hereareparameterdetails−
 file_name − The file_name argument is a string valuethat contains thenameof the file that you want to
access.
 access_mode − The access_mode determines the mode in which the file has to be
opened,i.e.,read,write,append,etc.Acompletelistofpossiblevaluesisgivenbelow in the table. This is optional
parameter and the default file access mode is read (r).
 buffering−Ifthebufferingvalueissetto0,nobufferingtakesplace.Ifthebuffering
valueis1,linebufferingisperformedwhileaccessingafile.Ifyouspecifythebuffering
valueasanintegergreaterthan1,thenbufferingactionisperformedwiththeindicated buffer size. If negative, the
buffer size is the system default(default behavior).
Hereisalistofthedifferentmodesofopeningafile–
1 r
Opensafileforreadingonly.Thefilepointerisplacedatthebeginningofthefile.Thisis the default mode.
2 rb
Opens a file for reading only in binary format. The file pointer is placed at the beginning of the file. This is the
default mode.
3 r+
Opens a file for both reading and writing. The file pointer placed at the beginning of the file.
4 rb+
Opens a file for both reading and writing in binary format. The file pointer placed at the beginning of the file.
5 w
Opensafileforwritingonly.Overwritesthefileifthefileexists.Ifthefiledoesnotexist, creates a new file for writing.
6 wb
Opens a file for writing only in binary format. Overwrites the file if the file exists. If the file does not exist,
creates a new file for writing.
7 w+
Opens a file for both writing and reading. Overwrites the existing file if the file exists. If the file does not
exist, creates a new file for reading and writing.
8 wb+
Opens a file for both writing and reading in binary format. Overwrites the existing file if the file exists. If the
file does not exist, creates a new file for reading and writing.
9 a
Opens a file for appending. The file pointer is at the end of the file if the file exists. That
is,thefileisintheappendmode.Ifthefiledoesnotexist,itcreatesanewfileforwriting.
10 ab
Opens a fileforappending in binary format.Thefilepointer is attheend of thefileif the file exists. That is, the
file is in the append mode. If the file does not exist, it creates a new file for writing.
11 a+
Opensafileforbothappendingandreading.Thefilepointerisattheendofthefileifthe file exists. The file opens in
the append mode. If the file does not exist, it creates a new file for reading and writing.
12 ab+
Opens a file for both appending and reading in binary format. The file pointer is at the end of the file if the
file exists. The file opens in the append mode. If the file does not exist, it creates a new file for reading and
writing.
ThefileObjectAttributes
Onceafileisopenedandyouhaveonefileobject,youcangetvariousinformationrelated to that file.
Hereisalistofallattributesrelatedtofileobject−

Sr.No. Attribute& Description

file.closed
1 Returnstrueiffileisclosed,falseotherwise.

file.mode
2 Returnsaccessmodewith whichfilewas opened.

file.name
3 Returnsnameofthefile.

file.softspace
4 Returnsfalseifspaceexplicitlyrequiredwithprint,true otherwise.

Example

#!/usr/bin/

python # Open

a file

fo=open("foo.txt","wb")

print"Nameofthefile:",fo.name

print"Closedornot:",fo.closed

print "Opening mode : ",


Thisproducesthefollowingresult−

Theclose()Method
Nameofthefile:foo.txt
The close() method of a file object flushes any unwritten information and closes the file object, after which no
Closed or not :False
more writing can be done.
Pythonautomaticallyclosesafilewhenthereferenceobjectofafileisreassignedto
Opening mode :wb another file. It is a good practice to
use the close() method to close a file.
Syntax
fileObject.close();
Example
#!/usr/bin/python

#Opena file

fo=open("foo.txt","wb")

print"Nameofthefile:",fo.name
Thisproducesthefollowingresult−
Nameofthefile:foo.txt
ReadingandWritingFiles
The file object provides a set of access methods to make our lives easier. We would see how to use read()
and write() methods to read and write files.
Thewrite()Method
The write() method writes any string to an open file. It is important to note that Python strings can have binary
data and not just text.
Thewrite()methoddoesnotaddanewlinecharacter('\n')totheendofthestring−
Syntax
fileObject.write(string);
Here,passedparameteristhecontenttobewrittenintotheopenedfile.
Example
#!/usr/bin/python

#Opena file

fo=open("foo.txt","wb")

fo.write("Pythonisagreatlanguage.\nYeahitsgreat!!\n");
Theabovemethodwouldcreatefoo.txtfileandwouldwritegivencontentinthatfileand finally it would close that file.
If you would open this file, it would have following content.

Theread()Method
Pythonisagreatlanguage.
The read() method reads a string from an open file. It is important to note that Python strings can have binary
Yeahits
data. apart great!!
from text data.
Syntax

Here, passed parameter is the number of bytes to be read from the opened file. This method starts reading
fileObject.read([count]);
from the beginning of the file and if count is missing, then it tries to read as much as possible, maybe until
the end of file.
Example
Let'stakeafilefoo.txt,whichwecreatedabove.
#!/usr/bin/python

#Opena file

fo=open("foo.txt","r+")
str = fo.read(10);

print"ReadStringis:",str #
Thisproducesthefollowingresult−
ReadStringis :Python is
FilePositions
The tell() method tells you the current position within the file; in other words, the next read or write will
occur at that many bytes from the beginning of the file.
The seek(offset[, from]) method changes the current file position. The offset argument indicates the number
of bytes to be moved. The from argument specifies the reference position from where the bytes are to be
moved.
If from is set to 0, it means use the beginning of the file as the reference position and 1
meansusethecurrentpositionasthereferencepositionandifit isset to2thentheend of the file would be taken as
the reference position.
Example
Letustakeafilefoo.txt,whichwecreatedabove.
#!/usr/bin/python
#Opena file
fo=open("foo.txt","r+") str = fo.read(10);
print"ReadStringis:",str
#Checkcurrentposition position = fo.tell();
print"Currentfileposition:",position
#Repositionpointeratthebeginningonceagain position = fo.seek(0, 0);
str=fo.read(10);
print"AgainreadStringis:",str # Close opend file
fo.close()

Thisproducesthefollowingresult−
ReadStringis:Pythonis
Currentfileposition:10

RenamingandDeletingFiles
Python os module provides methods that help you perform file-processing operations,such as renaming and
deleting files.
Tousethismoduleyouneedtoimportitfirstandthenyoucancallanyrelatedfunctions.
Therename()Method
Therename()methodtakestwoarguments,thecurrentfilenameandthenewfilename.
Syntax

Exampleos.rename(current_file_name,new_file_name)
Followingistheexampletorenameanexistingfiletest1.txt−

Theremove()Method
#!/usr/bin/
You can use the remove() method to delete files by supplying the name of the file to be deleted as the
argument.
python import
Syntax
os
os.remove(file_name)
Example

Followingistheexampletodeleteanexistingfiletest2.txt−
#!/usr/bin/
python import
os
DirectoriesinPython
All files are contained within various directories, and Python has no problem handling
thesetoo.Theosmodulehasseveralmethodsthathelpyoucreate,remove,andchange directories.
Themkdir()Method
You can use the mkdir() method of the os module to create directories in the current
directory.Youneedtosupplyanargumenttothismethodwhichcontainsthenameofthe directory to be created.
Syntax
os.mkdir("newdir")
Example
Followingistheexampletocreateadirectorytestinthecurrentdirectory−
#!/usr/bin/
python import
os

#Createadirectory"test"os.mkd
Thechdir()Method
Youcanusethechdir()methodtochangethecurrentdirectory.Thechdir()methodtakes an argument, which is the
name of the directory that you want to make the current directory.
Syntax
os.chdir("newdir")
Example
Followingistheexampletogointo"/home/newdir"directory−
#!/usr/bin/
python import
os

Thegetcwd()Method
Thegetcwd()methoddisplaysthecurrentworkingdirectory.

Syntax
os.getcwd()
Example
Followingistheexampletogivecurrentdirectory−
#!/usr/bin/
python import
os
Thermdir()Method
Thermdir()methoddeletesthedirectory,whichispassedasanargumentinthemethod. Before removing a directory,
all the contents in it should be removed.
Syntax

Exampleos.rmdir('dirname')
Following is the example to remove "/tmp/test" directory. It is required to give fully
qualifiednameofthedirectory,otherwiseitwouldsearchforthatdirectoryinthecurrent directory.

File&DirectoryRelatedMethods
#!/usr/bin/
Therearethreeimportantsources,whichprovideawiderangeofutilitymethodstohandle and manipulate files &
python
directories importand Unix operating systems. They are as follows −
on Windows
o FileObjectMethods:Thefileobjectprovidesfunctionstomanipulatefiles.
os
o OSObjectMethods:Thisprovidesmethodstoprocessfilesaswellasdirectories.

PHYTHON–EXCEPTIONHANDLING
Sometimes we what to catch some or all errors that can possibly get generated; and as a programmer,
we want to be as specific as possible. So, python allows programmers to deal with errors smoothly.
Exceptions are events that are used to modify the flow of control through a program when the error
occurs. Exceptions get triggered automatically on finding errors in Python.

Theseexceptionsareprocessedusingfivestatements.Theseare:

1. try/except: catch the error and recover from exceptions hoist by


programmers or Python itself.
2. try/finally: Whether exception occurs or not, it automatically performs theclean-up action.
3. assert:triggersanexceptionconditionallyinthecode.
4. raise:manuallytriggersanexceptioninthe code.
5. with/as: implement context managers in older versions of Python such as - Python 2.6 & Python 3.0.

ThelastwasanoptionalextensiontoPython2.6&Python3.0.
WhyareExceptionsUsed?

Exceptions allow us to jump outof random illogical large chunks of codes in case of errors. Let us take a
scenario that you have given a function to do a specific task. If you go there and found those things
missing that are required to do that specifictask,whatwillyoudo?
Eitheryoustopworkingorthinkaboutasolution
- where to find those items to perform the task. The same thinghappens here in case of
Exceptions also. Exceptions allow programmers jump to an exception
handlerinasinglestep,abandoningallfunctioncalls.Youcanthinkexceptionsto an optimized quality go-to
statement, in which the program error that occurs at runtime gets easily managed by the exception
block. When the interpreter encounters an error, it lets the execution go to the exception part to solve
and continue the execution instead of stopping.
While dealing with exceptions, the exception handler creates a mark & executes some code.
Somewhere further within that program the exception is raised that solves the problem & makes
Python jump back to the marked location; by not
throwingaway/skippinganyactivefunctionsthatwerecalledafterthemarkerwas left.

RolesofanExceptionHandlerinPython
 Error handling: The exceptions get raised whenever Python detects an error in a program at runtime. As
a programmer, if you don't want the default behavior then code a 'try' statement to catch and recover
the program from anexception.Pythonwilljumptothe'try'handlerwhentheprogramdetects an error the
execution will be resumed.
 Event Notification: Exceptions are also used to signal suitable conditions & then passing result flags
around a program & text them explicitly.
 Terminate Execution: There may arise some problems or errors in programs
thatitneedsatermination.Sotry/finallyisusedthatguaranteesthatclosing- time operation will be
performed. The 'with' statement offers an alternative for objects that support it.
 Exotic flow of Control: Programmers can also use exceptions as a basis for implementing unusual
control flow. Since there is no 'go to' statement in Python so exceptions can help in this respect.
ASimpleProgramtoDemonstratePythonExceptionHandling

Example01:
(a,b)= (6,0)

try:#simpleuseoftry-exceptblockforhandlingerrors g
= a/b

Output:
ThisisaDIVIDEDBYZEROerror
Theaboveprogramcanalsobewrittenlikethis: Example 02:

(a,b)= (6,0)
try:
g=a/b
exceptZeroDivisionErrorass: k =
s
print (k)
#Outputwillbe:integerdivisionormoduloby zero
Output:

divisionbyzero
The'try-Except'ClausewithNoException
Thestructureofsuchtypeof'except'clausehavingnoexceptionisshownwithan example.

try:
#alloperationsaredonewithinthisblock.
. . .. ..

except:
#thisblockwillgetexecutedifanyexception encounters.
. . .. ..

else:
#thisblockwillgetexecutedifnoexceptionis found.
Alltheexceptionsgetcaughtwherethereistry/exceptthestatementofthistype. Good programmers use this
technique of exception to make the program fully executable.
'except'ClausewithMultipleExceptions

try:
#alloperationsaredonewithinthisblock.
. . .. ..

except(Exception1[,Exception2[,….ExceptionN]]]):
#thisblockwillgetexecutedifanyexceptionencountersfromtheabovelistsof exceptions.
. . .. ..

else:
#thisblockwillgetexecutedifnoexceptionis found.
. . .. ..
The'try-Finally'Clause

try:
#alloperationsaredonewithinthisblock.
. . .. ..

#ifanyexceptionencounters,thisblockmaygetskipped. finally:
. . .. ..

#thisblockwilldefinitelybeexecuted.
PHYTHON–OOP

The python is an Object-oriented programming Language. This means there exists a concept called
'class' that let's programmer structure the codes of software in a fashioned way. Because of the use of
classes and objects, the programming became easy to understand and code.
DefiningClassandObject
A class is a technique to group functions and data members and put them in a
containersothattheycanbeaccessedlaterbyusingdot(.)operator.Objectsare
thebasicruntimeentitiesofobject-orientedprogramming.Itdefinestheinstance
ofaclass.Objectsgettheirvariablesandfunctionsfromclassesandtheclasswe will be creating are the
templates made to create the object.

Object-OrientedTerminologies

o class: Classes are auser-defined data type that is used toencapsulate data
andassociatedfunctionstogether.Italsohelpsinbindingdatatogetherinto a single unit.
o DataMember:Avariableormemorylocationnamethatholdsvaluetodoes a specific task within a program.
o MemberFunction:Theyarethefunctions;usuallyablockofacodesnippet that is written to re-use it.
o Instancevariable:Avariablethatisdefinedinsideamethodofaclass.
o Function Overloading: This technique isused to assignmultiple tasks to a single function & the tasks are
performed based on the numberof argument or the type of argument the function has.
o Operator Overloading: It is the technique of assigning multiple function/tasks to a particular operator.
o Inheritance: It is the process of acquiring the properties of one class to another, i.e., one class can
acquire the properties of another.
o Instantiation:Itisthetechniqueofcreatinganinstanceofaclass.

ProgramforClassinPython Example:

classkarl:
varabl =
Anotherprogramtoexplainfunctionsinsideaclass:
'Hello'deffunction(sel Example:
f):
classkarl(object):
print("ThisisamessageHello")
def init (self,x,y):
self.x = x
self.y = y
defsample(self):
print("Thisisjustasamplecode")

In the above code, we created a class name karl using 'class' keyword. And two functionsareused
namelyinit()(forsettingtheinstancevariable)& sample(). Classes are used instead of modules because
programmers can take this class 'karl'& use it or modify it as many times as we want & each one won't
interferewitheachother.Importingamodulebringstheentireprogramintouse.
CreatingObjects(InstanceofAClass)

Let'sseeanexampletoshowhowtocreateanobject:Example:

classstudent:
def init (self,roll,name):
self.r = roll
self.n = name
print((self.n))

#...
Output:
stud1 = student(1, "Alex")
stud2=student(2,"Karlos")
Alex
print("Datasuccessfullystoredinvariables")
Karlo
s
Datasuccessfullystoredinvariables

AccessingObjectVariables

We can access the object's variable using dot (.)


operator. The syntax is:

myobject_name.variable_name
Example:

printobject.varabl

AccessingAttributes

Objectattributescanalsobeaccessedbyusingdotoperator. Example:

stud1.display()

stud2.display()
UseofPre-definedFunctions

Instead of using general statements to access attributes, programmers can use the following functions:
o getattr(obj,name[,default]):usedtoaccessobject'sattribute.
o hasattr(object,name):usedforcheckingwhethertheattributeexistsornot.
o setattr(obj,name,value):setorcreateanattribute,ifdoesn'texist.
o delattr(obj,name):usedtodeleteanattribute.

Built-inClassAttributes

All the Pythonbuilt-in class attributes can be accessed using dot(.) operator like other attributes.
Thebuilt-inclassattributesare:

o dict :Thisattributeisadictionarythat containsclass's-namespace.


o doc :Usedforclassdocumentationstring.
o name :usedasclass-name.
o module :usedtodefinemodulenamefortheclassinwhichitis defined. In interactive
mode it is main .
o bases :Anemptytuplecontainingthe base-class.
PHPTutorial

The PHP Hypertext Pre-processor (PHP) is a programming language that allows web developers to create
dynamic content that interacts with databases.

PHPisbasicallyusedfordevelopingwebbasedsoftwareapplications.

PHPIntroduction

PHPstartedoutasasmallopensourceprojectthatevolvedasmoreandmorepeoplefoundout how useful


it was. Rasmus Lerdorf unleashed the first version of PHP way back in 1994.

 PHPisarecursiveacronymfor"PHP:HypertextPreprocessor".
 PHP isaserversidescriptinglanguagethat isembeddedinHTML.It isusedtomanage dynamic content,
databases, session tracking, even build entire e-commerce sites.
 It is integrated with a number of popular databases, including MySQL, PostgreSQL, Oracle, Sybase,
Informix, and Microsoft SQL Server.
 PHP is pleasingly zippy in its execution, especially when compiled as an Apache module on the Unix side. The
MySQL server, once started, executes even very complex queries with huge result sets in record-setting
time.
 PHP supports a large number of major protocols such as POP3, IMAP, and LDAP. PHP4 added support for
Java and distributed object architectures (COM and CORBA), making n-tier development a possibility for the
first time.
 PHPisforgiving:PHPlanguagetriestobeasforgivingaspossible.
 PHPSyntaxisC-Like.

Commonusesof PHP:

 PHP performs system functions, i.e. from files on a system it can create, open, read,write, and close them.
 PHPcanhandleforms,i.e.gatherdatafromfiles,savedatatoafile,thruemailyoucan send data, return data to the
user.
 Youadd,delete,modifyelementswithinyourdatabasethruPHP.
 Accesscookiesvariablesandsetcookies.
 UsingPHP,youcanrestrictuserstoaccesssomepagesofyourwebsite.
 Itcanencrypt data.

CharacteristicsofPHP

FiveimportantcharacteristicsmakePHP'spracticalnaturepossible:

 Simplicity
 Efficiency
 Security
 Flexibility
 Familiarity

"HelloWorld"ScriptinPHP:

Toget afeel for PHP,first startwithsimple PHP scripts.Since "Hello,World!"is anessential example, first we will
create a friendly little "Hello, World!" script.
1|Page
Asmentionedearlier,PHPisembeddedinHTML.ThatmeansthatinamongstyournormalHTML (or
XHTML if you're cutting-edge) you'll have PHP statements like this:

2|Page
<html>

<head>

<title>HelloWorld</title>

<body>

Itwillproducefollowingresult:

Hello,World!
If you examine the HTML output of the above example, you'll notice that the PHP code is not present in the
file sent from the server to your Web browser. All of the PHP present in the Web page is processed and
stripped from the page; the onlything returned to the client from theWeb server is pure HTML output.

AllPHP code must be included inside one of the three special markup tags ate are recognised by the PHP
Parser.

<?phpPHPcodegoeshere?>

<? PHPcodegoeshere ?>

<scriptlanguage="php">PHPcodegoeshere</script>

Mostcommontagisthe<?php...?>andwewillalsousesametaginourtutorial.

From the next chapter we will start with PHP Environment Setup on your machine and then we willdig out
almost allconcepts related to PHP to make you comfortable with thePHP language.

PHPEnvironmentSetup
InordertodevelopandrunPHPWebpagesthreevitalcomponents needtobeinstalledonyour computer system.

 Web Server - PHP will work with virtually all Web Server software, including Microsoft's Internet
Information Server (IIS) but then most often used is freely availble Apache Server. Download Apache for free
here: http://httpd.apache.org/download.cgi
 Database - PHP will work with virtually all database software, including Oracle and Sybase but most
commonly used is freely available MySQL database. Download MySQL for free here:
http://www.mysql.com/downloads/index.html
 PHP Parser - In order to process PHP script instructions a parser must be installed to generate HTML output
that can be sent to the Web Browser. This tutorial will guide you how to install PHP parser on your
computer.

PHPParserInstallation:

Before you proceeditisimportant tomake sure thatyouhave properenvironment setup on your machine to
develop your web programs using PHP.

Typethefollowingaddressintoyourbrowser'saddressbox.

http://127.0.0.1/info.php

3|Page
If this displays a page showing your PHP installation related information then it means you have PHP and
Webserver installed properly. Otherwise you have to follow given procedure to install PHP on your
computer.

ApacheConfiguration:

IfyouareusingApacheasaWebServerthenthissectionwillguideyoutoeditApache Configuration Files.

PHP.INIFileConfiguration:

ThePHPconfigurationfile,php.ini,isthefinalandmostimmediatewaytoaffectPHP'sfunctionality.

WindowsIIS Configuration:

To configure IISon your Windows machine you can refer your IISReference Manual shippedalong with IIS.

PHPSyntaxOverview
This chapter willgive you an idea of very basic syntax of PHP and very important to make your PHP
foundation strong.

EscapingtoPHP:

ThePHP parsingengineneedsa waytodifferentiatePHP codefromotherelementsinthepage. The mechanism


for doing so is known as 'escaping to PHP.' There are four ways to do this:

CanonicalPHPtags:

ThemostuniversallyeffectivePHPtagstyleis:
<?php...?>
Ifyouusethisstyle,youcanbepositivethatyourtagswillalwaysbecorrectlyinterpreted.

Short-open (SGML-style)tags:
Shortorshort-opentagslooklikethis:
<?...?>
Shorttagsare,asonemightexpect,theshortestoptionYoumustdooneoftwothingsto enable PHP to recognize the
tags:

 Choosethe--enable-short-tagsconfigurationoptionwhenyou'rebuildingPHP.
 Set the short_open_tag setting in your php.ini file to on. This option must be disabled to parse XML with
PHP because the same syntax is used for XML tags.

ASP-styletags:
ASP-style tags mimic the tags used by Active Server Pages to delineate code blocks. ASP-style tags look like
this:

TouseASP-styletags,youwillneedtosettheconfigurationoptioninyourphp.inifile.
<%...%>

4|Page
HTMLscripttags:

HTMLscripttagslooklikethis:

CommentingPHPCode:
<scriptlanguage="PHP">...</script>

Acommentis the portion of a program that exists only for the human reader and stripped out before
displaying the programs result. There are two commenting formats in PHP:

Single-linecomments:Theyaregenerallyusedforshortexplanationsornotesrelevanttothe local code. Here are


the examples of single line comments.

<?
Multi-linesprinting:Herearetheexamplestoprintmultiplelinesinasingleprintstatement:
#Thisisacomment,and

<?
#Thisisthesecondlineofthecomment
Multi-lines comments: They are generally used to provide pseudocode algorithms and more detailed
explanations#FirstExample
when necessary. The multiline style of commenting is the same as in C. Here are the example
of multi linesprint
comments.
<<<END

This uses the "here document" syntax to output


<?
/*multiple
This is lines with with
a comment $variable interpolation.
multiline Note
Author : Mohammad Mohtashim Purpose:MultilineCommentsDemo
*/thattheheredocumentterminatormustappearona line
with just a semicolon no extra whitespace!
print"Anexamplewithmultilinecomments";

END;

?>
PHPiswhitespaceinsensitive:

Whitespace is the stuff you type that is typically invisible on the screen, including spaces, tabs, and carriage
returns (end-of-line characters).

PHPwhitespaceinsensitivemeansthatitalmostnevermattershowmanywhitespace characters you have in a


row.one whitespace character is the same as many such characters

5|Page
Forexample,eachofthefollowing PHPstatementsthatassignsthesumof2+2tothevariable
$fourisequivalent:

PHPiscasesensitive:
$four=2+2;//singlespaces

YeahitistruethatPHPisacasesensitivelanguage.Tryoutfollowingexample:
$four<tab>=<tab2<tab>+<tab>2;//spacesandtabs
<html> $four=

<body>

<?

$capital=67;

print("Variablecapitalis$capital<br>");

Thiswillproducefollowingresult:
Variablecapitalis67
Variable CaPiTaL is
Statementsareexpressionsterminatedbysemicolons:

A statement in PHP is any expression that is followed by a semicolon (;).Any sequence of valid PHP
statements that is enclosed by the PHP tags is a valid PHP program. Here is a typical
statementinPHP,whichinthiscaseassignsastringofcharacterstoavariablecalled
$greeting:

Expressionsarecombinationsoftokens:
$greeting="WelcometoPHP!";

The smallest building blocks of PHP are the indivisible tokens, such as numbers (3.14159), strings (.two.),
variables ($two), constants (TRUE), and the special words that make up the syntax of PHP itself like if, else,
while, for and so forth

Bracesmakeblocks:

Although statements cannot be combined like expressions, you can always put a sequence of statements
anywhere a statement can go by enclosing them in a set of curly braces.

Herebothstatementsareequivalent:

if(3==2+1)

print("Good-Ihaven'ttotallylostmymind.<br>");

if(3==2+1)

6|Page
RunningPHPScriptfromCommandPrompt:

YesyoucanrunyourPHPscriptonyourcommandprompt.Assumingyouhavefollowing content in test.php file

<?php
Nowrunthisscriptascommandpromptasfollows:
echo"HelloPHP!!!!!";
$php test.php

Itwillproducefollowingresult:
HelloPHP!!!!!

HopenowyouhavebasicknowledgeofPHPSyntax.

PHPVariableTypes
ThemainwaytostoreinformationinthemiddleofaPHPprogramisbyusingavariable. Here are the most
important things to know about variables in PHP.
 AllvariablesinPHParedenotedwithaleadingdollarsign($).
 Thevalueofavariableisthevalueofitsmostrecentassignment.
 Variables are assigned with the = operator, with the variable on the left-hand side and the expression to be
evaluated on the right.
 Variablescan,butdonotneed,tobedeclaredbeforeassignment.
 VariablesinPHPdonothaveintrinsictypes-avariabledoesnotknowinadvance whether it will be used to store a
number or a string of characters.
 Variablesusedbeforetheyareassignedhavedefaultvalues.
 PHPdoesagoodjobofautomaticallyconvertingtypesfromonetoanotherwhen necessary.
 PHPvariablesarePerl-like.

PHPhasatotalofeightdatatypeswhichweusetoconstructourvariables:

 Integers:arewholenumbers,withoutadecimalpoint,like4195.
 Doubles:arefloating-pointnumbers,like3.14159or49.1.
 Booleans:haveonlytwopossiblevalueseithertrueorfalse.
 NULL:isaspecialtypethatonlyhasonevalue:NULL.
 Strings:aresequencesofcharacters,like'PHPsupportsstringoperations.'
 Arrays:arenamedandindexedcollectionsofothervalues.
 Objects:areinstancesofprogrammer-definedclasses,whichcanpackageupboth other kinds of values and
functions that are specific to the class.
 Resources:arespecialvariablesthatholdreferencestoresourcesexternaltoPHP (such as database
connections).

The first five are simple types, and the next two (arrays and objects) are compound - the compound types
can package up other arbitrary values of arbitrary type, whereas the simple types cannot.

We will explain only simile data type in this chapters. Array and Objects will be explained separately.

7|Page
Integers:
They are whole numbers, without a decimal point, like 4195. They are the simplest type .they correspond to
simple whole numbers, both positive and negative. Integers can be assigned to variables, or they can be
used in expressions, like so:

$int_var=12345;
Integer can be in decimal (base 10), octal (base 8), and hexadecimal (base 16) format. Decimal format is the
default, octal integers are specified with a leading 0, and hexadecimals have a leading 0x.

For most common platforms, the largest integer is (2**31 . 1) (or 2,147,483,647), and the smallest (most
negative) integer is . (2**31 . 1) (or .2,147,483,647).

Doubles:
Theylike 3.14159or 49.1.Bydefault,doublesprintwiththeminimumnumberofdecimal places needed. For
example, the code:

$many=2.2888800;
Itproducesthefollowingbrowseroutput:
$many_2=2.2111200;
2.28888+2.21112=4.5
Boolean:
Theyhaveonlytwopossiblevalueseithertrueorfalse.PHPprovidesacoupleofconstants especially for use as
Booleans: TRUE and FALSE, which can be used like so:

if (TRUE)

InterpretingothertypesasBooleans:
print("Thiswillalwaysprint<br>");

Herearetherulesfordeterminethe"truth"ofanyvaluenotalreadyoftheBooleantype:
print("Thiswillneverprint<br>");

 Ifthevalueisanumber,itisfalseifexactlyequaltozeroandtrueotherwise.
 If the value is a string, it is false if the string is empty (has zero characters) or is the string "0", and is true
otherwise.
 ValuesoftypeNULLarealwaysfalse.
 If the value is an array, it is false if it contains no other values, and it is true otherwise. For an object,
containing a value means having a member variable that has been assigned a value.
 Valid resources are true (although some functions thatreturn resources when they are successful will
return FALSE when unsuccessful).
 Don'tusedoubleasBooleans.

Each of the following variables has the truth value embedded in its name when it is used in a Boolean
context.

8|Page
$true_num=3+0.14159;

$true_str="Triedandtrue"

$true_array[49]="Anarrayelement";

$false_array=array();
NULL:
NULL isa specialtypethatonly has onevalue: NULL. Togive a variablethe NULL value, simply assign it like this:

The special constant NULL is capitalized by convention, but actually it is case insensitive; you could just as
$my_var=NULL;
well have typed:
$my_var=null;
AvariablethathasbeenassignedNULLhasthefollowingproperties:
 ItevaluatestoFALSEinaBooleancontext.
 ItreturnsFALSEwhentestedwithIsSet()function.

Strings:
Theyaresequencesofcharacters,like"PHPsupportsstringoperations".Followingarevalid examples of string

$string_1="Thisisastringindoublequotes";
Singlyquotedstringsaretreatedalmostliterally,whereasdoublyquotedstringsreplace variables with their values as
well as specially interpreting certain character sequences.
$string_2="Thisisasomewhatlonger,singlyquotedstring";

<?
Thiswillproducefollowingresult:
$variable="name";
My$variablewillnotprint!\n My
name will print
$literally='My$variablewillnotprint!\\n';
print($literally);
Therearenoartificiallimitsonstringlength-withintheboundsofavailablememory,youought to be able to make
arbitrarily long strings.

Stringsthataredelimited by doublequotes(asin"this")arepreprocessed in boththe following two ways by


PHP:

 Certaincharactersequencesbeginningwithbackslash(\)arereplacedwithspecial characters
 Variablenames(startingwith$)arereplacedwithstringrepresentationsoftheir values.

9|Page
Theescape-sequencereplacementsare:

 \nisreplacedbythenewlinecharacter
 \risreplacedbythecarriage-returncharacter
 \tisreplacedbythetabcharacter
 \$isreplacedbythedollarsignitself ($)
 \"isreplacedbyasingledouble-quote(")
 \\isreplacedbyasinglebackslash (\)

HereDocument:

Youcanassignmultiplelinestoasinglestringvariableusingheredocument:

<?php
$channel=<<<_XML_
<channel>
<title>What'sForDinner<title>

<description>Choosewhattoeattonight.</description>
</channel>
_XML_;

echo<<<END
This uses the "here document" syntax to output multiple lines with variable interpolation. Not
<br/>

END;

print$channel;
?>

Thiswillproducefollowingresult:
VariableScope:
This uses the "here document" syntax to output
multiple lines with variable interpolation. Note
Scope can bethattheheredocumentterminatormustappearona
defined asthe rangeof availability avariable hastothe programinwhichitis declared. PHP variables
line
can be one ofwith
four just
scopeatypes:
semicolon. no extra whitespace!

 Localvariables
<channel>
 Functionparameters
 Globalvariables
 Staticvariables

10|Page
VariableNaming:

Rulesfornamingavariableis:

 Variablenamesmustbeginwithaletterorunderscorecharacter.
 Avariablenamecanconsistofnumbers,letters,underscoresbutyoucannotuse characters like + , - , % , ( , ) . & ,
etc

Thereisnosizelimitforvariables.

PHPConstants
A constant is a name or an identifier for a simple value. A constant value cannot change during the
execution of the script. By default a constant is case-sensitive. By convention, constant identifiers
are always uppercase. A constant name starts with a letter or underscore, followed by any number
of letters, numbers, or underscores. If you have defined a constant, it can never be changed or
undefined.

To define a constant you have to use define() function and to retrieve the value of a constant, you
have to simply specifying its name. Unlike with variables, you do not need to have
aconstantwitha$.Youcan alsousethefunctionconstant()toreadaconstant'svalueifyou wish to obtain
the constant's name dynamically.

constant()function:

Asindicatedbythename,thisfunctionwillreturnthevalueoftheconstant.

This is useful when you want to retrieve value of a constant, but you do not know its name, i.e.It is
stored in a variable or returned by a function.

constant()example:

<?php
Onlyscalardata(boolean,integer,floatandstring)canbecontainedinconstants.
define("MINSIZE",50)

Differencesbetweenconstantsandvariablesare:
;

 There is no need to write a dollar sign ($) before a constant, where as in Variable one has to write a dollar
echoMINSIZE;
sign.
 Constantscannotbedefinedbysimpleassignment, theymayonlybedefinedusing the define() function.
 Constants may be defined and accessed anywhere without regard to variable scoping rules.
 OncetheConstantshavebeenset,maynotberedefinedorundefined.

11|Page
Validandinvalidconstantnames:

// Valid constant names


define("ONE", "first
thing"); define("TWO2",
"secondthing")
; define("THREE_3", "third
thing")
PHPMagicconstants:

PHPprovidesalargenumberofpredefinedconstantstoanyscriptwhichitruns.

There are five magical constants that change depending on where they are used. For example,
thevalueofLINEdependsonthelinethatit'susedoninyourscript.Thesespecial constants are case-
insensitive and are as follows:

Afew"magical"PHPconstantsategivenbelow:

Name Description

LINE Thecurrentlinenumberofthefile.

FILE Thefullpathandfilenameofthefile.Ifusedinsideaninclude,thenameof the


included file is returned. Since PHP 4.0.2, FILE always contains
anabsolutepathwhereasinolderversionsitcontainedrelativepathunder
some circumstances.

FUNCTION Thefunctionname.(AddedinPHP4.3.0)AsofPHP5thisconstantreturns
thefunctionnameasitwasdeclared(case-sensitive).InPHP4itsvalueis
alwayslowercased.

CLASS Theclassname.(AddedinPHP4.3.0)AsofPHP5thisconstantreturnsthe
classnameas it was declared(case-sensitive). In PHP4its valueisalways
lowercased.

METHOD Theclassmethodname.(AddedinPHP5.0.0)Themethodnameis returned


as it was declared (case-sensitive).

PHPOperatorTypes
What is Operator? Simple answer can be given using expression 4 + 5 is equal to 9. Here 4and 5 are
called operands and + is called operator. PHP language supports following type of operators.

 ArithmeticOperators
 ComparisionOperators
 Logical(orRelational)Operators
 AssignmentOperators
 Conditional (or ternary) Operators
Letshavealookonalloperatorsonebyone.

12|Page
ArithmaticOperators:

TherearefollowingarithmaticoperatorssupportedbyPHPlanguage: Assume
variable A holds 10 and variable B holds 20 then:
Operator Description Example

+ Addstwo operands A+Bwillgive30

- Subtractssecondoperandfromthefirst A-Bwillgive-10

* Multiplybothoperands A*Bwillgive200

/ Dividenumeratorbydenumerator B/Awillgive2

% ModulusOperatorandremainderof B%Awillgive0
after an integer division

++ Incrementoperator,increasesinteger A++willgive11
value by one

-- Decrementoperator,decreasesinteger A--willgive9
value by one

ComparisonOperators:

TherearefollowingcomparisonoperatorssupportedbyPHPlanguage Assume
variable A holds 10 and variable B holds 20 then:
Operator Description Example

== Checksifthevalueoftwooperandsare (A==B)isnottrue.
equalornot,ifyesthencondition
becomes true.
!= Checksifthevalueoftwooperandsare (A !=B)istrue.
equal or not, if values are not equal
then condition becomes true.

> Checks if the value of left operand is (A>B)isnottrue.


greaterthanthevalueofrightoperand, if
yes then condition becomes true.

< Checks if the value of left operand is (A<B)istrue.


lessthanthevalueofrightoperand,if yes
then condition becomes true.

13|Page
>= Checksifthevalueofleftoperandis (A>=B)isnottrue.
greaterthanorequaltothevalueof right
operand, if yes then condition
becomes true.

<= Checks if the value of left operand is (A<=B)istrue.


less than or equalto thevalue of right
operand,ifyesthenconditionbecomes
true.

LogicalOperators:

TherearefollowinglogicaloperatorssupportedbyPHPlanguage Assume variable A


holds 10 and variable B holds 20 then:
Operator Description Example

and CalledLogicalANDoperator.Ifboththe (AandB)istrue.


operands are true then then condition
becomes true.
or CalledLogicalOROperator.Ifanyof the (A orB)istrue.
two operandsare non zerothen then
condition becomes true.

&& CalledLogicalANDoperator.Ifboththe (A&&B)is true.


operands are non zero then then
condition becomes true.

|| CalledLogicalOROperator.Ifanyof the (A||B)istrue.


two operandsare non zerothen then
condition becomes true.

! Called Logical NOT Operator. Use to !(A&& B)isfalse.


reverses the logical state of its
operand. If a condition is true then
LogicalNOToperatorwillmakefalse.

14|Page
AssignmentOperators:

TherearefollowingassignmentoperatorssupportedbyPHPlanguage:

Operator Description Example

= Simpleassignmentoperator, C=A+BwillassignevalueofA+BintoC
Assigns values from right
side operands to left side
operand
+= Add AND assignment operator, C+=AisequivalenttoC=C+A
It addsright operandto theleft
operandandassigntheresultto
left operand

-= Subtract AND assignment C-=AisequivalenttoC=C-A


operator, It subtracts right
operandfromtheleftoperand
and assign the result to left
operand
*= Multiply AND assignment C*=AisequivalenttoC=C*A
operator, It multiplies right
operandwiththeleftoperandand
toleftoperand

/= DivideANDassignmentoperator, C/=AisequivalenttoC=C/A
It divides left operand with the
right operand and assign the
result to left operand

%= Modulus AND assignment C%=AisequivalenttoC=C%A


operator,Ittakesmodulususing
two operands and assign the
result to left operand

ConditionalOperator

There is one more operator called conditional operator. This first evaluates an expression for a true or false
value and then execute one of the two given statements depending upon the result of the evaluation. The
conditional operator has this syntax:

Operator Description Example

?: ConditionalExpression IfConditionistrue?ThenvalueX:
Otherwise value Y

15|Page
OperatorsCategories:

Alltheoperatorswehavediscussedabovecanbecategorisedintofollowingcategories:

 Unaryprefixoperators,whichprecedeasingleoperand.
 Binaryoperators,whichtaketwooperandsandperformavarietyofarithmeticand logical operations.
 Theconditionaloperator(aternaryoperator),whichtakesthreeoperandsandevaluates
eitherthesecondorthirdexpression,dependingontheevaluationofthefirstexpression.
 Assignmentoperators,whichassignavaluetoavariable.

PrecedenceofPHPOperators:

Operator precedence determines the grouping of terms in an expression. This affects how an
expressionisevaluated.Certainoperatorshave higherprecedencethanothers;forexample, the multiplication
operator has higher precedence than the addition operator:

For example x = 7 + 3 * 2; Here x is assigned 13, not 20 because operator * has higher precedenace than +
so it first get multiplied with 3*2 and then adds into 7.

Here operators with the highest precedenceappear at the top of the table, those with the lowest appear at
the bottom. Within an expression, higher precedence operators will be evaluated first.

Category Operator Associativity

Unary !++-- Righttoleft

Multiplicative */% Leftto right

Additive +- Leftto right

Relational <<=>>= Leftto right

Equality ==!= Leftto right

LogicalAND && Leftto right

LogicalOR || Leftto right

Conditional ?: Righttoleft

Assignment =+=-=*=/=

PHPDecisionMaking
Theif,elseif...elseandswitchstatementsareusedtotakedecisionbasedonthedifferent condition.

Youcanuseconditionalstatementsinyourcodetomakeyourdecisions.PHPsupportsfollowing threedecision making


statements:

16|Page
 if...elsestatement-usethisstatementifyouwanttoexecuteasetofcodewhena condition is true and another
if the condition is not true
 elseifstatement-isusedwiththeif...elsestatementtoexecuteasetofcode if one of several condition
are true
 switch statement - is used if you want to select one of many blocks of code to be
executed,usetheSwitchstatement.Theswitchstatementisusedtoavoidlongblocks of if..elseif..else code.

TheIf...ElseStatement

If you want to execute some code if a condition is true and another code if a condition is false, use the if
.........................else statement.

Syntax
if (condition)
Example
codetobeexecutedifconditionistrue;
Thefollowingexamplewilloutput"Haveaniceweekend!" ifthecurrentdayisFriday,otherwise it will output
"Have a nice day!":

<html>
Ifmorethanonelineshouldbeexecutedifaconditionistrue/false,thelinesshouldbe enclosed within curly braces:
<body>
TheElseIfStatement
<html>
<?php

Ifyouwanttoexecutesomecodeifoneofseveralconditionsaretrueusetheelseifstatement
$d=date("D");
<body>
if ($d=="Fri")
<?php
echo"Haveaniceweekend!";
$d=date("D");

if ($d=="Fri")

17|Page
Syntax
if (condition)
Example
codetobeexecutedifconditionistrue;
Thefollowingexamplewilloutput"Haveaniceweekend!"ifthecurrentdayisFriday,and"Have a nice Sunday!" if
elseif(condition)
the current day is Sunday. Otherwise it willoutput "Have a nice day!":

TheSwitchStatement
<html>

Ifyouwanttoselectoneofmanyblocksofcodetobeexecuted,usetheSwitchstatement.
<body> The switch
statement is <?php
used to avoid long blocks of if..elseif..else code.
Syntax
$d=date("D");
switch(expression)
Example if ($d=="Fri")
{
The switch statement works in an unusual way. First it evaluates given expression then seeks a lable
echo"Haveaniceweekend!";
caselabel1:
elseif ($d=="Sun")
tomatch theresultingvalue. Ifa matchingvalue isfoundthenthe code associatedwith the matching label will be
executed or if none of the lables match then statement will execute any specified default code.
codetobeexecutedifexpression=label1;

break;
caselabel2
:

codetobeexecutedifexpression=label2;

18|Page
<html>
<body>
<?php
$d=date("D"); switch ($d)
{
case"Mon":
echo"TodayisMonday"; break;
case"Tue":
echo"TodayisTuesday"; break;
case"Wed":
echo"TodayisWednesday"; break;
case"Thu":
echo"TodayisThursday"; break;
case"Fri":
echo"TodayisFriday"; break;
case"Sat":
echo"TodayisSaturday"; break;
case"Sun":
echo"TodayisSunday"; break;
default:
echo"Wonderwhichdayisthis?";
}
?>
</body>

</html>
PHPLoopTypes
LoopsinPHPareusedtoexecutethesameblockofcodeaspecifiednumberoftimes.PHP supports following four loop
types.

 for-loopsthroughablockofcodeaspecifiednumberoftimes.
 while-loopsthroughablockofcodeifandaslongasaspecifiedconditionistrue.
 do...while-loopsthroughablockofcodeonce,andthenrepeatstheloopaslongasa special condition is trur.
 foreach-loopsthroughablockofcodeforeachelementinanarray.

Wewilldiscussaboutcontinueandbreakkeywordsusedtocontroltheloopsexecution.

Theforloopstatement
The for statement is used when you knowhow many times you want to executea statement or a block of
statements.

Syntax

for(initialization;condition;increment)
The initializer is used to set the start value for the counter of the number of loop iterations. A variable may
{
be declared here for this purpose and it is traditional to name it $i.

19|Page
Example

Thefollowingexamplemakesfiveiterationsandchangestheassignedvalueoftwovariableson each pass of the


loop:

<html>
Thiswillproducefollowingresult:
<body>

Attheendoftheloopa=50and b=25
<?php
Thewhileloopstatement
Thewhilestatementwillexecuteablockofcodeifandaslongasatestexpressionistrue.
$a=0;

If the test expression


$b=0; is true then the code block will be executed. After the code has executed the test
expression will again be evaluated and the loop will continue until the test expression is found to be false.
for($i=0;$i<5;$i++)

Syntax {

Example while(condition)
Thisexampledecrementsavariablevalueoneachiterationoftheloopandthecounter
{
increments until it reaches 10
when the evaluation is false and the loop ends.

<html>

<body>

<?php

$i=0;

$num=50;

while($i<10)

20|Page
Thiswillproducefollowingresult:

Loopstoppedati=1andnum= 40
Thedo...whileloopstatement
The do...while statement will execute a block of code at least once - it then will repeat the loop as long as a
condition is true.

Syntax

Example do

{
Thefollowingexamplewillincrementthevalueofiatleastonce,anditwillcontinue incrementing the variable i as long
as it has a value of less than 10:

<html>
Thiswillproducefollowingresult:
<body>

Loopstoppedati=10
<?php
Theforeachloopstatement
The foreach $i=0;
statement is used to loop through arrays. For each pass the value of the current array element
is assigned to $value and the array pointer is moved by one and in the next pass next element will be
processed. $num=0;
do
Syntax
{

Example foreach(arrayasvalue)

{
Tryoutfollowingexampletolistoutthevaluesofanarray.
codetobe executed;

21|Page
<html>

<body>

<?php

$array=array(1,2,3,4,5);
foreach( $array as $value )

Thiswillproducefollowingresult:

Valueis1
Thebreakstatement
ThePHPbreakkeywordisusedtoterminatetheexecutionofaloopprematurely.
Valueis2

Valueis3is situated inside the statement block. If gives you full control and whenever you want
The break statement
to exit from the loop you can come out. After coming out of a loopimmediate statement to the loop will be
executed.

Example

Inthefollowingexampleconditiontestbecomestruewhenthecountervaluereaches3and loop terminates.

<html>
Thiswillproducefollowingresult:
<body>

Loopstoppedati=3
Thecontinuestatement
<?php
ThePHP continue keywordisusedtohaltthecurrentiterationofaloopbutitdoesnot terminate the loop.
$i=0;

while($i<10)

22|Page
Just like the break statement the continue statement is situated inside the statement block containing the
code that the loop executes, preceded by a conditional test. For the pass encountering continue statement,
rest of the loop code is skipped and next pass starts.

Example

In the following example loop prints the value of array but for which condition becomes true it just skip the
code and next value is printed.

<html>
<body>
<?php
$array=array(1,2,3,4,5); foreach( $array as $value )
{
if( $value == 3 )continue; echo"Valueis$value<br/>";

}
?>
</body>
</html>

Thiswillproducefollowingresult

Valueis1
PHPArrays
An array is aValueis2
data structure that stores one or more similar type of values in a single value. For example if
you want to store 100 numbers then instead of defining 100 variables its easy to define an array of 100
length.

There are three different kind of arrays and each array value is accessed using an ID c which is called array
index.

 Numericarray-Anarraywithanumericindex.Valuesarestoredandaccessedin linear fashion


 Associativearray-Anarraywithstringsasindex.Thisstoreselementvaluesin association with key values
rather than in a strict linear index order.
 Multidimensionalarray-Anarraycontainingoneormorearraysandvaluesare accessed using multiple
indices

NumericArray

Thesearrays can store numbers, strings and any object but their index will be prepresented by numbers. By
default array index starts from zero.

Example

Followingistheexampleshowinghowtocreateandaccessnumericarrays.

23|Page
Herewehaveusedarray()functiontocreatearray.Thisfunctionisexplainedinfunction reference.

<html>
<body>
<?php
/*Firstmethodtocreatearray.*/
$numbers=array(1,2,3,4,5); foreach( $numbers as $value )
{
echo"Valueis$value<br/>";
}
/*Secondmethodtocreatearray.*/
$numbers[0]="one";
$numbers[1]="two";

$numbers[2]="three";
$numbers[3]="four";
$numbers[4]="five";

foreach($numbersas$value)
{
echo"Valueis$value<br/>";
}
?>
</body>
</html>

Thiswillproducefollowingresult:

AssociativeArrays
Valueis1

The associative arrays are very similar to numeric arrays in term of functionality but they are different in
Valueis2
terms of their index. Associative array will have their index as string so that you can establish a strong
Valueis3
association between key and values.
Valueis4
To store the salaries of employeesin an array, a numericallyindexed array would not be the best choice.
Instead, we could
Value use
is the
5 employees names as the keys in our associative array, and the value would be
their respective salary.
Value is one

NOTE: Don't keep associative array inside double quote while printing otheriwse it would not return any
value.

Example

24|Page
<html>
<body>
<?php
/*Firstmethodtoassociatecreatearray.*/
$salaries=array(
"mohammad"=>2000,
"qadir"=>1000,
"zara"=>500
);

echo"Salaryofmohammadis".$salaries['mohammad']."<br/>"; echo "Salary of qadir is ".$salaries['qadir']


echo"Salaryofzarais".$salaries['zara']."<br/>";

/*Secondmethodtocreatearray.*/
$salaries['mohammad']="high";
$salaries['qadir']="medium";
$salaries['zara']="low";
echo"Salaryofmohammadis".$salaries['mohammad']."<br/>"; echo "Salary of qadir is ".$salaries['qadir']

echo"Salaryofzarais".$salaries['zara']."<br/>";
?>
</body>
</html>

Thiswillproducefollowingresult:

MultidimensionalArrays
Salaryofmohammadis2000
Salary of qadir is 1000
A multi-dimensional array
Salary of eachiselement
zara 500 in the main array can also be an array. And each element in the
sub-array can be an array, and so
Salaryofmohammadishigh on. Values in the multi-dimensional array are accessed using multiple
index. Salary of qadir is medium
Salary of zara is low
Example

In this example we create a two dimensional array to store marks of three students in three subjects:

Thisexampleisanassociativearray,youcancreatenumericarrayinthesamefashion.

25|Page
<html>

<body>

<?php

$marks=array(

"mohammad"=>array
(

"physics"=>35,

"maths"=>30,

"chemistry"=>39

),

"qadir"=>array
(

"physics"=>30,

"maths"=>32,

"chemistry"=>29

),

"zara"=>array
Thiswillproducefollowingresult:

Marksformohammadinphysics:35
PHPStrings Marks for qadir in maths : 32
Theyaresequencesofcharacters,like"PHPsupportsstringoperations".
Marks for zara in chemistry : 39 Following are valid
examples of string

$string_1="Thisisastringindoublequotes";
Singlyquotedstringsaretreatedalmostliterally,whereasdoublyquotedstringsreplace variables with their values as
well as specially interpreting certain character sequences.
$string_2="Thisisasomewhatlonger,singlyquotedstring";

<?

$variable="name";

$literally='My$variablewillnotprint!\\n';
print($literally);

26|Page
Thiswillproducefollowingresult:

My$variablewillnotprint!\n My
Therearenoartificiallimitsonstringlength-withintheboundsofavailablememory,youought
name will print to be able to make
arbitrarily long strings.

Stringsthataredelimited by doublequotes(asin"this")arepreprocessed in boththe following two ways by


PHP:

 Certaincharactersequencesbeginningwithbackslash(\)arereplacedwithspecial characters
 Variablenames(startingwith$)arereplacedwithstringrepresentationsoftheir values.

Theescape-sequencereplacementsare:

 \nisreplacedbythenewlinecharacter
 \risreplacedbythecarriage-returncharacter
 \tisreplacedbythetabcharacter
 \$isreplacedbythedollarsignitself ($)
 \"isreplacedbyasingledouble-quote(")
 \\isreplacedbyasinglebackslash (\)

StringConcatenationOperator

Toconcatenatetwostringvariablestogether,usethedot(.)operator:

<?php
Thiswillproducefollowingresult:
$string1="HelloWorld";

HelloWorld1234
$string2="1234";
Ifwelookatthecodeaboveyouseethatweusedtheconcatenationoperatortwotimes.Thisis because we had to insert
a third string.

Between thetwostring variables weadded a string with a single character, an empty space, to separate the two
variables.

Usingthestrlen()function

Thestrlen()functionisusedtofindthelengthofastring. Let's find the length


of our string "Hello world!":

<?php

echostrlen("Helloworld!");

27|Page
Thiswillproducefollowingresult:
12
The length of a string is often used in loops or other functions, when it is important to knowwhen the string
ends. (i.e. in a loop, we would want to stop the loop after the last character in the string)

Usingthestrpos()function

Thestrpos()functionisusedtosearchforastringorcharacterwithinastring.

If a match is found in the string, this function will return the position of the first match. If no match is found,
it will return FALSE.

Let'sseeifwecanfindthestring"world"inourstring:

Thiswillproducefollowingresult:
<?php

echostrpos("Helloworld!","world");
6
As you see the positionof the string "world"in our string is position6.The reason that it is 6, and not 7, is
that the first position in the string is 0, and not 1.

PHPFileInclusion
You can include the content of a PHP file into another PHP file before the server executes it. Thereare two
PHP functionswhich can be used to included one PHP file into another PHP file.

 Theinclude()Function
 Therequire()Function

ThisisastrongpointofPHPwhichhelpsincreatingfunctions,headers,footers,or elements that can be reused on


multiple pages. This will help developers to make it easy to change the layout of complete website with
minimal effort. If there is any change required then instead of changing thousand of files just change
included file.

Theinclude()Function

The include() function takes all the text in a specified file and copies it into the file that uses the include
function.Ifthere is anyprobleminloading afilethenthe include() functiongenerates a warning but the script
will continue execution.

Assume you want to create a common menu for your website. Then create a file menu.php with the
following content.

<ahref="http://www.tutorialspoint.com/index.htm">Home</a>-
Now create as many pages as you like and include this file to create header. For example now your test.php
file can have <ahref="http://www.tutorialspoint.com/ebxml">ebXML</a>-
following content.

28|Page
<html>

<body>

<?phpinclude("menu.php");?>

Thiswillproducefollowingresult

Therequire()Function
Home-ebXML-AJAX-PERL

Therequire()functiontakesallthetext inaspecifiedfileandcopiesitintothefilethatusesthe
include function.Ifthere is anyprobleminloading afilethenthe require() functiongenerates a fatal error and
halt the excution of the script.

So there is no difference in require() and include() except they handle error conditions. It is recommended
to use the require() function instead of include(), because scripts should not continue executing if files are
missing or misnamed.

You can try using above example with require() function and it will generate same result. But if you willtry
following two examples where file does not exist then you will get different results.

<html>
Thiswillproducefollowingresult
<body>

ThisisanexampletoshowhowtoincludewrongPHPfile!
<?phpinclude("xxmenu.php");?>
Nowletstrysameexamplewithrequire()function.

<html>
Thistimefileexecutionhaltsandnothingisdisplayed.
<body>
NOTE:Youmaygetplainwarningmessagesorfatalerrormessagesornothingatall.This depends on your PHP Server
<?phprequire("xxmenu.php");?>
configuration.

29|Page
PHPFiles&I/O
Thischapterwillexplainfollowingfunctionsrelatedtofiles:

 Openinga file
 Readinga file
 Writingafile
 Closinga file

OpeningandClosingFiles

The PHPfopen()function is used to open a file. It requires two arguments stating first the file name and
then mode in which to operate.

Filesmodescanbespecifiedasoneofthesixoptionsinthistable.

Mode Purpose

r Opensthefileforreadingonly.
Placesthefilepointeratthebeginningofthefile.

r+ Opensthefileforreadingandwriting.
Placesthefilepointeratthebeginningofthefile.

w Opensthefileforwritingonly.
Places the file pointer at the beginning of the file.
andtruncatesthefiletozerolength.Iffilesdoesnot
exist then it attemts to create a file.

w+ Opens the file for reading and writing only.


Placesthefilepointeratthebeginningofthefile.
andtruncatesthefiletozerolength.Iffilesdoesnot
exist then it attemts to create a file.

a Opensthefileforwritingonly.
Placesthefilepointerattheendofthefile.
Iffilesdoesnotexistthenitattemtstocreateafile.

a+ Opensthefileforreadingandwritingonly.
Placesthefilepointerattheendofthefile.
Iffilesdoesnotexistthenitattemtstocreateafile.

If an attempt to open a file fails then fopen returns a value of false otherwise it returns a file pointer which is
used for further reading or writing to that file.

After making a changes to the opened file it is important to close it with the fclose() function. Thefclose()
function requires a file pointer as its argument and then returns true when the closure succeeds or false if it
fails.

Readingafile
Once a file is opened usingfopen() function it can be read with a function calledfread(). This function
requires two arguments. These must be the file pointer and the length of the file expressed in bytes.

30|Page
The files's length can be found using the filesize() function which takes the file name as its argument and
returns the size of the file expressed in bytes.

Soherearethestepsrequiredtoreadafilewith PHP.

 Openafileusingfopen()function.
 Getthefile'slengthusingfilesize()function.
 Readthefile'scontentusingfread()function.
 Closethefilewithfclose()function.

The following example assigns the content of a text file to a variable then displays thosecontents on the web
page.

<html>

<head>
<title>ReadingafileusingPHP</title>
</head>
<body>

<?php
$filename="/home/user/guest/tmp.txt";
$file=fopen($filename,"r"); if( $file == false )
{
echo("Errorinopeningfile"); exit();
}
$filesize=filesize($filename);
$filetext=fread($file,$filesize); fclose( $file );
echo("Filesize:$filesizebytes"); echo ( "<pre>$text</pre>" );
?>

</body>
</html>

Writingafile

A new file can be written or text can be appended to an existing file using the PHP fwrite()function. This
function requires two arguments specifying afile pointerand thestring of data that is to be written.
Optionally a third intger argument can be included to specifythe length of the data to write. If the third
argument is included, writing would will stop after the specified length has been reached.

The following example creates a new text file then writes a short text heading insite it. After
closingthisfileitsexistenceisconfirmedusing file_exist() functionwhichtakesfilenameas an argument

31|Page
<?php
$filename="/home/user/guest/newfile.txt";
$file=fopen($filename,"w"); if( $file == false )
{
echo("Errorinopeningnewfile"); exit();
}
fwrite($file,"Thisisasimpletest\n"); fclose( $file );
?>

<html>
<head>
<title>WritingafileusingPHP</title>
</head>
<body>
<?php
if(file_exist($filename))
{
$filesize=filesize($filename);
$msg="Filecreatedwithname$filename";
$msg.="containing$filesizebytes"; echo ($msg );
}

else
{
echo("File$filenamedoesnotexit");
}
?>
</body>
</html>

PHPFunctions
PHP functions are similar to other programming languages. A function is a piece of code whichtakes one
more input in the form of parameter and does some processing and returns a value.

You already have seen many functions like fopen() and fread() etc. They are built-in functions but PHP gives
you option to create your own functions as well.

Therearetwopartswhichshouldbecleartoyou:

 CreatingaPHPFunction
 CallingaPHPFunction

In fact you hardly need to create your own PHP function because there are already more than 1000 of built-
in library functions created for different area and you just need to call them according to your requirement.

CreatingPHPFunction:

Its very easy to create yourown PHP function. Suppose you want to create aPHP function which will simply
write a simple message on your browser when you will call it. Following example creates a function called
writeMessage() and then calls it just after creating it.

Note that while creating a function its name should start with keyword function and all the PHP code should
be put inside { and } braces as shown in the following example below:

32|Page
<html>

<head>

<title>WritingPHPFunction</title>

</head>

<body>

<?php

/*DefiningaPHPFunction*/

functionwriteMessage()

Thiswilldisplayfollowingresult:
PHPFunctionswithParameters:
Youarereallyaniceperson,Haveanicetime!

PHP gives you option to pass your parameters inside a function. You can pass as many as parameters your
like. These parameters work like variables inside your function. Following example takes two integer
parameters and add them together and then print them.

<html>
Thiswilldisplayfollowingresult:
<head>
PassingArgumentsbyReference:
Sumofthetwonumbersis:30
<title>WritingPHPFunctionwithParameters</title>
It is possible</head>
to pass arguments to functions by reference. This means that a reference to the variable is
manipulated by the function rather than a copy of thevariable's value.
<body>
Any changes made to an argument in these cases will change the value of the original variable. You can pass
an argument<?php
by reference by adding an ampersand to the variable name in either the function call or the
function definition.
functionaddFunction($num1,$num2)

Followingexampledepictsboththecases.
{

33|Page
<html>
<head>
<title>PassingArgumentbyReference</title>
</head>
<body>
<?php
functionaddFive($num)
{
$num+= 5;
}
functionaddSix(&$num)
{
$num+= 6;
}
$orignum = 10; addFive(&$orignum);
echo"OriginalValueis$orignum<br/>"; addSix( $orignum );

echo"OriginalValueis$orignum<br/>";
?>
</body>
</html>

Thiswilldisplayfollowingresult:

PHPFunctionsreturningvalue:
OriginalValueis15
OriginalValueis21
A function can return a valueusing thereturnstatement in conjunction with a value or object. return stops
the execution of the function and sends thevalue back to the calling code.

Youcanreturnmorethanonevaluefromafunctionusingreturnarray(1,2,3,4).

Following example takes two integer parameters and add them together and then returns their
sumtothecallingprogram.Notethatreturnkeywordisusedtoreturnavaluefromafunction.

<html>
Thiswilldisplayfollowingresult:
<head>

Returnedvaluefromthefunction:30
<title>WritingPHPFunctionwhichreturnsvalue</title>

</head>

<body>

<?php

functionaddFunction($num1,$num2)

34|Page
SettingDefaultValuesforFunctionParameters:

Youcansetaparametertohaveadefaultvalueifthefunction'scallerdoesn'tpassit. Following function prints


NULL in case use does not pass any value to this function.

<html>
<head>
<title>WritingPHPFunctionwhichreturnsvalue</title>
</head>
<body>

<?php
functionprintMe($param=NULL)
{
print$param;
}
printMe("Thisistest"); printMe();
?>

</body>
</html>

Thiswillproducefollowingresult:

DynamicFunctionCalls:
Thisis test

Itispossibletoassignfunctionnamesasstringstovariablesandthentreatthesevariables exactly as you would the


function name itself. Following example depicts this behaviour.

<html>
Thiswilldisplayfollowingresult:
<head>

Hello
<title>DynamicFunctionCalls</title>

</head>

<body>

<?php

functionsayHello()

35|Page
Web Servers

Chapter2.SettingupaWebServer
TableofContents
WampserverandApacheHTTPonWindows.............................................................................................................1
Requirements 1
InstallingWampserver 2
SettingupServerPasswords 3
TestingApplications 5
ApacheTomcatonWindows....................................................................................................................................6
Requirements 6
TomcatSetup 7
TestingApplications 10
LampserverandApacheHTTPonUbuntu15.04.......................................................................................................10
Requirements 10
InstallingApache,PHPandMySQL..............................................................................................................................11
TestingApplications 13
ApacheTomcatonUbuntu15.04............................................................................................................................13
TestingApplications 14

Objectives
Attheendofthisunityouwillbeableto:

 installandsetupWampserverandApacheserveronWindows;
 installandsetupTomcatServeronWindows;
 installandsetupLampserverandApacheserveronUbuntu15.04;and
 installandsetupTomcatonUbuntu15.04.

WampserverandApacheHTTPon Windows
In this section, you will learn how to set up a Web Server on a Windows PC. The steps in this section
will illustrate how to use Apache HTTP. The next section will illustrate the setup for Apache Tomcat.
Apache is a popular Web Server that allows users to easily set up their own Web Servers. It has the
advantage of being open-source and hence is free to download. Apache is the basic software needed
to support running of HTML and related content. Additional software, such as Tomcat, can be installed
to complement the Web Server. Tomcat is a server that is meant to run applications written in Java
and JSP (Java Server Pages).
Some popular options for deploying Apache, and optionally PHP and MySQL on Windows are Apache
Lounge, XAMPP and Wampserver. Wampserver was used for this example. WAMP is an acronymthat
stands for “Windows, Apache, MySQL, and PHP”.
Requirements
To illustrate the steps below a Windows 7 64-bit computer was used. The Windows computer was
connectedtoalocalareanetwork(LAN)thathasInternetaccess.YoualsoneedtoknowtheIPaddressofyour

1
Web Servers

computer.YoucanfindyourIPaddressbytyping‘ipconfig’atacommandprompt.Findtheentrylabeled
‘Ethernet adapter Local Area Network’ and take note of the IPv4 address.

It is recommended to disable the Windows Firewall before starting the Web Server setup. The steps
below are for a fresh installation of Wampserver (assumes that Wampserver had not been installed
before).
InstallingWampserver
Download WAMP from http://www.wampserver.com/en/. You will have the option of choosing 64-bit
or 32- bit installation depending on your PC. This example uses the 64-bit installation. Locate the
downloaded Wampserver file and click on it. This will open an installation wizard as shown in Figure 1.
Follow the instruction wizard and leave the default settings as they are. After successful installation you
will get thewindowshown inFigure 2. Leave the ‘launchWampServer 2 now’boxchecked and click
on‘Finish’button(in future you can start WampServer by clicking on your Start menu and clicking on its
menu). On your toolbar,you should now see a ‘W’ shaped icon. On left-clicking this icon, you get the
pop-up management console in Figure 3. Click on ‘Start all services’ and then check the ‘W’ icon on your
toolbar. If the ‘W’ icon is green it means that all services are running. If it is red it means that no
services are running. If it is orange it means that some services are running. If everything was installed
correctly you should see a window such as the one in Figure 4.

Figure1:WelcomewindowtoWAMPsetup Figure2:Finishedinstallation

Figure3:WampServerManagementConsole

2
Web Servers

Figure4:Localhosthomescreen
SettingupServerPasswords
In this step, you will learn how to create passwords for your server and also passwords to protect the
files that you may want to share from your Web Server.
i. SettingupMySQLandPHPAdminPassword
On your local host home screen (Figure 4) click on ‘phpmyadmin’ under ‘Tools. The interface window
opens showing the WAMP configurationpage. Atthe bottomofthispage, a message indicates
thatMySQLisrunning without a password (Figure 5).

Click on users and then check the box next to ‘root localhost’ and then click on ‘Edit Privileges’ (Figure
6). Scroll down to change the password and then click on ‘Go’ to save the changes. If you try to click on
any other menu on the interface, for example on the SQL menu, you will get an error. Let us fix this by
also changing the PHP admin password to match the MySQL password.

OpenWindowsExplorer.NavigatetotheC:\wamp\apps\phpmyadminx.x.x\folder(Figure7).Insidethat
folder open config.inc.php – ideally using Notepad or any other html editor.
Searchfortheline$cfg['blowfish_secret']='';–ifyou’re usingnotepadit mightbeeasiertojustsearchforthe
word ‘blowfish’. Change the line $cfg['blowfish_secret'] = 'abcdef'; to $cfg['blowfish_secret'] =
'mypassphrase'; where mypassphrase is your own password – not the same one that you specified for
root in MySQL.

Nowsearchforthephrase['auth_type']='config'.Change‘config’to‘cookie’.Nowsearchfor
$cfg['Servers'][$i]['password'] = ''; Replace the '' with 'mysql-password'; where mysql-password is
theMySQL password you created earlier.

Figure5:NoPasswordsetforWampServer

3
Web Servers

Figure6:Changingrootuserprivilege

Figure7:Accessconfig.incfolder

Save the changes you have made and exit out of the editor. Go back to your toolbar where wampserver
islocated and click on ‘restart all services’. Refresh localhost on your browser. Click on ‘phpmyadmin’.
You shouldnowbepromptedfora usernameandpassword.Yourusernameis‘root’(since we
didnotchangeitfrom the default one) and your password is the MySQL password that you created.
ii. SettingupapasswordtoaccessfilesstoredintheWebServer
Nowin case you want to share files from your server, you do not want just anyone to be able to access
the files. Soletuspassword-
protectyourfiles.Forexample,assumethatyouwouldliketostoremusicfilesonyour
serverandsharethemwithothers.First,decidewhereyouwouldliketostoreyourmusicfiles.Inthis illustration,
the folder ‘www’ found in C:\wamp is used to store the music directory. We are assuming that you
want your users to be able to access any folders that are stored inside the ‘www’ folder.

Next,usingacommandprompt,accessthebindirectoryintheApachefolder(Figure8).Thentype:

4
Web Servers

htpsswd–c“C:\wamp\my-password-file.txt”username
my-password-file.txt is the file where you create the password to access the ‘www’ folder. username is
the username that you create to access the ‘www’ folder. Pick a username of your choice. Note that
the password file is not created inside the music folder. After you press enter, you will be prompted to
enter and re-enter a password. Create a password of your choice. This is the password that will be
associated with the username you have just created, and the combination will be used to access the
‘www’ folder.

Figure8:AccessingApachefolderviacommandprompt
Now we want to apply the login to your music folder. Open a new file in a plain text editor like Notepad.
Copy and paste the following into it:

AuthTypeBasic
AuthName"Thisisaprivatearea,pleaselogin"
AuthUserFile "c:\wamp\my_password_file.txt"
AuthGroupFile/dev/null require
valid-user
You can replace the message ‘this is a private area, please log in’ with your own security message that
you would like users to see. Save this file in the ‘www’ folder which is our server root folder. There are
two important things to note when saving this file:
1. Savethisfileas.htaccess(includingthedot).
2. If using an html editor such as Notepad put quotation marks around the name, thus “.htaccess”. This
way, it will not be saved as a text file.
Nowwhenyourefreshyourlocalhostonthebrowser,youshouldbepromptedforlogindetails.
Testing Applications
SharingfilesstoredonyourWampServer
If you would like to share the music files that you have stored on your Web Server, simply create a
directory called ‘music’ insider the ‘www’ folder (Figure 9). Put the music files that you would like to
share in the‘music’ folder. Type http://localhost/music/on your address bar and you should be able to
see a listing of your music.

5
Web Servers

Figure9:Musicfoldertobeshared
Take note of your computer’s IP address. Go to your wampserver toolbar, left-clickand click‘Putonline’.
Your server can now be accessed on the Web.

Share the address http://xxx.xxx.xx.xxx/music/with someone else to try on another computer. ‘xxx’
represents the numbers in your IP address. The user will be prompted for the logindetails that yousetup
inthe last section. Note that this may not work if you are sharing the address with someone outside of
your network who is behind a firewall.

Weshallsoonsee howto writeHTMLfilesthatcanbeaccessedviathe ApacheHTMLserver. The


next section illustrates how to set up an Apache Tomcat server on Windows.
Testinga‘HelloWorld’ Application
Let ustrya simple example to test that the websites we will create will workonthis web server.
OpenNotepad andtypethe followingcodetoprint‘hello
world’andsaveisashello.phpinthe‘www’folder.Thenaccessthis file from your browser using your ip
address or localhost/hello.html. You should get ta ‘hello world’ output on your browser.

<html>
<head>
<title>HTMLTest</title>
</head>
<body>Hellow
orld
</body>
</html>

ApacheTomcatonWindows
ApacheTomcatisaJava-capableHTTPserver,whichisabletoexecutespecialJavaprogramsknownasJava
Servlet and Java Server Pages (JSP). It is also able to execute HTML files just like Apache HTTP.
Requirements
To illustrate the steps below a Windows 7 64-bit computer was used. The Windows computer had
Internet access. Tomcat 8 was used for this installation. You need to have the latest Java JDK version
installed. The recommended JDK version for Tomcat 8 is jdk1.8. Make sure that your computer is
updated with this version. Go to java.com to download the latest version of Java.
The steps below are for a fresh installation of Apache Tomcat (assumes that Tomcat had not been
installed before).

6
Web Servers

TomcatSetup
i. DownloadandInstallTomcat
Go to http://tomcat.apache.org/and download the latest version of Tomcat (Tomcat 9 at the time of
writingthis). Under Download on the left click on ‘Tomcat 9’ and under Binary Distribution click on
‘Core’ and you willsee variouspackages. Clickonthe package applicable to you. For a Windows64-
bitcomputer clickon‘64- bit Windows zip’. Download this file.
Unzip the downloaded file to a directoryof your choice. It is recommended not to unzip to the desktop
as it is a difficult directory to locate from a command prompt. For this illustration a folder named
‘tomcat’ was created under drive D, hence D:/tomcat. The zipped file was extracted to this location. It is
recommended to rename the unzipped file from the default name, for example, rename to
‘apachetomcat’ (Figure 10).

Figure10:Creatingfolderstostoretomcatfiles

ii. CreateanEnvironmentVariable
First, take note of the directory into which JDK was installed. The default is "C:\Program Files\Java\
jdk1.8.0_{xx}", where {xx} is the latest upgrade number. It is important to verify your JDKinstalled
directory before you proceed further. Start the command prompt and type ‘set JAVA_HOMEtocheck if
the environmental variable had been set. If not, you will get the message ‘Environment Variable
JAVA_HOME not set’. IfJAVA_HOMEis set, check if it is set to your JDK installed directorycorrectly (For
example in Figure 11). If not, proceed to set the environmental variable as below.
To set the environment variableJAVA_HOMEin Windows 7: Press "Start" button > Control Panel >
System & Security > System > Advanced system settings > Switch to "Advanced" tab > Environment
Variables > System Variables >"New" (or "Edit" for modification) > In "Variable Name", enter
"JAVA_HOME"> In "Variable Value", enter your JDKinstalled directory(e.g., "c:\ProgramFiles\Java\
jdk1.8.0_51").ClickOK. To verify, restart the command promptand type ‘setJAVA_HOME’. Youshould
nowsee the outputasinFigure 11.

Figure11:CheckingenvironmentalvariablesforJAVA_HOME
iii. ConfigureTomcatServer
The Tomcat configuration files are located in the "conf" sub-directory of your Tomcat installed
directory, e.g. "D:\tomcat\apachetomcat\conf". There are 4 configuration XML files: server.xml,
web.xml, context.xml and tomcat-users.xml.Make a BACKUP of the configuration files before you
proceed.

7
Web Servers

Setthe TCP Port Number


UseanHTMLtexteditor(e.g.,NotePad++)toopentheconfigurationfile"server.xml",underthe"conf" sub-
directory of Tomcat installed directory.

The default TCP port number configured in Tomcat is 8080, you may choose any number between 1024
and 65535,whichisnotusedbyanexistingapplication.Weshallchoose8888inthisarticle. Locatethe following
lines that define the HTTP connector, and change port="8080" to port="8888". Save the file and exit.

<Connectorport="8888"protocol="HTTP/
1.1"connectionTimeout="20000"redirectPort="8443" /
>
EnablingDirectoryListing
Again,useanHTMLtexteditortoopentheconfigurationfile"web.xml",underthe"conf" sub-directoryof
Tomcat installed directory.

Weshallenabledirectorylistingbychanging"listings" from"false" to"true" forthe"default" servlet.


Locate thefollowinglinesthatdefine the"default" servlet;and changethe"listings" from"false" to
"true". Saveand exit.

<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

EnablingAutomaticReload
We shall add the attribute reloadable="true" to the <Context> element to enable automatic reload
after code changes. Again, this is handy for test system but not for production, due to the overhead of
detecting changes. Open context.xml and locate the <Context> start element, and change it to
<Context reloadable="true">. Save and exit.
<Contextreloadable="true">
……</Context>

iv. StartTomcat Server


LaunchaCMDshell.Setthecurrentdirectorytothetomcatdirectory\bin",andrun"startup.bat"asinFigure12:

8
Web Servers

Figure12:Startingtomcatfromcommandprompt

A new Tomcat console window appears (look out for the Tomcat's port number (double check that
Tomcat is running on port 8888). Future error messages will be sent to this console. Output messages
from related Java
programsarealsosenttothisconsole.Ifyouwanttoshutdowntheservertype‘shutdown’inplaceof‘startup’.
Start a browser. Issue URL "http://localhost:8888" to access the Tomcat server's welcome page. For
users on the other machines over the net, they have to use the server's IP address or DNS domain
name or hostname in the format of "http://serverHostnameOrIPAddress:8888". Note that this may
not work if you are sharing the address with someone outside of your network who is behind a
firewall. If everything is setup correctly, you should see the screen in Figure 13.

Figure13:Tomcathomescreenonlocalhost

InstallTomcat'sSampleWeb Application

Goto:http://localhost:8888/docs/
Clickthelink:"3.Firstwebapplication"
Click"ExampleApp"undercontentsontheleftsideofthescreen.
Click on the link "here" to download their "Sample Application". (Download
link: http://localhost:8888/docs/appdev/sample/sample.war )
Savetothislocation:C:\Tomcat\apachetomcat\webapps
GivetheTomcatcontaineraminuteanditwillautomaticallyextracttheWARfileandcreateaWebApplication
called "Sample".
Testyourinstall:http://localhost:8888/sample

If you wishto create your owndirectoryunder webapps, choose anamefor your webapp.
Let'scallit"myapps". Go to Tomcat's "webapps" sub-directory. Create the following directory structure
for you webapp "myapps":
1. Under Tomcat's "webapps", create your webapp root directory "myapps"
(i.e., "tomcat\apachetomcat\webapps\myapps").
2. Under "myapps", create a sub-directory "WEB-INF" (case sensitive, a "dash" not an underscore)

9
Web Servers

(i.e.,"tomcat\apachetomcat\webapps\myapps\WEB-INF").

10
Web Servers

3. Under "WEB-INF", create a sub-sub-directory "classes" (case sensitive, plural)


(i.e., "tomcat\apachetomcat\webapps\myapps\WEB-INF\classes").

Restartyourtomcatservertopickupthechanges.Thenonyourbrowsertypehttp://localhost:8888/myapps/

You should see the directorylisting of the directory"tomcat\apachetomcat\webapps\myapps",


which shall be empty (provided you have enabled directory listing in web.xml earlier).

Weshallsoonseehowto writeHTMLandPHPfilesthatcanbeaccessedviatheTomcat server.


TestingApplications
SharingfilesstoredonyourTomcatServer
If you would like to share the music files that you have stored on your Web Server, simply
create a directory called ‘music’insider the ‘myapps’ folder. Put the music files that you would
like to share in the ‘music’ folder. Type http://localhost:8888/myapps/music/on your address
bar and you should be able to see a listing of your music.
Testinga‘HelloWorld’ApplicationonTomcatServer
Letustryasimpleexampleto testthatthe websiteswe willcreate
willworkonthiswebserver.OpenNotepad andtypethe followingcodetoprint‘hello
world’andsaveis ashello.htmlinthe‘myapps’folder.Thenaccess this file from your browser using
your ip address or http://localhost:8888/myapps/hello.html. You should get ‘hello world’
output on your browser.
<html>
<head>
<title>HTMLTest</title>
</head>
<body>He
lloworld
</body>
</html>

LampserverandApacheHTTPonUbuntu 15.04
In this section, you will learn how to set up a Web Server on Ubuntu 15.04. The steps in this
section will illustrate howto use Apache HTTP. The next section willillustrate the setup for
Apache Tomcat. LAMP stack is a group of open source software used to get web servers up
and running. The acronym stands for Linux, Apache, MySQL or MariaDB, and PHP. Since I
assume that your computer is already running Ubuntu, the Linux part is taken care of.
Requirements
To illustrate the steps below a 64-bit computer running Ubuntu 15.04 was used. The computer
was connected to a local area network (LAN) with Internet access. You also need to know your
server IP address. You can find out your IP address by right clicking the network icon in the
notification area and clicking Connection Information, or by running ifconfig –a on the
terminal. To log into your server, you will need to know the password for the "root" user's
account.First, run the command belowto update your server, before which you will be
prompted to enter your root password.

11
Web Servers

sudoapt-getupdate
stallingApache,PHPandMySQL
RunthecommandsbelowtoinstallApache2WebServerandwaitforcompletionofinstallation.

sudoapt-getinstallapache2
RunthecommandsbelowtostarttheApache2WebServer.

sudoserviceapache2start
Atthistime,ifyoubrowsetotheserver usingitsIPaddress,you’llsee Apache2defaultpageforUbuntuasin
Figure 14. This is how you also tell the server is up and functioning.

Thenextstep isto installPHPas wellasits moduleto enablePHP appsor web servicesto function.
Thereare
hundredsofPHPmodules,butthesefewwillgetmostwebservicesstarted.ToinstallPHPandothermodules,
run the commands below.
sudoapt-getinstallphp5php5-mysqlphp5-curlphp5-gdphp5-snmpphp5-mcryptphp5-tidy php5-xmlrpc
libapache2-mod-php5

Figure14:SuccessfulApacheInstallation
Afterinstallingtheabove modules, gotoApacherootdirectory.Itcanbefoundat/var/www/htmlinUbuntu.
There create a file called phpinfo.php. Then in that file, add the lines below.
<?phpphpinfo();
?>
Save the file, restart Apache and browser to the server IP address followed by phpinfo.php. (ex.
http://Your IP address/phpinfo.php). There you’ll find PHP information page such as Figure 15. This is
how you also know PHP is functioning.

12
Web Servers

Figure15:SuccessfulPHPInstallation
ThenextstepistoinstallMySQL.Runthecommandsbelow.Waitforcompletion.
sudoapt-getinstallmysql-servermysql-client
Afterinstallingthedatabaseserver,youcanstarteditusingthecommandsbelow.
sudosystemctlstartmysql
Whenit’sstarted,runthecommandsbelowtoconfigurethedatabaseserver.
sudomysql_secure_installation
Whenprompted,followtheoptionsbelowandtype yourrootpassword.
Next, choose Yes for the rest of the prompts until you’re done.
 Entercurrentpasswordforroot(enterfornone):Typerootpassword
 Changetherootpassword?N
 Removeanonymoususers?Y
 Disallowrootloginremotely?Y
 Removetestdatabaseandaccesstoit?Y
 Reloadprivilegetablesnow?Y
RestartApache2andyou’redone.

Atthistime,Apache2,PHP5andothermodulesandMySQLdatabaseservershouldbeinstalledand functioning.
You Ubuntu server is ready for any open source application that supports the LAMP stack.

You may wish to install PhpMyAdmin,which is a web interface through which you can easily
manage/administer your MySQL/MariaDB databases. The installation can be completed with the
following command:
sudoapt-getinstallphpmyadmin
Upon installation you will be asked to select the web server you are using. Select “Apache” and
continue. Next you will be asked if you wish to configure phpmyadmin with dbconfig-common. Select
“Yes”. You need to perform one more step so that you can be able to access phpmyadmin from your
Apache server. Run the following command.

sudoln-s/usr/share/phpmyadmin/var/www/html

13
Web Servers

Ifyounowaccessphpmyadminonyourbrowserthroughhttp://YourIPaddress/phpmyadmin
youshouldsee thesame windowinFigure16 and youcanbeableto login using your MySQL username
and password that you created.

Figure16:Phpadminhomepage
TestingApplications
SharingfilesstoredonyourTomcatServer
IfyouwouldliketosharethemusicfilesthatyouhavestoredonyourWebServer,createadirectorycalled ‘music’
insider the ‘var/www/html’ folder.

Putthemusicfilesthatyouwouldliketoshareinthe‘music’folder.Typehttp://localhost/music/onyour
address bar and you should be able to see a listing of your music.
Testinga‘HelloWorld’ApplicationonTomcatServer
Letustryasimpleexampletotestthatthewebsiteswewillcreatewillworkonthiswebserver.Typethe following
command on the terminal to open the gedit editor.
sudogedit
Inthegediteditor,typethefollowingcodetoprint‘hello world’andsaveisathello.htmlundervar/www/html
Then access this file from your browser using your ip address or localhost/hello.html. You should get
‘hello world’ as output in your browser.

<html>
<head>
<title>HTMLTest</title>
</head>
<body>Helloworld
</body>
</html>

ApacheTomcatonUbuntu15.04
Make sure that Java JDK in installed on your machine. For this example, JDK-7 was installed.First, head-
on- over to the Apache Tomcat 8 Download site. Then, under the heading 8.0.28 (the current version as
ofNovember 2015), or whichever is the newest version at the time you read this chapter, you’ll see
Binary Distributions. Under Binary Distributions you’ll see Core and then under Core, you will see tar.gz.
Right click on tar.gz and copy the URL link location.

14
Web Servers

IntheterminalusetheURLyoucopiedthus:

wgethttp://apache.is.co.za/tomcat/tomcat-8/v8.0.28/bin/apache-tomcat-8.0.28.tar.gz
Afterthedownloadcompletes,decompressthefileusingthefollowingcommand:
tarxvzfapache-tomcat-8.0.28.tar.gz

Now,movethefileintoaproperlocationusingthefollowingcommand.Iammovingittoafoldercalledopt.
mvapache-tomcat-8.0.28/opt

Nowlet’ssettheenvironmentvariablesin.bashrcbytypingthefollowingcommand:
vim~/.bashrc

Once in the vim editor, type ‘i’ in order to enter the insert mode. Add this information to the end of the
file.After thatpressesc onthe keyboardto gobackto normal mode. Nextpress‘:’(the colon) and this
willdrop the cursor to the bottom of the terminal. Here you save your changed by typing ‘w’ and press
enter, and then youcan type ‘q’ to quit vim.
exportJAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64export
CATALINA_HOME=/opt/ apache-tomcat-8.0.28Make the changes
effective by running the following command:
. ~/.bashrc
Tomcat should nowbe installed and configured for your server. To activate Tomcat, run the following
script on the terminal. Note that the commands are case sensitive.
$CATALINA_HOME/bin/startup.sh
You can verify that Tomcat is installed correctly by typing http://localhost:8080 in your browser. You
shouldsee the window indicating successful installation.
TestingApplications
SharingfilesstoredonyourTomcatServer
If you would like to share the music files that you have stored on your Web Server, simply create a
directory called ‘music’ insider the ‘webapps’ folder. Put the music files that you would like to share in
the ‘music’folder. Type http://localhost/music/on your address bar and you should be able to see a
listing of your music.
Testinga‘HelloWorld’ApplicationonTomcatServer
Let us try a simple example to test that the websites we will create will work on this web server. Type
the following command on the terminal to open the gedit editor.
sudogedit
In the gedit editor, type the following code to print ‘hello world’ and save is at hello.html under the
webapps folder.Thenaccessthisfilefromyourbrowserusingyouripaddressorlocalhost/
hello.html.Youshouldgetthe output in Figure 17.

<html>
<head>
<title>HTMLTest</title>
</head>

15
Web Servers

<body>Helloworld
</body>
</html>

Figure17:HelloWorldOutput

16
EclipseIDETutorial

TostartEclipse,double-clickontheeclipse.exe(MicrosoftWindows)oreclipse(Linux/Mac) file in the directory where


you unpacked Eclipse.
The system will prompt you for a workspace. The workspace is the physical location (file
path)youareworkingin.Yourprojects,sourcefiles,imagesandotherartifactscanbestored and saved in your
workspace. The workspace also contains preferences settings, plug-in specific metadata, logs etc.
Youtypicallyusedifferent workspacesifyourequiredifferentsettingsforyourprojectorif you want to divide your
projects into separate directories.
YoucanchoosetheworkspaceduringstartupofEclipseorviathemenu (File→Switch Workspace → Others).
SelectanemptydirectoryandclicktheOKbutton.

Onceyouselecttheworkspace,theapplicationwilllooksimilartothefollowing screenshot.
Eclipse projects

AnEclipseprojectcontainssource,configurationandbinaryfilesrelatedtoacertaintask and groups them into


buildable and reusable units. An Eclipse project can
havenaturesassignedtoitwhichdescribethepurposeofthisproject.Forexample,the
JavanaturedefinesaprojectasJavaproject.Projectscanhavemultiplenaturescombinedto model different technical
aspects.
ProjectsinEclipsecannotcontainotherprojects.
Viewsandeditors-parts

Partsareuserinterfacecomponentswhichallowyoutonavigateandmodifydata.Apart can have a dropdown menu,


context menus and a toolbar.
Partscanbefreelypositionedintheuser interface.

Partsaretypicallyclassified into viewsandeditors.Thedistinctionintoviewsandeditorsis


notbasedontechnicaldifferences,butonadifferentconceptofusingandarrangingthese parts.
A viewistypicallyused to workona set ofdata,which might be ahierarchical structure.If
dataischangedviatheview,thischangeistypicallydirectlyappliedtotheunderlyingdata structure. A view sometimes
allows us to open an editor for a selected set of data.
AnexampleforaviewistheProject Explorer,whichallowsyoutobrowsethefilesofEclipse projects. If you change data in
the Project Explorer, e.g., renaming a file, the file name is directly changed on the file system.
Editorsaretypicallyusedtomodifyasingledataelement,e.g.,thecontentofafileoradata object. To apply the changes
made in an editor to the data structure, the user has to explicitly save the editor content.
Forexample,theJavaeditorisusedtomodifyJavasourcefiles.Changestothesourcefile are applied once theuser
selectsthe Save command. A dirty editor tab ismarked with an asterisk to the left of the modified name of the
file.
Perspective

A perspective is a visual container for a set of parts. Perspectives can be used to store
differentarrangementsofparts.Forexample,theEclipseIDEusesthemtolayouttheviews appropriate to the task
(development, debugging, review, ...) the developer wants to perform.
Open editors are typically shared between perspectives, i.e., if you have an editor open in
theJavaperspectiveforacertainclassandswitchtothe Debugperspective,thiseditorstays open.
YoucanswitchPerspectives viatheWindow→OpenPerspective →Other...menuentry.

ThemainperspectivesusedforJavadevelopmentarethe Javaperspectiveand the Debug perspective.


Youcanchangethelayoutandcontentwithinaperspectivebyopeningorclosingpartsand by re-arranging them.
Toopenanewpartinyourcurrentperspective,usethe Window→Show View → Other... menu
entry.
PerspectivesinEclipse

Eclipseprovidesdifferent perspectivesfordifferenttasks.Theavailable perspectivesdepend on your installation.


ForJavadevelopmentyouusuallyusethe JavaPerspective,butEclipsehasmuchmore predefined perspectives, e.g., the
Debug perspective.
Eclipseallowsyoutoswitchtoanother perspectiveviatheWindow→Open Perspective → Other... menu
entry.
Javaperspective andPackageExplorer

ThedefaultperspectiveforJavadevelopmentcanbeopenedvia Window→Open Perspective → Java.


Onthelefthandside,thisperspectiveshowsthe ProjectExplorerview,whichallowsyouto browse your projects and to
select the components you want to open in an editor via a double-click.
Forexample,toopenaJavasourcefile,openthetreeundersrc,selectthe
corresponding.javafileanddouble-clickit.ThiswillopenthefileinthedefaultJavaeditor.

ThefollowingpictureshowstheEclipseIDEinitsstandardJava perspective.TheProject Explorer view is on the left. In


the middle you see the open editors. Several editors are stacked in the same container and you can switch
between them by clicking on the corresponding tab. Via drag and drop you can move an editor to a new
position in the Eclipse IDE.
Totherightandbelowtheeditorareayoufindmore viewswhichwereconsideredusefulby the developer of the
perspective. For example, the Javadoc view shows the Javadoc of the selected class or method.

CreateyourfirstJavaprogram Create project

Select File→New→Javaprojectfromthemenu.

Enterc343.firstastheprojectname.Selectthe Createseparatefoldersforsourcesandclass files flag.


PresstheFinishbuttontocreatetheproject.Anewprojectiscreatedanddisplayedasafolder. Open the c343.first folder
and explore the content of this folder.
Createpackage

Inthefollowingstepyoucreateanew package.Agoodconventionfortheprojectand package name is to use the same


name for the top level package and the project. For example, if you name your project com.example.javaproject
you should also
usecom.example.javaprojectasthetop-levelpackagename.

Tocreatethec343.firstpackage,selectthesrcfolder,right-clickon itand
selectNew→Package.Enterthenameofyournewpackageinthedialogandpress the Finish button.

CreateJavaclass

Right-clickonyourpackageandselect New→Class.EnterMyFirstClassastheclassname and select the public static


void main (String[] args) checkbox. Press the Finish button.
ThiscreatesanewfileandopenstheJava editor.Changetheclassbasedonthefollowing listing.
packagec343.first;

publicclassMyFirstClass{
public static void main(String[] args) { System.out.println("HelloEclipse!");
}
}
Youcouldalsodirectlycreatenewpackagesviathisdialog.Ifyouenteranewpackageinthis dialog, it is created
automatically.

Runyourprojectin Eclipse

Nowrunyourcode.Eitherright-clickonyourJavaclassinthe PackageExplorerorright-click in the Java class and select


Run-as → Java application.
EclipsewillrunyourJavaprogram.YoushouldseetheoutputintheConsoleview.

Congratulations!YoucreatedyourfirstJavaproject,apackage,aJavaclassandyouranthis program inside Eclipse.


How to Install Windows 10? (Step-By-Step Guide)
February 26, 2025 27.5K views
0
This guide will teach you how to install Windows 10 smoothly, covering steps to download Windows 10, complete
the installation process, and deploy Windows 10 on a new PC. With easy-to-follow instructions and visuals, you'll
learn how to install Windows 10 properly and optimize the setup, making this definitive guide essential for any user
upgrading their operating system.
System requirements for installing Windows 10
To install Windows 10, you need to make sure your PC meets the minimum system requirements:
 Processor: 1GHz or faster
 RAM: 1GB for 32-bit OS or 2GB for 64-bit OS
 Storage: 16GB for 32-bit OS or 20GB for 64-bit OS
 Graphics card: DirectX 9 graphics device with WDDM (Windows Display Driver Model) driver
 Display: 800x600 resolution
 Network: Internet connection
It's recommended to use a more powerful PC for better performance. Also, check if your hardware and programs
are compatible before installing.
100% secure Win7, 10, 11
How to install Windows 10? (In Easy Steps)
There are two main methods to install Windows 10:
Type 1: Full installation
Before you start:
 Make sure you have a stable internet connection.
 Get a blank USB drive with at least 8GB of storage space. You'll need to erase everything on the drive, so use a
blank one if you can.
This will erase everything and install a clean version of Windows 10. Follow these steps:
Step 1: Download and Open Windows 10 installation media from Microsoft's website.
Step 2: Accept license terms by choosing Accept.
accept term before installing
Step 3: Choose Create installation media and click Next.
create installation media usb
Step 4: Click Next.
recommended options for this pc before installing windows 10
Step 5: Choose USB flash drive and click Next to proceed.
choose usb flash drive to boot windows 10
Step 6: Plug your USB Device into the PC
Step 7: Select the drive to install Windows and click Next. This will erase and reformat the drive.
select a usb flash drive to install windows 10
Step 8: Windows 10 is now being downloaded into your USB device. Wait until this process finishes and close the
setup window.
download windows 10
Step 9: Plug your USB Device (as a bootable device now) with Windows 10 installer into a new PC.
Step 10: Turn on your new computer and access the BIOS/UEFI (typically using F2, F10, or Del).
change boot order
Step 11: In BIOS/UEFI, set the USB flash drive as the first boot option.
Step 12: Save changes and exit. Your PC will reboot from the USB drive.
Step 13: When the Windows Setup appears, select language, time/currency format, etc. then choose Next.
Setup windows 10 installation
Step 14: After that, Click Install Now and follow the prompts to set up Windows.
install now windows 10
Type 2: Upgrading from an older Windows version
You can also upgrade to Windows 10 from the older version of Windows while keeping files, settings, and
programs. Here is how:
Step 1: Run the Windows 10 installation media.
Step 2: Choose Upgrade this PC now and click Next to start the upgrade.
upgrade this pc now
Step 3: Now, Windows 10 Setup will begin the installation process
creating windows 10 media process
Step 4: Windows will install automatically while preserving files and settings.
installing windows 10 process
Step 5: Windows will reboot several times during the upgrade process. Follow prompts till it finishes.
What to do after installing Windows 10?
After completing Windows 10 installation, here are some recommendations:
 Make sure Windows is activated.
 Update Windows 10 to the latest version for new features and security patches.
 Install the latest drivers for the graphics card, audio, networking, etc., for best compatibility.
 Customize Windows 10 as you prefer via Settings app - themes, Start menu layout, privacy setting, etc.
 Install essential software like antivirus, Office Suite, creative apps, gaming clients, etc.
 Transfer data from a backup or old PC via transfer cable or cloud storage.
 Create a Windows restore point and recovery drive in case of any issues later.
 Remove any unnecessary pre-installed apps for a cleaner system.
Following these post-installation steps will ensure your Windows 10 PC runs smoothly and securely.
Single-User vs. Multi-User:
A single-user system supports only one user at a time (e.g., MS-DOS), while a multi-user system allows two or more
users to access the computer at the same time.

Classification by device
 Desktop OS:
The most common type for personal computers, such as Windows, macOS, and Linux.
  Server OS:
Optimized to handle multiple user requests and run applications for many users, such as Windows Server and Linux
Server.
  Mobile OS:
Specifically designed for mobile devices like smartphones and tablets, such as Android and iOS.
  Embedded OS:
Designed to run on a dedicated device, such as the operating system in a car's navigation system or a smart TV,
such as QNX or embedded Linux.
Windows 10?
Windows 10 is the most recent version of the Microsoft Windows operating system. There have been many
different versions of Windows over the years, including Windows 8 (released in 2012), Windows 7 (2009),
Windows Vista (2006), and Windows XP (2001). While older versions of Windows mainly ran on desktop and
laptop computers, Windows 10 is also designed to run equally well on tablets.
An operating system manages all of the hardware and software on a computer. Without it, the computer would be
useless. To learn more about how operating systems work, check out Understanding Operating Systems and
Getting to Know the OS in our Computer Basics tutorial.
How is Windows 10 different from other versions?
Many users complained that Windows 8, the previous version of Windows, was confusing and difficult to use. As a
result, Windows 10 looks and feels similar to older versions. Still, it includes a lot of new features and
improvements. Watch the video below to learn more:
<span id="selection-marker-1" class="redactor-selection-marker"></span>
Start menu
Whereas Windows 8 uses the Start screen to launch applications, Windows 10 has reintroduced a more traditional
Start menu. It's also been expanded to make it easier to find important apps.

Microsoft Edge
This new browser is designed to give Windows users a better experience on the Web. It's faster, more secure, and
includes a lot of new features. Microsoft Edge is meant to replace Internet Explorer as your default web browser,
but you'll still be able to use another browser if you prefer.

Cortana
Similar to Siri and Google Now, you can talk to this virtual assistant with your computer's microphone. Cortana can
answer questions like What's the weather like today?, perform simple tasks like remind you to take out the trash,
and much more.
Multiple desktops and Task view
Instead of keeping everything open on the same desktop, you can move some of your windows to a virtual desktop
to get them out of the way. And the new Task view feature makes it easy to manage all of your open windows.

Action Center
The new Action Center is pretty different from previous versions of Windows. For example, it's been expanded to
let you access frequently used settings, such as Wi-Fi connectivity and tablet mode. It's also where you'll see
important notifications, so if your computer receives an update you'll get a notification about it here.
Tablet mode
Unlike Windows 8, Windows 10 makes a clear distinction between desktops and tablets. If you're using a keyboard
and mouse with Windows 10, you'll be in desktop mode by default. If your computer also has a touchscreen, you
can go into tablet mode at any time. Tablet users can also switch back to desktop mode if they prefer.

Should you upgrade to Windows 10?

Talk to our experts


1800-120-456-456

 Computer Science
 Exploring Windows 10
Exploring Windows 10
Reviewed by:
Nafeez Khan
Download PDF
Study Materials
Sample Papers
Syllabus
Textbook Solutions

Introduction to Windows 10
Windows 10 is the most significant release of the Windows operating system since Windows 8. It came out first in
July 2015. This update brought back the much-loved home screen of Windows 8. The Start button has been added
back, and the vertical toolbars have been removed. It was later succeeded by Windows 11 in 2021.

Features of Windows 10 in Computer


The main features of Windows 10 in computers have been explained below:
 Start Menu

Start menu.

The Start menu is the place from which you can open any programs. There are two ways to open the Start menu.
A. Click one time with the mouse on the start button located on the down left side of the homepage.
B. Press the Windows key located on the keyboard.

 Action Center

Action Center

The action center is a window that allows you to access useful shortcuts and tools quickly. Various services like Wi-
Fi, Bluetooth and location are available in it.

 Task Bar

Taskbar

The task view bar is located at the very end of the home page. It displays the frequently used apps so they can be
easily accessed. On the left side, it shows information like Internet connection, battery percentage, etc. In the
centre, the apps you have pinned down will appear. Microsoft Edge is the default app pinned down in the Task Bar.

 Task View
Task View

The Task view can be opened by clicking on the Task view from the Taskbar. It allows the user to change the tab
that is open. You can also use it to see all the tabs at one time and remove any tab you do not want.

 Tablet Mode

Tablet Mode

The tablet mode is Windows 10 allows you to open apps in a tablet-size window. This feature is very useful for
people using computers and smartphones.

 File Explorer

File Explorer

The file explorer in Windows 10 allows the user to access his/her files. You can open, close, delete, share and copy
your files easily with the help of file explorer.

 Cortana

Cortana

Cortana is a virtual assistant developed by Microsoft. It has the ability to write and send emails or messages by
itself. You can search for various information just by speaking to it. You do not need to press any key on the
keyboard to use Cortana. It allows you to truly do multitasking efficiently.

 Microsoft Edge

Microsoft Edge

Microsoft Edge is the new browser developed by Microsoft. It has replaced the older Internet Explorer web
browser. Microsoft Edge uses the Microsoft Bing search engine as its search engine. Microsoft Edge is faster and
more secure than Internet Explorer. It is the only pinned-down app in the task view bar by default.

 Firewall
Firewall

It is like a virtual wall that protects your computer. It checks the information entering the computer. If any threats
are found, it blocks the information from entering the computer.

 Screensaver

Screensaver

When you do not use the computer for some time, it goes dormant. When it is in a dormant state, it displays a set
image on its screen.

 Viruses

Virus

Viruses are unneeded software that try to harm your computer. It has the ability to modify or delete files from your
computer. It can automatically create many copies of it itself and slow down the computer.
The Definition of Windows Operating System: History, Functions, and Features

 meilinaeka
 28 April 2023
 Blogs
This article explains about the Windows operating system developed by Microsoft and released in 1985. In this
article, you will find the history of the evolution of the Windows operating system, its main functions in
managing computer resources.
Definition of Windows OS
Windows operating system is a computer program that manages all computer resources and provides services to
applications that run on top of it. This operating system was developed by Microsoft and released in 1985 under
the name Windows 1.0. Since then, the Windows operating system has continued to evolve and become one of the
most popular operating systems in the world. The Windows operating system is designed to run on various types of
hardware, including desktops, laptops, servers, and mobile devices. Windows uses a graphical user interface (GUI)
that allows users to interact with the computer through icons, buttons, and visual menus, rather than using text
commands like other operating systems. Windows also has many features such as multitasking capability, which
allows several applications to run simultaneously, as well as plug-and-play capability that makes it easy for users to
connect additional devices such as printers, scanners, and cameras.
History of Windows OS
This OS was first introduced by Microsoft in 1985 and has since undergone many developments and evolutions.
Windows 1.0, the first version of this OS, was released in November 1985. This OS was the first graphical operating
system designed for commercial use and could be used on PCs using Intel 8086 or 8088 processors. Windows 1.0
had a simple interface and offered support for several applications, such as Paintbrush, Write, and Calculator.
In 1987, Microsoft released Windows 2.0. This OS offered several improvements and enhancements compared to
the previous version, including support for more applications, the ability to run multiple programs simultaneously,
and the introduction of drag-and-drop functionality.
Windows 3.0, released in 1990, was the first truly popular Windows operating system. Windows 3.0 offered a more
modern and user-friendly interface, support for more programs, and the ability to run multiple programs
simultaneously. In addition, Windows 3.0 also included the introduction of features such as File Manager and
Program Manager.
Windows 95, released in 1995, was a very popular Windows operating system and a milestone for modern
operating systems. Windows 95 offered a completely new interface, which included the Start button and Taskbar,
as well as support for plug-and-play hardware. Windows 95 also added support for 32-bit programs and introduced
features such as Windows Explorer, Internet Explorer, and Microsoft Office software.
After Windows 95, Microsoft released several other versions of Windows, including Windows 98, Windows 2000,
Windows XP, Windows Vista, Windows 7, Windows 8, and Windows 10. Each version of this OS offered different
improvements and fixes, including performance improvements, enhanced interface, support for new hardware and
software, and better security features.
The Windows operating system has undergone incredible evolution since it was first launched in 1985. Each version
of Windows offers different improvements and fixes, and this operating system remains one of the most popular in
the world to this day.
Functions of the Windows Operating System
The functions of the Windows operating system are crucial in running various applications and programs on
computers or laptops. Some of the functions of the Windows operating system include:
Managing Computer Resources: The primary function of the Windows operating system is to manage and organize
computer resources such as CPU, RAM, and hard disk. The Windows operating system will complete various tasks
such as opening applications, accessing the internet, and printing documents using these resources.
Providing an Interface: The Windows operating system provides a Graphical User Interface (GUI) that allows users
to access and use various applications and programs easily. This interface allows users to select menus, click icons,
and navigate various applications easily.
Providing Compatibility: The Windows operating system is designed to support various hardware and software
devices, making it easier for users to install and use different applications and programs on their computers or
laptops. Windows also provides the ability to run programs and applications designed for different versions of the
Windows operating system.
Facilitating Network Setup: Windows operating system provides various tools to facilitate network setup, such as
network configuration, firewall configuration, and network access configuration. This allows users to connect to
networks and share data with other devices in the network easily.
Facilitating Security: The Windows operating system provides various security features such as anti-virus, anti-
malware, and firewall that help protect computers or laptops from virus and malware attacks. Windows also
provides tools to configure network security and access control to protect user’s important data.
Managing File Management: Windows also facilitates file management such as data storage, access rights
configuration, and file searching. Windows provides various tools to help users organize and store data and files on
their computers or laptops.
Facilitating System Setup: Windows provides various tools for system setup such as desktop appearance
configuration, sound and visual effects configuration, and operating system updates. This makes it easy for users to
configure and update the operating system according to their needs and preferences.
Providing Technical Support: Windows provides technical support for users in the form of customer service,
tutorials, and documentation. This helps users solve problems and optimize the use of Windows operating system
on their computers or laptops.
Advantages and Disadvantages of Windows Operating System
As the most widely used operating system in the world, Windows has various advantages and disadvantages that
need to be considered. Here are some of the advantages and disadvantages of the Windows operating system:
Advantages:
Wide Compatibility: Windows has extensive compatibility with various hardware and software devices, making it
possible for users to use different types of devices with this operating system.
Ease of Use: Windows is designed with a user-friendly and familiar user interface for many people, making it easy
to learn and use even for new users.
Rich Multimedia Features: Windows provides many multimedia features, such as Windows Media Player, that allow
users to play various types of audio and video files easily.
Large Developer Support: There are many developers who make applications and games for Windows, so users can
choose from a variety of application and game options available.
Long-term Support: Microsoft provides long-term support for each version of Windows, which means users can
receive updates and security support for several years after its release.
Disadvantages:
Vulnerability to Malware: As the most widely used operating system in the world, Windows is also more vulnerable
to virus and malware attacks, so users need to be more cautious in using it.
Hardware Requirements: Windows requires relatively high hardware requirements, making it difficult for users with
older computers or laptops to use the latest version of Windows.
Cost: Windows is not a free operating system, so users need to purchase a license to use it, which can be expensive.
Having too many features: In some cases, Windows can be too complicated with too many features, so users have
to take the time to learn and understand these features.
In conclusion, Windows OS has its strengths and weaknesses like any other operating system. However, its wide
compatibility and large developer support make it the top choice for many users. Users should take note of these
shortcomings and ensure to take necessary security measures to protect their devices from virus and malware
attacks.
20 Features Of Window 10 Operating System
 ShiwKumar Gupta
 1y
 178.3k
 9
 2
300
 Article
Introduction
Windows 10 is the new Microsoft Windows Operating System and successor to the Windows 8 (and Windows 8.1)
Operating System. It is a familiar and flexible computer operating system like Windows 7 with the Start menu
developed by Microsoft as part of the Windows NT family of operating systems.
Features of Windows 10
Windows 10 was released with mostly positive reviews upon its original announcement in July 2015; detractors
praised Microsoft's decision to downplay user-interface mechanics introduced by Windows 8 (including the full-
screen apps and Start screen). Here are the best features of the operating system.
It's free
One of the best new growth in Windows 10 is that it is completely free to upgrade. Microsoft made this declaration
at its January event in Redmond. The steady has said it will be available at no charge for the first year for Windows
8.1 and Windows Phone 8.1 users. It will also be free if you are still running Windows 7.
Start Menu
As we know previous to the January meeting, Windows 10 will mark the return of the much-loved Start Menu. In
the latest build shown, it has some updated graphics and can optionally go full-screen. In this feature half of the
menu looks pretty much like it did in Windows 7 but there's the clear addition of Live Tiles.

Snap Assist helps you snap windows


A new feature is Snap Assist that helps users work out, you need to do is to drag the title bar to the edge of the
screen. Snap has been already available in previous versions of Windows, but some features have been added.
Drag the title bar to the edge top of the screen maximum window.
You can drag the left or right edge of the screen to snap the application to the right or left.
Cortana
Cortana is a new feature of Windows 10. It is a voice-activated personal associate. We can use it to set reminders,
get weather forecasts, tell you jokes, send an email, find files, and search the Internet, and so on. The digital
associate, which rivals Google Now, has been available on Windows Phone for a while and will come to PCs and
tablets. To get started, type a question in the search box on the taskbar. Or select the microphone icon and talk to
Cortana.
Here are some things we can say to Cortana.
 Tell me a joke
 Where are you from?
 How old are you?
 What's happening this weekend?
 What’s going on in your life?
 What’s up?
Command Prompt
This is the new feature of the command prompt is now getting a keyboard shortcut, which is copying/pasting your
command prompt. Specially, you can now use Ctrl + C and Ctrl + V in the Command Prompt. The previous version
does not this feature.
Settings App vs. Control Panel
In the start menu of the setting option, you can take straight to the new setting app that is involved from the PC
setting app on Windows 8. This is a more user-friendly way to arrange your computer. However, it does not contain
every system. The old control panel window is still included. It’s also available in the old control panel window.

Xbox app and streaming


Microsoft developed the Xbox app for game streaming to Windows 10 back in January; we can meet up with
friends online, and see what your friends are playing. The Xbox app dashboard has been updated to support the
new feature; the Xbox One app for Windows 10 is not quite ready yet. This feature allows you to leave your living
room and play your favorite Xbox One games anywhere with access to your home network. This is good news for
gamers as not only the Xbox One get Windows 10; but Windows 10 will also come with the Xbox app although
there was no indication of Windows 10 for phones getting it, which has features like the capability to control the
Xbox One and a DVR capture for any Windows games.
Desktop and Security Improvements
There are still many desktop security improvements to do in Windows 8, but we have not seen them if we have
used Windows 7. Microsoft gives the features of upgraded task manager, it’s so easy to what’s requirements and
resources of your system and even manages a startup program without third-party software. Windows 10 includes
Windows Defender by default, Window Defender has just changed the version of Microsoft Security Essentials.
Window Defender has antivirus protection to save your system.
File Explorer
File Explorer is also known as Windows Explorer. It is a core part of the operating system. You can use the shortcut
“Windows + e” on your keyboard. When File Explore opens, we can access the frequently used folders and recently
used files.

Universal apps
The universal app is a Windows experience that is made upon the Universal Windows Platform (UWP). It is good
news for someone using more than one Windows device. A package of apps with Photos, Videos, Music, Maps,
People and Messaging, and Mail and Calendar will look and feel the same across different devices and screen sizes.
Universal apps include a lot of backend enhancements for developers that encourage development on Windows
Phone and Windows 8. They are not completely the same in terms of code; nor does it mean that developers can
just push a button to make those apps on either platform.

Edge browser
Microsoft developed a new web browser called Edge; It gives you new ways to find stuff and read/write on the
web. Microsoft Edge is built with interoperability in mind, according to Microsoft. It’s a feature that includes a
reading mode and the ability to annotate, either with a keyboard, pen, or a finger. There's also integration with
Cortana to provide additional information, for example, when we are on a web page for a restaurant/Hotel Cortana
will make a booking and display information such as opening times.
Best new features in Windows 10
Enhancements The new OS is still in active development; the main features and enhancements of Windows 10 are
more or less feature-locked and are certain to the announced within Windows 10 Release to Manufacturing (RTM).
Microsoft is making changes suggested by Windows users around the globe. Since Windows 10 runs across all
devices, the OS will have unified settings. It means the end of a distinct control panel and PC settings.
There's also the Action Center now provides notifications and is synchronized across devices. Contact Support
Microsoft has added a new feature in Windows 10 is safe for users who fail to find any they need. Users can contact
the Phone or Chat Microsoft Tech Support Team using the Contact Support App, to solve the problem with Internet
Explorer Edge, Office, and Xbox. We can chat online on a call.
Microsoft Money
Microsoft Money is a personal finance management software program from Microsoft. It has capabilities for
viewing bank account balances, tracking expenses, and creating budgets.
Phone Companion
Microsoft announced a special type of phone companion app for Windows 10 that strategy to understand
smartphone owners to gap between their handset and computer. The phone companion app works like a hub
(center) to download apps like Skype, Outlook, and Xbox Music, etc.
Windows Phone
Windows 10 has launched but it does not get on your phone. It can’t say that Windows Phone 10 as the new
operating system will run phones, tablets and you’re PCs. Windows Phone is near as Windows 10 will arrive on
Windows Phone devices when it launches. Microsoft has given no other name for running it on a smartphone, small
tablets, and PCs. It looks much the same as Windows Phone 8 but with tweaks. Action Center is synced with your
other devices and the app menu will show recently installed apps at the top. Windows 10 is already here for your
computer and we have got all the details you need.
HoloLens
HoloLens is Microsoft's immersive headset. We discuss one platform, a single binary, a single app that can run
across all of these devices." This means it’s a futuristic, hologram-generating HoloLens headset. Windows 10 is the
first holographic computing platform. A developer can create holographic experiences with a set of APIs in the real
world. Microsoft receives the world’s first untethered holographic computer that doesn't need to connect to a PC
to work with the HoloLens.
Continuum Mode
Continuum is a method for Windows to define the hardware, we are always using the optimum interface on the
machine. If we are using a desktop or laptop with no touchscreen, then Windows will now know this and present
the traditional mouse and keyboard interface. The OS moves easily between laptop/ desktop (keyboard/mouse)
and tablet (touch) usage modes automatically. It will do this if it detects the loss or addition of a keyboard.

Alarms and Clock


Microsoft announced some new system apps with new designs and features in the table. We detail what’s new in
the Alarms and Clock apps which seem to have grown significant improvements.
We start with the new alarm app called ‘Clock’ considering all of the new features. The app has four tabs, Alarm,
World Clock, Timer, and Stopwatch.
Calculator and Maps
Microsoft has developed a standard calculator in Windows 10. As we know the desktop Calculator in Windows 7
and Windows 8/8.1 sports a simple interface but it’s very powerful. The new standard-style Calculator in Windows
10 is well-looking.
Maps guide for everywhere that finds our voice navigation and turn-by-turn driving and walking direction.
Summary
In this article you will learn the features of Windows 10, Hope you like it.
Hidden Windows 10 Features and Functions
February 25, 2020

Whether you are new to Windows 10 because you recently upgraded after support for Windows 7 was
discontinued, or you haven’t explored more recent updates to the operating system, there are a lot of ways to
enhance your computing experience. There are many enhancements including an upgraded clipboard, new screen
capture, and dark mode. You can also enable speech recognition and dictation, control updates and customize the
tiles menu. Read more to find out about how to control your Windows 10 experience.
Windows Updates
The most recent major to the Windows 10 operating system was in November 2019, though smaller updates are
issued frequently. Windows 10 updates also include security patches, which are very important but recently have
made headlines for wreaking havoc on your system. You can control if your computer gets auto-updates, uninstall
troublesome updates, and more by typing “Windows Update” in the search bar. To uninstall an update go to
Windows Update – View Update History – Uninstall Updates. You can also download the Windows Update
Troubleshooter to hide problematic updates and prevent them from reinstalling. It is also a wise idea to set
automatic restore points so if something goes terribly wrong you can revert to a previous version of your system.
The restore point does not delete new files, but it is always a good idea to have redundant file backup.
Show Desktop Button
This feature has been in the Windows operating system since Windows 7, but still useful to know. In the far-right
corner of your screen there is a tiny, practically imperceptible vertical bar. If you click on it, you will be taken
directly to your desktop without having to close or minimize any applications. Click it again to return to where you
were. If you want to be able to glance at your desktop simply mouse over the button to “peek” at your desktop.
Enable Peek by going to Settings – Personalization – Taskbar – Use Peek to Preview the Desktop.
Windows 10 Tiles and Start Menu
Windows 10 uses “tiles” to show you applications, weather, and other information and replaced the standard
Windows start menu. If you don’t like the tiles you can customize them, remove them, or even revert to the
Windows 7 look and feel with a third party app. You can also access the “secret” start menu by right-clicking on the
Windows button in the lower-left corner of your screen or using the Windows keyboard shortcut Windows key + X.
Task View and Virtual Desktop
In the Windows 10 taskbar, there is an icon that looks a little like a ladder. If you click on it you will be able to see all
the applications you have open and go to them, or close them. It also shows you the documents you have worked
on in the past few days. If you click on “New Desktop” you can create virtual desktops. A virtual desktop will let you
create multiple desktops with default apps and docs open. For instance, you can have a desktop with your primary
productivity apps open (like Word, Excel and your practice management app) and one with your communication
tools like Outlook, Teams or Slack. By segregating your desktops, you can reduce distractions and focus on tasks
more effectively.
Silence All the Notifications
By default, Windows 10 pops up a lot of alerts. You can control this by using Focus Assist, which came out with the
April 2018 update. Go to Settings – System – Focus Assist and you can customize notifications for just about
everything. You can also add “quiet hours” so you can schedule deep work and get no notifications. You can
further refine notifications under “Notifications and Actions” so that you get only the notifications you want, when
you want them.
Speech Recognition/Dictation
You can dictate text, open applications and perform other tasks by voice. To enable and customize speech
recognition in Windows 10 press Windows key + H. If you haven’t enabled speech services, you will be guided
through the process via Settings. Like other speech recognition tools, you’ll need to say “period”, “comma”, “new
line”, etc. when dictating. If you need to correct something just say, “undo that”. You can also have text read back
to you, which may help identify tone and word choice. There are a lot of options and features you can leverage
with the speech recognition tools. If you don’t want to turn on speech recognition operating system-wide, Word
and Outlook have their own dictation tools built-in.
Cortana
Cortana is the Windows 10 “personal productivity assistant”, much like Siri in iOS. You can control what permissions
Cortana has and when to wake “her” up. In addition to voice commands you can cc Cortana on an email to help
find available time on your calendar. If you like using Siri and talking to your device give Cortana a try. If you prefer
not to have your computer listen to you then disable Cortana or log out of Cortana.
Dark Mode
In Windows 10 you can change your color scheme by going to Settings – Personalization – Colors. You can have one
theme for Windows menus and a different one for apps. You can customize the colors in each one, should you
choose to do so. Dark mode is very popular, as it helps reduce eye strain and also can help save your battery on a
laptop. It also makes icons much easier to see, especially in your taskbar. If you just want to change your color
scheme for Office 365 go into Outlook, click File – Office Account – Office Theme and choose from Colorful, Dark
Grey, Black or White.
Cloud Clipboard
You can save multiple items in your clipboard when you copy images or text to reuse in applications, as well as keep
a history of what you have copied. Because copies are now stored in the cloud you can access your history and
paste into an application on a completely different device. Enable the clipboard history by going to Settings –
Clipboard and turn on Clipboard history. You can choose whether the clipboard is cloud-enabled by toggling on
“sync across devices”. To enable your clipboard history press the Windows logo key + V. There are a lot of options
with this powerful feature.
Snip & Sketch
The handy Windows Snip tool has been around since Windows 7 and it lets you capture and crop any part of your
screen, a much more granular option than doing a print screen. The new clipping utility that came with the October
2018 update is called Snip and Sketch. In addition to “snipping” a select portion of your screen you can now have it
do a “countdown” before capturing the clip so you can open menus and other setups. You can annotate the clips
(thus Sketch), crop them and save them. However, if you need a powerful screen clipping and annotation tool you
still need something like Snagit.
Security Features
In Windows 10 you can turn on Windows Hello to unlock your computer with facial recognition, as well as log you
into apps like Dropbox, Office 365 apps and more. Additionally, Windows 10 comes with Microsoft Defender which
includes antivirus, firewalls, real-time protection and more. To configure it and learn more go to Settings – Security
Center – Windows Security. You can run Windows Defender and another antivirus product simultaneously.
Conclusion
There are lots of other tips, tricks and options in Windows 10. While you don’t necessarily think about the
operating system too much, focusing more on the apps that support productivity, communication and information,
knowing some ways to leverage the platform these apps sit on can help you leverage the power of your Windows-
based computer.
Introduction to Windows
In this topic, we will learn about the Introduction to Windows. Microsoft Windows is a multitasking operating
system developed by Microsoft Corporation, which uses Graphical User Interface to interact with users. Microsoft
was initially named “Traf-O-Data” in 1972, was renamed “Micro-soft” in November 1975, and then “Microsoft” on
November 26, 1976. Microsoft entered the marketplace in August 1981 by releasing version 1.0 of the operating
system Microsoft DOS (MS-DOS), a 16-bit command-line operating system. Bill Gates and Paul Allen founded
Microsoft, and the Windows operating system has been its primary product.
In this Introduction to Windows, we will also clear you about the latest OS release of Windows, “Windows 10”,
launched in 2015.
In a nutshell, below is how Microsoft Windows evolved:
 Windows 1.0 – Nov 1985
 Windows 2.0 – Dec 1987
 Windows 3.0 – May 1990
 Windows 95 – Aug 1995
 Windows 98 – June 1998
 Windows ME – Sep 2000
 Windows XP – Oct 2001
 Windows Vista – Nov 2006
 Windows 7 – July 2009
 Windows 8.0 – Oct 2012
 Windows 8.1 – Oct 2013
 Windows 10 – July 2015
 Windows 11 – October 2021
Main Components of Windows
After learning about the Introduction to Windows, we are now going to study the main components of Windows.
The main components of the Windows Operating System are the following:
 Configuration and maintenance
 User interface
 Applications and utilities
 Windows Server components
 File systems
 Core components
 Services
 DirectX
 Networking
 Scripting and command-line
 Kernel
 NET Framework
 Security
 Deprecated components and apps
 APIs
Source Link: https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_components
When coming to GUI components, we have the following as the main components:
1. Desktop
It is the first screen you will see once the windows start. Here you will see “My Computer”, “My Documents”, “Start
Menu”, “Recycle Bin”, and the shortcuts of any applications that you might have created.
2. Taskbar
At the bottom, you will see a row known as the taskbar. It has the currently running applications; you can pin
applications you frequently use using the option Pin to Taskbar”.
3. Start Menu
This is located in the bottom left corner of Windows OS GUI. This is where the user can search for any setting and
any application for their use. Users can uninstall or repair applications from the control panel. The user can do a lot
of activities just by searching through the start menu.
4. My Computer
Double-clicking the “My Computer” menu will let you navigate between your different computer drives and the
control panel tools. You can see and manage the contents that are inside your drive.
5. Recycle Bin
Deleting an item from any of your drives using the “delete” button or simply clicking right-clicking and selecting the
“delete” option is not deleted completely. Instead, it is moved to the “Recycle Bin” folder of Windows. You can
recover your content if you have deleted it by mistake, or if you choose to delete the items from here, it will get
deleted permanently. Should you wish to delete the item in the first go itself without moving it to recycle bin, you
can use the key “Shift+Del”
Features of Windows
 Windows Search: We can have multiple files and contents located on our system, and sometimes we may run out
of memory about the exact location of our file. Windows Search is a function included with Windows that allows
users to search their entire computer.
 Windows File Transfer: We may need to transfer in or transfer out the files and contents from our machine to
other devices such as other computers or mobiles, and tablets. We can do this using an Easy Transfer Cable, CDs or
DVDs, a USB flash drive, wireless Bluetooth, a network folder, or an external hard disk.
 Windows Updates: Windows includes an automatic update feature to keep its operating system safe and up-to-
date.
 Windows taskbar: At the bottom-most part of your windows, you will see a row known as the taskbar. It has the
currently running applications; you can pin applications you frequently use using the option Pin to Taskbar”. The
taskbar is the main navigation tool for Windows.
 Remote Desktop Connection: This Windows feature allows you to connect to another system and work remotely
on another system.
Windows Applications

A program that is written to run under the MS operating system is the Windows Application. Examples of
applications that run on Windows OS are Microsoft Outlook, Internet Explorer, Remote Desktop Condition,
Snipping Tool, and numerous others.
These applications provide great functionality for users to do their day-to-day activities. Every application
developed for them to launch on Windows should be compatible with the Windows operating system. That is why
when you install software, you might see two or three download options, download for Windows, download for
Linux and download for iOS. If you are interested in developing applications for Windows, you can start right here:
https://docs.microsoft.com/en-us/windows/win32/
Advantages and Disadvantages of Windows
After going through all the components, Features and the broad Introduction to Windows, we will explore the
advantages and disadvantages of Windows.
Advantages
 Desktop as well as tablet-friendly OS.
 Switching between applications is very easy.
 Operating Windows does not require much technical knowledge.
 Windows OS is the dominant OS and enjoys over 90% of the Market share.
 MS OS has a great support community, and it also has the most significant number of applications.
 Microsoft provides a robust set of Enterprise focused Operating Systems, Applications and services, making it the
most dominant player in the OS market.
 More gaming.
Disadvantages
There are privacy and security concerns and incidents, and they are widespread. Linux OS is by far the most secure
OS ever built.
 Cost for an upgrade.
 Windows OS attracts many virus programs due to its significant market share and easy-to-breach paradigm.
 Windows OS is not that much of touch-friendly.
History
 DOS (Disk Operating System) was developed by Microsoft Inc. and released it as IBM PC DOS (known as MS-DOS)
for the first time on August 21, 1981, as MS-DOS 1.0, which was written by Tim Paterson.
 It was last updated in April 1994 when MS-DOS 6.22 was released. Today, MS-DOS is no longer used at large scale;
however, the command shell, more commonly known as the Windows command line is still used by many users in
window OS.
 It was the first OS for the PC (IBM PC) and is the underlying control program for Windows 3.1, 95, 98 and ME.
 Windows NT, 2000 and XP emulate DOS in order to support existing DOS applications.
Introduction
 This OS was written initially in assembly language and later advance version also with C language.
 The first version of MS DOS was MS DOS 1.x and latest version is MS DOS 7.
Definition
 DOS is a Free, single-user, single or Uni tasking, earlier, 16-bit, CUI/character based or command line(non-GUI),
standalone operating system from Microsoft for the PC that controls and regulates computer’s hardware and
peripheral devices behaviour and functionality.
Features
 DOS contains a master control program that is automatically run when we start our personal computer (PC). DOS
stays in the computer all the time letting us run a program and manage files.
 DOS uses the File Allocation Table (FAT) filesystem. This was initially FAT12 which supported up to 4078 clusters per
drive. Later, DOS 3.0 added support for FAT16 which used 16-bit allocation entries and supported up to 65518
clusters per drive.
 Advantages:
o DOS (Disk Operating System) was the first widely installed operating system for personal computers.
o It is Free OS.
o It does File management works such as creation, updation, deletion of files.
 Disadvantages:
o It doesn’t support GUI i.e. it has text based interface.
o It has Single user OS.
o It has Uni tasking OS.
o It is a 16-bit OS.
o The mouse didn’t work in it.
Terminology
Commands:
 A command is a set of instructions used to perform a specific task on files or directory.
 This command is executed/interpreted by OS interpreter to a machine language (0&1).
 It is unique keyboard recognize by an OS.
 There are two types of DOS Commands-
(a) Internal DOS commands

o These commands are loaded during/with the system booting with command.com file and are stayed and executed
from the RAM.
o These commands cannot be created, viewed, updated or deleted by the user because they do not exist in the form
of a file rather included in command.com file.
o These commands are in-built in DOS and are part of shell.
o There is no external file to read the internal commands.
o Examples are – DATE, TIME, VER, VOL, MD, CD, CLS, DEL, CLEAR, COPY CON, REM, RMDIR, TYPE, BREAK, CALL,
CMD/COMMAND, COLOR, ECHO, EXIT, CTTY, FOR, GOTO, IF, MD, MKDIR, LOCK, MOVE, PATH, PAUSE, PROMPT, RD,
REN, RMDIR, UNLOCK, TITLE etc.
(b) External DOS commands

o These commands are only loaded from disk to main memory as a file when they are invoked.
o These commands are loaded after system booting when required and are present and executed from the Disk.
o It can be invoked whenever necessary.
o These commands are not in-built in DOS and are part of shell.
o These commands can be viewed, updated, copied or deleted by the user because external files exist in the form of
a file as .exe, .bat, .com etc.
o Examples are – APPEND, ASSIGN, ATTRIB, CHKDSK, COMPACT, DEBUG, DEFRAG, DELTREE, DISKCOPY, EXTRACT,
FDISK, FIND, HELP, IPCONFIG, LABEL, LOGOFF, MORE, NET, NETSH, NETSTAT, PING, POWER , QBASIC, SCANDISK,
SHUTDOWN, TELNET, EDIT, SYS, FORMAT, XCOPY, PRINT, SORT, TREE, UNDELETE, UNFORMAT etc.
Directory(Folder):
 Directory is a file used to store/list another files and directories(called sub-directory) inside it.
 It is considered as a catalog of files & directory.
 There are 3 types of directory used in MS-DOS –
(a) Root Directory

o A directory which is created automatically when the disk is formatted.
o For example –
 For a floppy disk, drive A:\ and B:\ are root directory.
 For a hard disk, drive C:\, D:\, E:\ etc. are root directory.
(b) Parent Directory

o Parent directory is a directory which is one level up to the current directory.
o For example –
 C:\ Audio\Sad_Songs\01.mp3.
C:\ = Root directory.
Audio = Parent directory.
Sad_Songs = Current or working directory.
01.mp3 = An Audio file.
(c) Current or Working Directory

o The directory in which a user is working at that moment or currently.
o For example –
 C:\ Audio\Sad_Songs\01.mp3.
C:\ = Root directory.
Audio = Parent directory.
Sad_Songs = Current or working directory.
01.mp3 = An Audio file.
Sub-directory (Sub-folder):
 A directory is within/inside a directory is called sub-directory.
Wild Card Characters in MS DOS:
 Wild Cards are special characters and symbols that represent one or more characters.
 The wild card characters are – (*) Asterisk – used to represent one or more characters and (?) Question mark –
used to represent single character.
 Wild card is mainly used to search specific pattern of files or directories.
DOS Commands
 DOS commands are not case sensitive.
How to open DOS in Window XP/7/8.1/10 OS
(a) Press “Window key+r” – Type ”cmd or command” in box – ok.
Discover more
Computer programming
Computer
Science
computers
Programming
OR
(b) Right click on Start button – Choose and click “Command prompt or command prompt(admin)”.[In window 10
OS]
Discover more
Computer
computers
Programming
Science
Computer programming
NB: command prompt(admin) is used to open DOS in administrator mode.
Batch Command :
 The batch command is a recovery console command that executes a series of commands written within a file called
Batch files.
 Batch files allow MS-DOS and Microsoft Windows users to create a list of commands to run in sequence once the
batch file has been executed.
 A simple batch file does not require any special programming skills and can be done by users who have a basic
understanding of MS-DOS commands.
 A good example of Batch file is use of Shortcut icon in Windows. Another very good example of Batch file is the use
of Autoexec.bat file. (This is a boot batch file loaded each time the computer boots into MS-DOS and early versions
of Windows. This batch file contained all the necessary commands and programs used to run MS-DOS and
Windows each time the computer booted.).
 A batch file is executed in two ways – By command prompt and double click on the batch file.
 Batch files are created through two ways –
o Using MS-DOS:
 A basic batch file is created using MS-DOS, the following steps are taken to create –
1. Open MS-DOS.
2. Create a new batch file by typing the name of file as edit test.bat at the MS-DOS prompt and then type press enter.
3. Now, type the require commands:
pause
dir c:\windows
dir c:\windows\system
4. Now, save the file again.
5. Once we are back at the MS-DOS prompt(C:\), type: test and press enter. (This will execute the test.bat file and
begin running the file. Because the first line is pause, we will first be prompted to press a key. Once we press a key
the batch file will run line-by-line; in this case, listing the files in the windows and windows\system directories
occurs.)
NB : Some versions of MS-DOS and bootable diskettes may not have the edit command; if this the case, we would
either need to obtain the edit.com file to access this file or use the copy con command to create a new file.
o Using MS-Windows:
 A Windows user can use any simple text editor, such as Notepad, to create/save batch files with file extension .bat.
For this, we should follow the below steps –
1. Open Notepad.
2. Once notepad is open, type the commands in the file
@echo off
echo Batch file is started executing
pause
dir c:\windows
3. Save the file as “test.bat”, and choose “Save as type” option, as “All files”, otherwise it will save as a text file. Once
all of this has been done click the Save button and exit notepad.
4. Now, to run the batch file, by double-clicking on it or run the file like any other program. Once the batch file has
completed running it will close the window automatically.
NB: Here, @ symbol avoids echo back the text after the at symbol. This most commonly used as @ECHO OFF to
prevent any of the commands in the batch file from being displayed, just the information needed.
In batch file, CALL statement is used to run another batch file within a batch file. When the batch file that is called is
completed, the remainder of the original batch file command is completed. And if the called batch file does not
exist it will give an error message.
Chdir/Cd Command :
 This command is used to change/switch and display the current directory.
 Example:
o CD directory_name command is used to move to the new directory ahead from current working directory.
o CD.. command is used to move to the one directory back in one go (i.e., in parent/root directory) from current
working directory.
o CD/ command is used to move to the beginning or first directory back (i.e., in root directory) from current working
directory in one go.
o cd /d command is used to switch from one drive to another drive in one go such as c:\cd / e:\new folder5 to move
from c drive to new folder5 directory of e drive in one go.
Chkdsk command :
 Chkdsk stands for Check Disk.
 This command is used to check the status of the file system.
 It scans the disk drive and helps in detecting error, repair and retrieval of data from bad sectors.
 Syntax:
o C:\Chkdsk drive_name (Press Enter)
 Example:
o C:\Chkdsk d: /r (Press Enter)
o C:\Chkdsk d: /f (Press Enter)
o C:\Chkdsk *.* (Press Enter)
Cls command :
 This command is used to clear/clean the complete previous contents of the screen and leave only a prompt.
 Syntax & Example:
C:\ cls (Press enter)
Copy Command :
 This command is used to copy a complete file from one location to another.
 Syntax:
C:\ copy source_file_name destination (press enter)
 Example:
C:\ copy file1.txt d:\new folder (press enter)
C:\ copy *.txt f:\new folder1 (press enter)
Copy Con command :
 Copy con command is used to write/create a new or fresh file with certain name in the current/working directory.
 After the finishing of new file creation, CTRL+ Z button is pressed/required to save & exit from the created file
successfully to come again at DOS prompt.
 This command actually copies the contents from the console and writes into a file.
 This command does not edit the created file.
 Syntax :
C:\ Copy Con Filename (Press enter)
 Example
C:\ Copy Con File1.txt (Press enter)
——–
——–
———
Ctrl+Z (to save & exit)
Date Command :
 The date command can be used to display the current date of the system and prompt for a new one. If no date is
entered, the current date will be kept.
 This command is also used to change the date to an alternate date.
 C:\ date (Press enter)
 C:\>date
The current date is: 30-12-2022
Enter the new date: (dd-mm-yy)
Dir Command :
 This command is used to display all the non-hidden files & sub-directories present/stored in that current/working
directory.
 In another words, this command is used to view the contents of a directory (directory list=files & directories).
 Syntax :
C:\ dir (Press enter)
C:\dir/option Directory_name (Press enter)
 Example :
(i) C:\ dir (Press enter) [Display all the non-hidden files & sub-directories only from C drive/directory.]
(ii) D:\ dir (Press enter) [Display all the non-hidden files & sub-directories only from D drive/directory.]
(iii) C:\ New Folder\New Folder1\dir (Press enter) [Display all the non-hidden files & sub-directories only from New
Folder1 directory.]
(iv) C:\ dir New Folder (Press enter) [Display all the non-hidden files & sub-directories only from New Folder
directory of C drive.]
(v) C:\dir *.exe = To display or list all the non-hidden executables files from C drive.
(vi) C:\dir *.txt *.docx = To display or list all the .txt and .docx extension files from C drive.
 There are several options used with dir command to display the contents according to the need. These are –
o dir/a = Used to display all the hidden and non-hidden files & directories from that current/working directory.
o dir/ah = Used to display all the hidden files & directories only from that current/working directory.
o dir/a-d = Used to display all the files only from that current/working directory.
o dir/ad = Used to display all the directories only from that current/ working directory.
o dir/a/s = Used to display all the directories with files and sub-directories from that current/working directory.
o dir ra*.* = Used to display all the files & directories starting with ra alphabets having any extension name from that
current/working directory.
o dir /s = List the files in the directory that we are in and all sub directories after that directory.
o dir /p = List all the files’ contents page wise.
o dir /w = List the file and directory related information width wise/horizontally.
o dir /s /w /p = List all the files and directories in the current directory and the sub directories after that, in wide
format and one page at a time.
o dir /on = List the files in alphabetical order by the names of the files.
o dir /o-n = List the files in reverse alphabetical order by the names of the files.
o dir \ /s |find “i” |more = To list all directories on the hard drive, one screen page at a time, and see the number of
files in each directory and the amount of space each occupies.
Del (Erase) command:
 Del command is used to remove one or more files permanently from a directory.
 Syntax:
C:\Del filename (Press Enter)
 Example:
o C:\Del File1.txt (Press Enter)
o C:\Del *.txt (Press Enter)
DelTree command:
 Deltree command is used to remove a directory along with sub-directory and files, if any, in one go, permanently.
 Syntax:
C:\Deltree Directory_name (Press Enter)
 Example:
o C:\Deltree Dir1 (Press Enter)
Echo command:
 Echo command is used to display messages as we typed or turns command-echoing on or off.
 Syntax:
o ECHO [message]
o ECHO [ON | OFF]
 Example:
o C:\>echo Welcome
Welcome
Edit command:
 Edit command allows a user to view, create, or modify the text files.
 Syntax:
o C:\Edit filename (Press Enter)
 Example:
o C:\ Edit File1.txt (Press Enter)
Exit command:
 This command is used to come out/close/exit from the DOS.
 It quits the command.com file.
 Example :
C:\ exit (Press enter)
Format command:
 This command is used to format the diskette and fixed disks drive.
 This command initializes the directory and file allocation tables.
 Syntax:
C:\ Format drive_name: (press enter)
Finger command:
 This command is used to view information about users logged onto a remote computer.
 This may include their e-mail address, full name, when last time user logged in, read their e-mail etc.
 Syntax:
C:\ finger -l user@ localhost (Press enter)
Help command:
 Help command is used to give the information about the given keyword from a MS-DOS prompt.
 Syntax:
o C:\ keyword -help
or

o C:\keyword /?
 Example:
o C:\dir -help
or
C:\dir /? [Gives the full detail about dir command]
o C:\help dir (Press enter)
o C:\help dir (Press enter)
o C:\help date (Press enter)
o C:\date /? (Press enter)
Hostname command:
 Hostname command is used to display the name of current Host.
 Syntax & Example:
o C:\ hostname (Press enter)
Ipconfig command:
 ipconfig command is used verify a network connection or view network settings.
 Syntax & Example:
o C:\ ipconfig (Press enter)
o C:\ ipconfig /all (Press enter)
Mkdir or MD Command :
 This command is used to create a new & blank directory in the current working directory with unique name.
 Syntax:
C:\ mkdir directory_name(Press enter)
C:\ md directory_name(Press enter)
 Example :
C:\ mkdir India (Press enter)
C:\ md India (Press enter)
More Command :
 More command is used to display information or file contents to be displayed one page at a time.
 Example:
o C:\dir | more (Press enter)
o C:\file1.txt | more (Press enter)
Move Command :
 This command is used to cut/move a complete file from one location to another.
 This command is also used in renaming the files, sub-directories and directories.
 Syntax:
o C:\ move source_file_name destination (press enter)
o C:\ move old_file_name new_file_name (press enter)
 Example:
C:\ move file1.txt d:\new folder (press enter)
C:\ move *.txt f:\new folder1 (press enter)
Net Command :
 Net command is used to manage, set, view and determine network settings.
 Example:
o C:\net view (Press enter)
o C:\net config (Press enter)
Netstat Command :
 Netstat command is used to display the TCP/IP network protocols statistics and information.
 Example:
o C:\netstat (Press enter)
o C:\netstat -a (Press enter)
Ping Command :
 Ping command is used to determine whether the network is able to communicate with the network or not.
 Syntax:
o C:\ping IP_address/web_address (Press enter)
Prompt Command :
 Prompt command is used to change the MS-DOS prompt letter.
 Syntax:
o C:\prompt normal_text (Press Enter)
 Example:
o C:\prompt raj (Press Enter)
o raj_
 Some special characters are not used as prompt using normal characters rather it is used specifically such as for –
o equal sign(=) use $Q.
o dollar sign ($) use $$
o Current time use $T
o Current date use $D
o Current drive use $N
o Pipe symbol (|) use $B
o Greater than symbol (>) use $G
o Smaller than symbol (<) use $&
 Type PROMPT without parameters to reset the default prompt again.
RM command:
 Remove command is used to remove files permanently from a directory.
 This command works similar as Del/Erase command.
 Syntax:
C:\rm filename (Press Enter)
 Example:
o C:\rm File1.txt (Press Enter)
o C:\rm *.txt (Press Enter)
Rmdir/RD Command :
 This command is used to remove a blank directory from the root/parent/current working directory.
 Syntax:
C:\ rd directory_name(Press enter)
 Example:
C:\ rd folder1(Press enter)
Ren/Rename Command :
 Ren command is used to rename files and directories from the original name to a new name.
 Unlike the move command, this command cannot be used to rename sub-directories or rename file across drivers
or cannot specify a new drive etc.
 Syntax:
o C:\ren directory_name or File_name (Press enter)
 Example:
 C:\ ren raj raj1 (press enter)
 C:\ ren *.txt *.bak (press enter)
 C:\ ren file1.txt file2.txt (press enter)
Sfc Command :
 Sfc command scans all protected system files and replaces incorrect versions with correct Microsoft versions.
 This is a great command to run when we are running into an issue that is difficult to troubleshoot.
 Syntax:
o C:\ sfc (press enter)
 Example:
o C:\ sfc (press enter)
o C:\ sfc /SCANNOW (press enter) [Scans all protected system files immediately.]
o C:\ sfc /SCANONCE (press enter)[Scans all protected system files once at the next boot.]
o C:\ sfc /SCANBOOT( press enter) [Scans all protected system files at every boot.]
Systeminfo Command :
 This command displays the complete system information for installed OS and network hardware used in our
computer.
 Syntax & Example:
o C:\ Systeminfo (press enter)
Time Command :
 Time command is used to allow the user to view and edit the computer’s time.
 Syntax:
o C:\time
 Example:
o C:\time (press enter)
The current time is: 11:12:49.96
Enter the new time:
Title Command :
 Title command enables a user to change the title of their MS-DOS window i.e., sets the window title for the
command prompt window.
 Syntax:
o C:\Title String (press enter)
 Example:
o C:\ Title Window DOS (press enter)
Tree Command :
 Tree command is used to allow the user to view a listing of files and folders in an easy-to-read listing mode.
 It usually lists in tree form of the current drive files and folders.
 To stop the Tree view in the middle of the screen, press Ctrl+C.
 Syntax:
o C:\Tree Drive_letter (press enter)
 Example:
o C:\Tree (press enter)
o D:\Tree (press enter)
Type Command :
 Type command allows the user to see the contents detail of a file.
 Syntax:
o C:\Type filename (press enter)
 Example:
o C:\Type file1.txt (press enter)
o C:\Type D:\file2.txt (press enter)
Ver Command :
 Ver command is used to displays the version of MS-DOS or if running Windows 95 or above the version of
Windows.
 Syntax:
o C:\ver (press enter)
 Example:
o C:\ver (press enter)
Microsoft Windows [Version 10.0.17763.3770]
Vol Command :
 Vol Command is used to display the volume information about the designated logical drive.
 Syntax:
o C:\vol (press enter)
 Example:
o C:\vol (press enter)
Volume in drive C is WIN 10 OS NEW
Volume Serial Number is K2E7-X516
Xcopy Command :
 Xcopy Command is used to copy one or more files and directories including sub-directories from one location to
another.
 Syntax:
o C:\Xcopy sourcefile destinationfile (press enter)
 Example:
o C:\Xcopy c:\dirname1 d:\ (press enter)
MS DOS File System
 The booting process of DOS involves three main system files of DOS into memory. These files are IO.SYS,
MSDOS.SYS and COMMAND.COM.
 The operating files of MS DOS are broadly categorized into –
o System files
o Command-line Interpreter/Shell file
o User Configuration files
System files
 System files are high priority files performing system tasks.
 System files may be a plain text file or binary(bin) files.
 There is no way to open a .sys file. It’s a driver file that is processed by an OS automatically.
IO.SYS (or IBMBIO.COM) file:

o It was an essential part of MS-DOS and Windows 9x systems but is not used in newer versions of Windows.
o IO. SYS is an Input- Output System files.
o IO. SYS is a hidden, executable, binary file which processes instructions when the operating system is booted.
MSDOS.SYS (or IBMDOS.COM) file:

o This file contains the DOS kernel which is the main components of DOS OS.
o This file manages the hardware, device drivers, file & directory management, memory & program management.
Command-line Interpreter/Shell
 Command COM file :
o COMMAND.COM file is responsible for user’s command (Interactive mode) and batch files (Batch mode)
interpreter. Hence, this file is called the default command line interpreter for MS-DOS, Windows 95, Windows 98
and Windows Me OS.
o This file uses the DOS API to communicate with the disk operating system.
o Internal commands reside in the COMMAND.COM file as binary file.
o It is also called MS DOS Prompt.
User Configuration files
 CONFIG.SYS File:
o CONFIG.SYS means Configuration System file.
o It is a text file that contains commands and instructions (i.e. settings) to load drivers, shell, buffers etc. for a DOS
system.
o This file is also used to load programs in memory to manage memory, hardware, printer, mouse, keyboard and
other peripherals.
o It is executed during system boot.
o After executing the command of the config.sys file, the autoexec.bat file is executed.
o This is a primary or main configuration file for OS/2 and DOS OS.
o The CONFIG.SYS file is read every time when a DOS system is booted. The system then reads that file and executes
the command following it.
o Users can easily make changes in this file, if required, as per their requirements in the system by simply saving the
changes made in the CONFIG.SYS file. Since it is a text file, it can be edited it in any simple editing program.
o This file is located in the root directory of the drive; from where system is booted.
o The most common commands of the CONFIG.SYS file are:
 BUFFERS = This command is used to specify the buffer size.
 FILES = This command is used to determine the number of files that a user can open simultaneously.
 AUTOEXEC.BAT
o This is a special plain-text batch file that is executed after system boot.
o With the help of this command, we can run commands, programs and batch files automatically at the time of
startup or booting of the system, by adding them to this file.
Operating System
History :


o The first operating system used for real work was GM-NAA I/O, produced in 1956 by General
Motors’ Research division for its IBM 704.

Introduction :


 All computers need some sort of hardware platform to run the software; these platforms are called
Operating System (OS).

Definition :


 An operating system commonly called OS, is system software which acts as an interface between a
user and computer hardware. It also acts as a bridge between application programs and the
computer hardware.
 Operating system is a program that acts as an interface between user of computer and the
computer hardware.
 Operating System is the software that manages all the computers‘ resources to optimize its
performance provides common services for efficient execution of various application software and
acts as an interpreter between the hardware, application programs and the user.

Features :


o The purpose of an operating system is to provide an environment in which user can execute
program in a convenient and efficient manner.
o Operating system is an important part of almost every computer system i.e. operating system is
must in order to operate a computer. Without operating system computer is of no use.
o An operating system is essential for any computer to be useful to us.
o Examples are – Microsoft Windows, UNIX, LINUX, OS/360, OS/2 etc are some of the famous
examples of an Operating system.
o Operating system is one of the most important example of system software.
o An Operating System is one of the most important components of the computer software which is
essential to operate a computer.
o When a user or a program wants the hardware to do something, the request is always
communicated to and processed by the operating system.
o Operating system is installed in secondary memory permanently, while it’s some part are stored
permanently in read only memory during starting/loading of computer system.
o For large systems, the operating system has even greater responsibilities and powers.
o Some part of the operating system resides in random access memory and the computer begins to
execute this part of the system.
o The majority of modern home computers use some form of Microsoft’s operating systems.
o Operating systems performs basic tasks, such as recognizing input from the keyboard, sending
output to the display screen, keeping track of files and directories on the disk and controlling
peripheral devices.
o The original & initial Microsoft operating system was called DOS (Disk Operating System) though
most computers use Windows. Windows comes in various versions beginning with version 3.x then
95, 98, XP and currently Windows 7/8/10.
o A few computers use IBM’s O/S2.
o Apple’s Mac use their own operating system beginning with OS 1 though most modern Macs use
version 8.x or 9.x. Apple’s latest version is OS 10.1.x.
o Some computer professionals, Internet Service Providers (ISP) and mainframe computer users use
an operating system such as UNIX/Linux, Windows NT or 2000 or server based operating systems.
o In short, when computer is turned on, it first needs to load some main components of operating
system into RAM sometimes referred to a booting up. It checks all its components and will usually
display a message if there is a problem. It is also known as Power on Self Test (POST). Loading the
system is usually automatic. Once the system is loaded, the user can start the application or
program that he/she going to use.

Functions :


o It manages all resources of computer system.
o The operating system controls the input and output or directs the flow of information to and from
the CPU. Much of this is done automatically by the system.
o A OS controls and manages all the hardware components of a computer as well as it also controls
input and output, memory and files. In other word a OS can be seen as a manager of the system.
o It optimizes and utilizes various kinds of resources like I/O devices, Memory, CPU etc.

Examples :

(i) MS Windows Operating System (Such as Windows 10, Windows 8/8.1, Windows 7, Windows Vista,
Windows XP, Window 98, Window 95, Window 3.11/3.1, MS DOS etc.)

(ii) Apple’s Macintosh/OS X/MAC Operating System

(iii) Linux( such as Fedora, Red Hat, Debian, Ubuntu, Kali etc.)/Unix Operating System

(iv) Chrome OS

(v) BlackBerry Tablet OS

(vi) Solaris OS

(vii) Free BSD[Berkeley Software Distribution] OS

(viii) CentOS

(ix) Android
(x) iOS

Introduction

 The evolution of operating systems (OS) can be traced back to the early days of computing when the first
computers were designed for specific purposes and were operated by engineers and technicians.
 The evolution of operating systems (OS) can be traced back to the 1950s when the first mainframe
computers were developed. At that time, computer systems were very large, expensive and required
specialized operators to run them.
 During this time(the 1950s), computers were large, expensive, and used by only a few individuals or
organizations. As a result, the early operating systems were very simple and were primarily designed to
control the hardware.
 The evolution of operating systems has been driven by advances in hardware technology and the needs of
users. As technology continues to evolve, operating systems will evolve to meet new demands and provide
new features and functionality.

Generation of OS

The evolution/development of the operating system can be summarised as the generation of OS :

Discover more

computers

Science

Programming

Computer programming

Computer

1. First Generation OS:


o The first generation of operating systems was developed in the 1950s.
o This generation of OS was mainly designed for batch processing, which involved executing large
numbers of jobs without any user interaction.
o These systems were mainly used in large-scale mainframe computers.

2. Second Generation OS:


o In the 1960s, second-generation operating systems were developed.
o This generation of OS introduced the concept of time-sharing, allowing multiple users to interact
with a computer at the same time.
o The most famous example of a second-generation operating system is UNIX, which is still used
today.

3. Third Generation OS:


o The 1980s saw the emergence of third-generation operating systems.
o This generation of OS was designed to be more user-friendly and to support graphical user
interfaces (GUIs).
o Third-generation examples of OS are – Microsoft Windows and Apple Macintosh OS.

4. Fourth Generation OS:


o Fourth-generation operating systems were developed in the 1990s
o Fourth-generation operating systems are still in use today.
o These systems are designed to be highly portable and support a wide range of hardware and
software applications.
o Examples of Fourth-generation operating systems are – Windows 10, macOS, and Linux.

5. Fifth Generation OS:


o The fifth generation of operating systems is currently being developed and will focus on emerging
technologies such as artificial intelligence, machine learning, and the Internet of Things (IoT).
o These systems are expected to be highly integrated, secure, and intelligent.

Category of Evolution of OS

 The evolution of operating systems (OS) can be traced back to the 1950s when early computers were first
developed.
 Over the years, operating systems have evolved and become more advanced, with new features and
improvements being added along the way.
 The evolution category of operating systems are:

1.

1. Batch Processing Systems:


o In the early days of computing, computers were used mainly for scientific calculations, and
the operating systems were designed to run one program at a time.
o Batch processing systems were introduced in the 1950s, which allowed multiple
programs/jobs to be submitted in batches and executed sequentially.
o It was the first operating system that was designed to manage batch processing systems.

2. Time-Sharing Systems:
o In the 1960s, time-sharing operating systems were introduced, which allowed multiple
users to access/share a single computer system simultaneously through terminals.
o These systems were designed to allow users to interact with the computer in real-time,
making it possible to run interactive applications.

3. Personal Computers Systems:


o In the 1970s, the introduction of personal computers, such as the Apple II and the IBM PC
came into existence.
o These computers had their own operating systems, such as Apple DOS and MS-DOS, which
were simple command-line interfaces. This is the most famous operating system from this
era.
o In the 1970s, the development of microprocessors and the miniaturization of computer
hardware led to the development of personal computers (PCs).
4. Graphical User Interfaces (GUIs) Systems:
o In the 1980s, the first graphical user interfaces were introduced, which allowed users to
interact with the computer using icons, menus, and windows using a mouse instead of
typing commands.
o The most well-known GUIs are Apple’s Macintosh operating system and Microsoft’s
Windows operating system.

5. Networking Systems:
o The 1990s saw the widespread adoption of networking technologies, which allowed
computers to communicate with each other and share resources.
o This led to the development of client-server architectures and distributed systems where
multiple computers could share resources over a network.
o Windows NT and UNIX operating systems of this era were designed to support multiple
users and provide advanced networking capabilities.

6. Mobile Devices Systems:


o In the 2000s, the rise of mobile devices, such as Laptops, smartphones, and tablets, led to
the development of mobile operating systems, such as iOS and Android.
o These operating systems are designed for small screens and touch-based input support for
mobile-specific features such as GPS and accelerometers.

7. Cloud Computing:
o In recent years, the rise of cloud computing has led to the development of cloud-based
operating systems, which run on remote servers and provide access to applications and
data over the internet.
o Here, applications and data are hosted on remote servers rather than on local machines.
o Examples of cloud-based operating systems include Google’s Chrome OS and Microsoft’s
Windows 365.

Over time, operating systems became more complex and powerful, with the ability to support multiple
users and handle a variety of input and output devices.

Icons

 There are several small 2D or 3D graphical images scattered over the desktop are called icons.
 It represents various items found on a desktop in simpler form which is used in several work of computer.
 These Icons may also be found on the toolbars and in the menus of several computer application software
such as MS Office Suite(Microsoft Word, Microsoft Excel etc.).
 Icons are more user-friendly compare to text-based commands and hence helps even a lay person to use
computer easily.
 We can also rename an icon name by right-clicking on it.

 Types of Icons :

There are two types of Icons- (a) System Icons and (b) Shortcut Icons

Discover more
Computer

Science

Programming

computers

Computer programming

(a) System Icons:

Discover more

computers

Computer

Computer programming

Science

Programming


o Examples are – This PC, Control Panel, Recycle Bin, My Documents etc.

(b) Shortcut Icons:


o Examples are – MS Office icons, Other User’s Application icons etc.

Desktop

 Desktop is the first stable screen/background area on our computer screen, appears after soft/normal
booting process.
 We can customize/arrange our desktop in several ways. We can add background picture, background color
etc. on a desktop.
 In most modern computers, the desktop is an important part of Graphical User Interface (GUI) and is
believed that it is the gateway(Entry or Exit Place) of a computer system.
 A desktop is a place which holds many icons, files, folders for first time use.
 Some of the main components of Desktop Screen are:
o My Computer/This PC
o My Documents
o Recycle Bin
o Task Bar
My Computer/This PC


o This is one of the main icon that displays the main components of our computer.
o We can open any of the items in this window to further examine the components of our computer
by clicking on my computer icon.
o It displays different drives/disks attached with the computer.

My Documents


o It is the default space in Microsoft Windows where all the user created files are stored
automatically unless we specifically instruct the computer to save at a different specified location.
o It is a special folder where the system stores user’s files, pictures, music, download contents etc.

Recycle Bin


o In windows Operating System, Recycle Bin is a temporary folder which holds files and folders
before it is permanently deleted from the storage devices.
o The Recycle Bin only stores, files deleted from hard drives, not from removable media, such as
memory cards and pen drive/ flash drives.
o It also doesn’t store files deleted from network drives.
o We can restore the files from the recycle bin to its original deleted location automatically or we can
cut the files from recycle bin and paste it at desired location.
o It is also possible that we can bypass the recycle bin and the files deleted will be directly removed
from the computer without moving it to the recycle bin. For this we keep holding the SHIFT key and
delete the desired files. Sometimes it might happen that we need to restore the files which has
been deleted accidentally.
o We can restore the deleted files from recycle bin. For this we follow these steps : –
 Double click the icon of recycle bin on the desktop
 Choose a file which we want to restore back and right-click on it and then click restore
 To restore all the files in the recycle bin click on restore all items.

Taskbar


o The taskbar is the long horizontal bar/area at the bottom of desktop screen.
o It is used to launch and monitor running applications.
o It has four main sections:
(i) The Start button area which opens the start menu.
(ii) The Quick Launch Toolbar area which allows us to open programs quickly with a single click.
(iii) The Middle Section allows us to see the documents and programs which we have opened and
to switch between them.
(iv) The Notification Area, which includes a small system application such as clock and icons which
shows the status of certain programs and computer settings.
(A) On the basis of the operating system’s architecture, it is divided into the following categories –

Discover more

database

computers

processes

device

multiprogramming operating system

multimedia

Computer hardware

computer

operating system

Multimedia

(a) Network Operating System

(b) Distributed Operating System

(c) Multiprocessor Operating System

(B) On the basis of the use/application of the operating system, it is divided into the following
categories –

Discover more

computer system

device

Multiprogramming Operating System

database

real-time

processes

real-time operating system

Server
Real-time systems

Database

(a) Embedded Operating System

(b) Batch Operating System

(c) Real Time Operating System

(d) Time-Sharing Operating System

(e) Database Operating System

(f) Multimedia Operating System

(C) On the basis of the number of users use the operating system at a time, it is divided into the
following categories –

(a) Single User Operating System

(b) Multi-User Operating System

(D) On the basis of tasks performed at a time, the operating system is divided into the following
categories –

Discover more

Computer hardware

hardware

Multimedia

computers

Software

Process

servers

server

multimedia

software

(a) Single/Unitasking Operating System


(b) Multitasking Operating System

(E) On the basis of the use of the operating system in a computer network environment, it is divided
into the following categories –

(a) Client’s Operating System

(b) Server Operating System

(F) On the basis of the function performed by an operating system individually, it is divided into the
following categories –

(a) General Purpose Operating System

(b) Special Purpose Operating System

(G) On the basis of use whether it is free/paid or source code is available or not, an operating system
is divided into the following categories –

(a) Open Source(Free to use) Operating System – Linux

(b) Paid Operating System – Rest of others

(H) On the basis of use in different types of devices/machines, the Operating system is divided into
the following categories –

(a) Desktop/PC Operating System – MS Windows, Linux, Mac OS, etc

(b) Tablet Operating System – BlackBerry Tablet OS

(c) Mobile/Smartphone Operating System – Android & iOS

(I) On the basis of the technique used by the operating system, it is divided into the following
categories –

(a) Multithreaded Operating System

(A)
(a) Network Operating System

Definition


o
 A network operating system is a collection of system software (OS) and associated/related
protocols that allow a set of autonomous computers, which are interconnected by certain
mediums in a computer network, to be used together in a coordinated, convenient and
cost-effective manner.

Features/Characteristics


o
 This operating system works in a computer network environment.
 Network operating systems focus on the use of remote services and resources existing in a
network of computer systems.
 In this operating system, there are multiple individual computers (usually called client
computers) that are connected with at least a single or more remote/server machines with
a network medium either with air or cable.
 Here, each client computer has its own same/different private operating system, memory,
processor, etc. along with a global remote system having a powerful specific operating
system.
 In this environment, each user normally works on his/her own client system.
 In this environment, users are typically aware of where/ which system, each of their files is
kept and must move files from one system to another with explicit file transfer commands
with the help of a remote machine.
 The system/environment has little or no fault tolerance i.e. if 10% of the personal
computers crash, only 10% of the users are out of business.

Advantages


o
 In this environment, users can access the various resources of the network hosts.
 It provides, controlling access to particular resources to authorized users.
 The use of remote resources by the users appears to be identical to the use of local
resources.
 It provides up-to-the-minute network documentation online.

(b) Distributed Operating System

Definition


o
 Distributed operating systems are operating systems for a network of autonomous
computers connected by a communication network.

Features


o
 A distributed operating system controls and manages the hardware and software resources
of a distributed system such that its users view the entire system as a powerful monolithic
computer system.
 When a program is executed in a distributed system, the user is not aware of where the
program is executed or of the location of the resources accessed.
 Distributed operating systems focus on the effective utilization of resources in distributed
computing environments.
 Users have unique IDs in a distributed system.
 Distributed systems today cover a wide spectrum of computer hardware, software, and
topological configurations; resource-sharing services range from offline access to real-time
access and topologies vary from locally distributed to geographically distributed.
 Examples – LOCUS, etc.

Structure


o
 A distributed operating system consists of similar to a traditional operating system, viz.,
process synchronization, deadlocks, process scheduling, file systems, interprocess
communication, memory and buffer management, failure recovery, etc.
 They lack both shared memory and a physical global clock, and unpredictable
communication delays make the design of distributed operating systems much more
difficult.

Advantages


o
 Cost-effectiveness in both computations and resources.
 Resource sharing
 Resource sharing is the main motivation for distributed systems.
 The nature of the distribution and sharing of resources in a distributed system has
changed due to advances in networking technology.
 Reliability
 Reliability is the availability of a resource despite failures in a system. A distributed
environment enhanced the availability of resources through the Operating System,
redundancy of resources, and communication paths. For example, the availability
of a disk resource can be increased by having two or more disks located at different
sites in the system. If one disk is unavailable due to a disk or site failure, a program
can use some
other disk. The availability of a data resource, e.g., a file, can be similarly enhanced
by keeping copies of the file at various sites in the system.
 Communication
 Communication between users at different locations is greatly facilitated by using a
distributed system easily. Communication continued even when users migrate to
different sites of a system.
 Incremental growth
 Distributed systems are capable of incremental growth, i.e., It is the capabilities of
a system (mainly its processing power) can be enhanced at a price proportional to
the nature and size of the enhancement.

(c) Multiprocessor Operating System

Definition


o
 A multiprocessor operating system is an operating system that can manage and distribute
workload across multiple processors (also known as CPUs or cores) in a computer system.
This allows multiple tasks to be executed simultaneously, which can significantly improve
system performance and efficiency.
 A multiprocessor operating system is a type of operating system that is designed to work
with computer systems that have multiple processors or CPUs (Central Processing Units).

Features


o
 A typical multiprocessor system consists of a set of processors that share a set of physical
memory blocks over an interconnection network.
 A user is not aware of the presence of multiple processors and their interconnection
network in a multiprocessor system.
 The main goal of a multiprocessor operating system is to distribute the workload between
different processors in an efficient and balanced manner, thereby improving the overall
system performance.
1. Task scheduling: The operating system must be able to assign tasks to different
processors and ensure that each processor is being utilized efficiently.
2. Memory management: The operating system must be able to manage memory
access between multiple processors and ensure that there are no conflicts or data
corruption.
3. Inter-processor communication: The operating system must provide a mechanism
for communication between different processors, allowing them to share data and
synchronize their operations.
4. Load balancing: The operating system must be able to balance the workload
between different processors to ensure that each processor is working at optimal
capacity.
5. Scalability: The operating system must be scalable, allowing for the addition of
more processors as the system grows in size.
 Examples of multiprocessor operating systems include Linux, Unix, Windows Server, and
macOS Server.
 These operating systems are designed to work with multi-core processors, which are
processors that contain multiple processing cores on a single chip.
 In a multiprocessor system, the operating system must manage the allocation of system
resources such as memory, input/output devices, and processing power among the
processors. It must also ensure that tasks are executed in a coordinated and efficient
manner, without interference or conflicts between them.
 One of the key challenges/disadvantages is designing of a multiprocessor operating system.
This requires careful synchronization and coordination mechanisms, such as locks and
semaphores, to ensure that only one processor can access a shared resource at any given
time.

Another challenge is load balancing, which involves distributing the workload


evenly across all processors to ensure that none are idle while others are overloaded.
Load balancing algorithms can be used to dynamically adjust the distribution of
workload based on system conditions and performance metrics.

Structure


o
 The design of multiprocessor operating systems is the same as in a traditional operating
system. But process synchronization, task scheduling, memory management, and
protection and security become more complex because the main memory is shared by
many physical processors.

Function


o
 A multiprocessor operating system controls and manages the hardware and software
resources such that users view the entire system as a powerful uni-processor system.

Types

There are many types of multiprocessor systems:-

(I)

(a)Loosely Coupled Multiprocessor System


o


 A loosely coupled multiprocessor system is a type of computer system in
which multiple processors or computers work together to perform a task,
but they operate independently and are not tightly interconnected.
 In other words, the processors in a loosely coupled system do not share a
memory or communicate with each other in real time.
 A loosely coupled multiprocessor system is a type of computer architecture
where multiple processors are interconnected to work together as a whole
in a distributed manner.
 Each processor in a loosely coupled system has its own memory and can
execute tasks independently.
 When multiple processors need to work together on a task, they
communicate through a network or other communication mechanism,
such as message passing or shared files. This allows the processors to
operate independently and work on different tasks simultaneously,
without interfering with each other.
 A loosely coupled multiprocessor system is typically used for tasks that can
be divided into smaller subtasks that can be executed independently by
different processors.
 Loosely coupled systems are more scalable and flexible than tightly
coupled systems.
 They are often used in applications that require a high degree of
parallelism and can tolerate some latency in communication between
processors.
 Examples of loosely coupled multiprocessor systems include clusters of
computers connected by a network, and multi-core processors within a
single computer.
 These systems can be used for a variety of applications such as scientific
simulations, data processing, and web serving.

(b)Tightly Coupled Multiprocessor System


o


 A tightly coupled multiprocessor system(TCMP) is a computer system or
architecture that has multiple processors that share a common memory
and are closely/tightly interconnected (such that they can rapidly exchange
data and synchronize their activities), allowing them to work together as a
single system.
 In a tightly coupled multiprocessor system, the processors can access and
modify the shared memory concurrently, which enables parallel processing
and improves system performance.
 In a tightly coupled multiprocessor system, the processors communicate
with each other through shared memory, message passing, or a
combination of both.
 One example of a tightly coupled multiprocessor system is a symmetric
multiprocessing (SMP) system, where each processor has equal access to
the system’s resources and can perform any task assigned to it.
 Tightly coupled multiprocessor systems are commonly used in high-
performance computing, scientific simulations, and data processing
applications.
 Overall, tightly coupled multiprocessor systems offer advantages in terms
of performance and scalability but also require careful design to ensure
proper synchronization, load balancing, and fault tolerance.
 One advantage of a TCMP is that it can achieve higher performance than a
single-processor system since the workload can be divided among multiple
processors.
 The disadvantage of this system is its design and programming which can
be complex since the processors must communicate effectively and
coordinate their activities to avoid conflicts and ensure the consistency of
data. Also, TCMPs can be more expensive to build and maintain than single
processor systems, due to the need for specialized hardware and software.
 TCMPs are widely used in high-performance computing environments,
such as supercomputers and data centers, where the ability to process
large amounts of data quickly is essential.

(II)

(a)Homogeneous Multiprocessor System


o


 A homogeneous multiprocessor system is a computer system or
architecture that has multiple identical/same-type processors or CPUs, that
share a common memory and are interconnected by a bus or network or
connected together as a single shared-memory architecture.
 In this system, all the processors have the same access capabilities to
memory and other system resources, and they are all capable of executing
the same set of instructions or same tasks.
 The main advantage of a homogeneous multiprocessor system is that it
allows for parallel processing of tasks, which can significantly improve
system performance. This is because each processor can work on a
separate task simultaneously.
 The goal of this system is to achieve maximum performance by dividing a
task into smaller parts that can be executed simultaneously. The
processors work together to process the task, which results in faster
execution times.
 Homogeneous multiprocessor systems are commonly used in high-
performance computing, scientific simulations, and large-scale data
processing applications. They are also used in embedded systems, such as
in automotive or aerospace applications, where high reliability and fault
tolerance are required.
 The disadvantage of this system is – (i) Its complex design and
programming, as it requires specialized knowledge of parallel processing
techniques and efficient memory management. (II) Additionally,
communication between processors can also be complex, as data must be
shared and coordinated between them to ensure the proper execution of
tasks. (III) Also, a homogeneous multiprocessor system is that it can be
difficult to scale. As the number of processors in the system increases, the
amount of communication between the processors can become a
bottleneck, which can limit the overall performance of the system.

(b)Heterogeneous Multiprocessor System


o


 A heterogeneous multiprocessor system (HMP) is a type of computer
system that contains multiple processing units of different types,
architectures, or capabilities, such as CPUs, GPUs, DSPs(Digital Signal
Processors), or FPGAs, that work together to execute a program or a
variety of programs.
 The use of heterogeneous processors in a single system allows for better
performance and power efficiency for a wide range of applications, as each
processor type can handle tasks that they are specialized in, and can work
together in parallel to execute tasks faster.
 In an HMP system, the processors are interconnected using a high-speed
communication network, such as a shared memory bus, a point-to-point
network, or a high-speed interconnect, to enable efficient data sharing and
task allocation.
 HMP systems are becoming more prevalent in high-performance
computing and embedded systems due to their ability to provide efficient
parallel computing capabilities while reducing power consumption.
 HMP systems require specialized hardware and software to effectively
manage and distribute tasks among the different processing units. The
software used to manage HMP systems is typically designed to take
advantage of the unique capabilities of each processor type and distribute
tasks according to their needs.
 The examples/use/applications of HMP systems are – scientific
simulations, machine learning, and video processing, among others. HMP
systems are commonly used in applications that require high-performance
computing, such as scientific simulations, machine learning, and video
processing.
 The main advantage of an HMP system is its ability to leverage the
strengths of different processor architectures to achieve high performance
and energy efficiency. For example, CPUs are generally good at handling
serial tasks, GPUs(Graphics Processor Units) are well-suited for parallel
tasks, and FPGAs(field-programmable gate arrays) can be programmed for
specialized tasks with high data throughput requirements.
 Disadvantage: The designing and programming of HMP systems can be
complex and challenging, as it requires expertise in multiple processor
architectures and their associated programming models.
(III)

(a) Shared Memory Multiprocessor System


o


 A shared memory multiprocessor system is a type of computer architecture
that allows multiple processors to access a shared pool of memory.
 In this type of system, each processor has its own cache memory, but they
all share a common physical memory space.
 The benefit of a shared memory system is that it can provide high
performance and flexibility for certain types of applications that require a
lot of memory access.
 This system is used in scientific simulations, database management, and
multimedia processing.
 With a shared memory system, multiple processors can access the same
data simultaneously, which can reduce the overall processing time.
 One of the main disadvantages is that multiple processors of this system
do not try to access the same memory location at the same time, which
can lead to data corruption or inconsistencies. Another challenge with this
shared memory system is scalability,i.e., as the number of processors in a
system increases, the amount of contention for shared resources also
increases, which can lead to performance degradation. To overcome this
challenge, some shared memory systems use a hierarchical architecture
that allows for better scalability by partitioning the memory and cache into
smaller, more manageable units. Thus, this system requires careful design
and management to ensure that they operate efficiently and reliably.

(b) Distributed Memory Multiprocessor System


o


 A Distributed Memory Multiprocessor System(DMMS) is a type of parallel
computing architecture in which multiple processors are connected to each
other and have their own local memory.
 In this architecture, the system is divided into multiple nodes or
processors, each having its own local memory and processing power.
 In a DMMS, each processor has its own local memory, which is directly
accessible to that processor. However, to access data stored in another
processor’s memory, a message-passing mechanism is required. This is
because each processor has its own address space and cannot directly
access the memory of another processor.
 The communication between the nodes is achieved through a network that
connects them, and each node can access data stored in its local memory
and in the memory of other nodes in the system. The processors work
together to solve a common problem, with each processor contributing its
processing power and memory.
 They provide high performance and scalability, allowing users to process
large amounts of data and perform complex calculations in a shorter
amount of time.
 Distributed Memory Multiprocessor Systems are used in a wide range of
applications, including scientific simulations, big data analytics, and
machine learning.
 One common example of Distributed Memory Multiprocessor System is a
cluster, which is a group of computers connected to each other through a
network and working together to solve a common problem. Another
example is a supercomputer, which is a highly powerful computer
consisting of multiple processors and a large amount of memory. Some
popular DMMS systems include MPI (Message Passing Interface), OpenMP,
and OpenACC.
 The programming model for a DMMS is more complex.

(c) Uniform Memory Access (UMA) System


o


 Uniform Memory Access (UMA) is a computer memory architecture in
which the time it takes to access any location in memory is essentially the
same, regardless of the memory location or the processor accessing the
memory.
 In UMA, all processors have equal access to a shared memory pool, which
is typically implemented using a single shared bus.
 In UMA systems, all processors can access any memory location with equal
latency, which simplifies programming and makes it easier to develop
parallel algorithms. In other words, the access time to any memory
location in UMA is uniform for all processors in the system.
 In this architecture, each processor has equal access to the memory and
can execute programs concurrently.
 One of the disadvantages of this system is that the UMA system suffers
from memory contention and scalability issues as the number of
processors increases, as multiple processors may be contending for the
same memory location at the same time, leading to performance
degradation. It may also suffer from scalability issues as the number of
processors increases.
 UMA architectures are commonly used in symmetric multiprocessing
(SMP) systems, where multiple processors share a common memory and a
common bus or interconnect.
 In UMA systems, the memory access time is not dependent on the location
of the memory module or the processor accessing it. This is in contrast to
Non-Uniform Memory Access (NUMA) systems, where the access time to a
memory location may depend on the location of the processor relative to
the memory module.
 The advantage of UMA architecture is that it is simple to design and
implement, and it allows for efficient communication between processors
because they share the same memory.
 The disadvantage of the UMA system is that, as the number of processors
in the system increases, the memory bandwidth may become a bottleneck,
leading to performance degradation. Additionally, UMA systems may not
be scalable beyond a certain number of processors, making NUMA a more
suitable architecture for larger systems.
 Examples of UMA systems are multi-socket servers, high-performance
computing clusters, and some shared-memory parallel computers.

(B)
(a) Embedded Operating System

Definition


o
 Embedded Operating Systems are small OSs, designed to operate on small machines or
devices with less autonomy.
 An embedded operating system (OS) is a specialized type of operating system designed to
run on embedded systems, which are small, dedicated computer systems that perform
specific tasks or functions.

Features


o
 They are very compact and extremely efficient by design and are able to operate with a
limited amount of resources.
 Embedded operating systems are typically optimized for low-power, limited-memory, and
low-cost devices with specific hardware requirements.
 Embedded operating systems are commonly used in a wide variety of applications,
including industrial automation, automotive systems, consumer electronics, medical
devices, and more i.e., these systems are commonly used in various electronic devices such
as smartphones, digital cameras, routers, and medical equipment.
 Embedded operating systems are typically designed to be lightweight, fast, and reliable,
with a small footprint. They are usually optimized for specific hardware architectures and
are often customized to fit the requirements of the embedded system.
 They are typically tailored to the specific requirements of the application, which can
include real-time processing, low latency, and high reliability.
 Embedded systems are designed to perform specific tasks and often have limited
resources, such as memory and processing power.
 Some popular embedded operating systems are:
1. FreeRTOS(A popular real-time operating system (RTOS) that is open-source and
designed for microcontrollers.)
2. ThreadX
3. VxWorks(A real-time operating system that is commonly used in mission-critical
applications such as aerospace, defense, and medical devices.)
4. Linux Embedded(Embedded distributions such as OpenEmbedded, Yocto Project,
Minix 3, and Buildroot are designed specifically for embedded systems.)
5. Android (for mobile devices and other embedded systems)
6. Windows Embedded (Windows CE for industrial and embedded systems)


o

Advantages


o
 It makes small machines or devices operable.

(b) Batch Operating System

History


o
 In the early 1950s, General Motors Research Laboratories (GMRL) introduced the
first Single-Stream batch processing systems.
 Batch OS was very popular in the 1970s.

Introduction


o
 Early computers, before batch OS, were very expensive, due to less processor utilization.
Also, the wasted time is due to poor scheduling and setup time.
 Batch processing is the most primitive type of operating system.
 This operating system is termed “batch operating” because the input data (job) are first
collected and filtered as groups or batches of a similar type having similar needs into sets
of records and each batch is processed sequentially as a unit(group). Thus, a Batch is
defined as a group of jobs with similar needs. The batch operating system allows users to
form batches.
 Each user prepares its jobs/batch on an offline device like a punch card and submits it to
the computer operator for further processing. Now, OS keeps a number of jobs in memory
and executes them without any manual information, and jobs are processed in the order of
submission, i.e., first come first served fashion.

Definition


o
 The batch operating system is a type of earlier and comparatively less used os in which os
executes each batch sequentially, processing all jobs of a batch and considering them as a
single process.

Features


o
 The principle behind the simple batch-processing system is the use of a piece of software
known as the monitor.
 In batch OS, the user no longer has direct access to the processor. Instead, the user submits
the job on cards or tape to a computer operator, who batches the jobs together
sequentially and places the entire batch on an input device, for use by the monitor. Each
program is constructed to branch back to the monitor when it completes processing, at
which point the monitor automatically begins loading the next program.
 With a batch operating system, processor time alternates between the execution of user
programs and the execution of the monitor.
 Examples are – Payroll Systems, Transactions Processing Systems, forecasting, statistical
analysis, & large scientific number-crunching programs, etc.

Types

There are mainly two types of batch operating systems. These are:-

(i) Simple Batched System: Use the basic concept of batch during operations.

(ii) Multi-programmed batched system: Use Spooling concept during processing.

Advantages


o
 They don’t require any special or specific hardware to input data.
 Scheduling & memory management in a batch system is very simple.
 Batch operating systems load less stress on the CPU and include minimal user interaction.
 Here, batch processes are completed even in the absence of humans’ direct interaction.

Disadvantages


o
 Debugging is very difficult in batch systems.
 A user cannot interact with the batch operating system after the submission of the job or
during the processing i.e. the computer system and the user has no direct interaction.
 Computer operators must have full knowledge of batch systems.
 In a batch system, whenever an error occurs in one of the jobs of a batch then, all the
remaining jobs get affected i.e; they have to wait until the error is resolved.
 Due to turnaround delays & offline debugging, the batch is not very convenient for
program development.

(c) Real Time Operating System

Definition


o
 An OS is used in time-critical environments where data must be processed extremely
quickly in time because the output influences immediate decisions.

Features


o
 Real-time systems are used for space flights, airport traffic control, industrial processes,
sophisticated medical equipment, telephone switching, etc.
 A real-time system must be 100 percent responsive in time.
 In real-time systems, the correctness of the computations not only depends upon the
logical correctness of the computation but also upon the time at which the results are
produced.
 In this system, if the timing constraints of the system are not met, system failure is said to
have occurred.
 Real-time operating systems are especially used in environments where a large number of
events, mostly external to the computer system, must be accepted & processed in a short
time or within certain deadlines.
 A primary objective of real-time systems is to provide quick event-response times and thus
meet the scheduling deadlines. User convenience & resource utilization are of secondary
concern to real-time system designers.
 It is common for a real-time system to be expected to process bursts of thousands of
interrupts per second without missing a single event. Such requirements usually cannot be
met by multi-programming alone, and real-time operating systems usually rely on some
specific policies & techniques for doing their job. The work of Multitasking operations in
this OS is accomplished by scheduling processes for execution independently of each other.
Each process is assigned a certain level of priority that corresponds to the relative
importance of the event that it services. The processor is normally allocated to the highest-
priority process among those that are ready to execute. Higher-priority processes usually
preempt execution of the lower-priority processes. This form of scheduling called priority-
based preemptive scheduling is used by a majority of real-time systems.
 Unlike, time-sharing OS, the process population in real-time systems is fairly static, and
there is comparatively little moving of programs between primary & secondary storage. On
the other hand, processes in real-time systems tend to cooperate closely, thus
necessitating support for both separation & sharing of memory.
 The time-critical device management is one of the main characteristics of real-time
systems. In addition to providing sophisticated forms of interrupt management & I/O
buffering, real-time operating systems often provide system calls to allow user processes to
connect themselves to interrupt vectors & to service events directly. File management is
usually found only in larger installations of real-time systems.
 There are some embedded real-time systems that also exist such as an onboard
automotive controller, which may not even have any secondary storage, to fulfill the
requirements.
 The primary objective of file management in real-time systems is usually the speed of
access, rather than the efficient utilization of secondary storage
 Examples are – PSOS, VRTX, etc.

(d) Time-Sharing Operating System

Definition


o

 A time-sharing operating system (OS) is an operating system that allows multiple


users to access a computer system at the same time.

Features


o
 In this, OS divides the computer’s resources such as CPU time, memory, and storage among
the users or applications that are running simultaneously.
 These operating systems provide various tools and features that allow users to manage
their resources and applications effectively, such as process scheduling, file sharing, and
network management.
 In a time-sharing system, each user has a terminal or computer connected to the main
computer, and the OS allocates a small amount of CPU time to each user in a round-robin
fashion.
 This OS allows multiple users to use the computer simultaneously and interact with it in
real-time as if they were the only user.
 Time-sharing OSs are particularly useful in situations where many users need access to a
single computer, such as in universities, research labs, or business environments.
 They also facilitate collaborative work and allow users to share data and resources.
 Examples of time-sharing OSs include Unix, Linux, and Windows Server.
 Most time-sharing systems use time-slicing scheduling.
 Time-sharing is a popular representative of multi-programmed, multi-user systems.
 The mode of operation in this OS generally provides a quick response time to interactive
programs.
 In addition to general program-development environments, many large computer-aided
design & text-processing systems belong to this category.
 Examples are – Multics, etc.


o

(e) Database Operating System

Definition


o
 A database operating system (DBOS) is a specialized type of operating system that is
specifically designed to manage the database and control access to a database.

Features


o
 The primary function of a DBOS is to ensure the efficient and secure management of the
database.
 It also provides tools for users to manipulate data and perform queries.
 It provides an interface between the user and the database management system (DBMS)
and is responsible for performing tasks such as file management, memory management,
and access control.
 A database operating system plays a critical role in the efficient and reliable management
of data in large-scale enterprise environments.
 A DBOS also provides features such as transaction management, concurrency control, and
backup and recovery. These features ensure the reliability and availability of the database
even in the face of hardware failures, power outages, or other disruptions.
 The choice of a particular DBOS depends on the specific needs and requirements of an
organization or application.
 A DBOS provides a layer of software between the database applications and the hardware.
 DBOS is designed to handle large amounts of data and to provide efficient access to that
data.
 It includes features such as concurrency control, backup and recovery, security, and query
optimization.
 It also provides a set of tools for managing the database, such as utilities for loading data
into the database, monitoring database activity, and tuning database performance.
 These systems are widely used in many enterprise environments to support mission-critical
applications such as e-commerce, customer relationship management, and financial
transactions.

Examples

o
 Some examples of database operating systems include Oracle, Solaris, IBM DB2, MySql,
PostgreSQL, and Microsoft SQL Server. These database packages perform several complex
specialized operations like operating systems such as data storage, retrieval, concurrency
control, backup and recovery, partitioning, clustering, advanced data compression,
encryption, integration with other database products, and query optimization.
 It offers features like data warehousing, data mining, and analysis services.
 It offers features like replication, high availability, and support for multiple storage engines.
 It is also widely used for mission-critical applications that require high availability,
scalability, and performance.

(f) Multimedia Operating System

Definition


o
 A multimedia operating system is a type of operating system that is specifically designed to
handle complex multimedia tasks such as audio, video, graphics, and animation.

Features


o
 These tasks require a significant amount of processing power and memory, as well as
specialized software and hardware components such as sound cards and video cards.
 Multimedia operating systems typically provide features such as:

1.
1.
1.
1. Support for various multimedia formats and codecs.
2. High-performance multimedia playback and recording capabilities.
3. Advanced graphics and animation rendering capabilities.
4. Audio and video editing tools.
5. Network streaming and sharing features.


o
 Examples of multimedia operating systems include Windows Media Center, Mac OS X,
Android, and Linux distributions such as Ubuntu Studio and AV Linux. These operating
systems are often used by professionals in the media and entertainment industries, as well
as by home users who want to create or consume multimedia content on their computers.
(C)
(a) Single User Operating System

Definition


o
 A single-user operating system is a type of operating system designed to be used by only
one user at a time.

Features


o
 This OS is designed to work on personal computers and does not require complex
configurations or a network connection.
 The single-user operating system provides a single GUI interaction interface for the user to
interact with the computer hardware and other applications.
 Single-user operating systems typically provide features such as file management, security,
and system updates.
 This OS also supports a wide range of software applications, including productivity tools,
multimedia applications, and games.
 Single-user operating systems are popular among individual users who require a simple and
intuitive interface to perform everyday tasks on their personal computers.
 This type of operating system is typically found on personal computers and workstations,
where a single user interacts with the system using a keyboard, mouse, and display.
 Single-user operating systems are designed to provide a user-friendly interface that allows
users to easily navigate and control the system.
 These operating systems are designed to provide a wide range of functionality to individual
users, including web browsing, multimedia playback, document editing, and gaming.
 Some popular examples of single-user operating systems are Microsoft Windows, Apple
macOS, and Linux distributions like Ubuntu and Fedora.

(b) Multi-User Operating System

Introduction


o
 Multi-user os is also called Multi-access OS.

Definition


o
 Multi-user operating system is a powerful OS that supports or handles multiple users’ work
at a time.
 Multi-access operating systems allow simultaneous access to a computer system through
two or more terminals.

Features


o
 Multi-user operating systems provide facilities for the maintenance of individual user
environments & therefore require user accounting.
 An example of a Multi-user OS is (a dedicated transaction processing system, such as) an
airline or railway ticket reservation system, that supports hundreds of active terminals
under the control of a single program.

(D)
(a) Uni/Single Tasking Operating System

History


o
 These operating systems were prevalent in early computer systems, where the
computational resources were limited, and there was a need to optimize system
performance.
 “Uni Tasking” is a term that refers to an operating system that only allows a single task to
run at a time.
 While uni-tasking systems were common in the early days of computing, modern operating
systems are typically multi-tasking, meaning they can run multiple processes or tasks
concurrently.

Definition


o
 Uni-tasking operating systems are those that allow only one task to be executed at a time.

Features


o
 In a uni-tasking operating system, the entire system’s resources are dedicated to executing
a single task, which makes the system more efficient.
 However, this system cannot handle multiple tasks simultaneously, which can be a
significant disadvantage in modern computer systems.
 Uni-tasking operating systems may still be used in specialized systems, such as embedded
systems, where the focus is on executing a single task efficiently and reliably. However, for
most general-purpose computing tasks, multi-tasking operating systems are the best ones.
 In such a system, the CPU (central processing unit) is dedicated to executing a single
process or task, and no other tasks can be executed until the current task is completed or
interrupted.
 While uni-tasking systems have the advantage of simplicity and predictable behavior, they
may not be suitable for modern computing environments that require more complex and
demanding workloads.
 One of the best examples of Uni tasking OS is MS-DOS.

(b) Multitasking Operating System

Introduction


o
 The terms multitasking & multiprocessing are often used interchangeably, although in
multiprocessing more than one CPU is involved whereas in multitasking only one CPU is
involved, it switches from one program to another so quickly that it gives the appearance
of executing all of the programs at the same time.

Definition


o
 Multitasking OS is a type of OS that allows more than one program to run concurrently.
This ability to execute more than one task at the same time, a task being a program is
called multitasking.

Features


o
 A multitasking OS is distinguished from others by its ability to support the concurrent
execution of two or more active processes.
 Multitasking is usually implemented by maintaining the code & data of several processes in
memory simultaneously.
 There are two basic types of multitasking: –
(i) preemptive multitasking (ii) cooperative multitasking

(i) In preemptive multitasking, the OS parcels out CPU time slices to each program. OS/2, Windows 95,
Windows NT, & UNIX are examples of preemptive multitasking.

(ii) In cooperative multitasking, each program can control the


CPU as long as it needs it. If a program is not using the CPU, however, it can allow another program to use
it temporarily. Microsoft Windows 3.x & the MultiFinder use cooperative multitasking.
(c) Multiprogramming Operating System(MPOS)

Definition


o
 A multiprogramming operating system permits multiple programs to be loaded into
memory & execute the programs concurrently/at the same time.
 Multiprogramming is a technique used in operating systems to allow multiple programs to
run simultaneously on a computer system.

Features


o
 MPOS enables a computer to run more than one program concurrently, which can increase
the overall throughput, efficiency, and utilization of the system’s resources.
 In a multiprogramming operating system, the CPU is shared among multiple programs
through a technique called time-sharing. The operating system assigns a slice of time to
each program, allowing it to execute a few instructions before switching to another
program. This process continues in a round-robin fashion until all programs have
completed their execution.
 Multiprogramming operating systems can also take advantage of features such as virtual
memory, which allows programs to use more memory than is physically available by
swapping data between the memory and the hard disk.
 A multiprogramming operating system is designed to manage the execution of multiple
programs by allowing them to share the CPU and other system resources.
 In a multiprogramming operating system, the CPU is shared among multiple programs, with
each program being allocated a certain amount of time to execute. This allows several
programs to run at the same time, improving the overall efficiency of the system.
 To manage the execution of multiple programs, the operating system must be able to
allocate and deallocate system resources such as memory, CPU time, and I/O devices. This
is typically done using a scheduler, which decides which program to execute next based on
various factors such as priority, resource availability, and time slice.
 One of the main advantages of a multiprogramming operating system is that it can improve
system utilization by allowing multiple programs to run simultaneously, which can reduce
idle time and increase throughput. However, it can also introduce complexities such as
resource contention, synchronization, and scheduling overhead, which must be managed
by the operating system.
 Examples are – Windows O/S, UNIX or Linux O/S, etc.

(E)
(a) Client’s Operating System

Definition

o
 A client operating system is an operating system that is designed/installed to run on
personal computers, and other devices used by individuals and uses services provided by a
server.

Features


o
 It is designed to be used by individual users, rather than managing server resources.
 The choice of client operating system will depend on the needs and preferences of the
user, as well as the applications and services that the user needs to access.
 A client operating system provides an interface that allows users to interact with the
computer and its applications.
 Some common examples of client operating systems are Windows, Mac OS, Linux,
Android, and iOS.

(b) Server Operating System

Definition


o
 A server operating system is a type of operating system designed to run on servers, which
are computers that provide services to other computers or devices on a network.

Features


o
 Server Operating Systems are the ones that run on the dedicated machine servers.
 Server Operating Systems allow sharing of multiple resources like hardware, files, or print
services.
 Web pages are stored on a dedicated server to handle requests and responses.
 Server operating systems are typically more robust and stable than desktop operating
systems and are designed to handle heavier workloads and manage multiple users and
applications simultaneously.
 A server operating system is an operating system that is specifically designed to operate on
server hardware and manage the resources of a server.
 This OS often includes features such as security and networking tools, virtualization
capabilities, and remote administration capabilities.
 Choosing the right server operating system depends on factors such as the type of
applications and services that will be running on the server, hardware requirements, and
user preferences.
 A server operating system is different from a desktop operating system in that it is
optimized for running server applications, providing network services, and managing data
storage.
 Examples of popular server operating systems are:- Microsoft Windows Server[to provide
features such as Active Directory, web server support, and virtualization.], macOS Server[to
provide file sharing, email server support, and VPN connectivity], Linux (such as CentOS,
Ubuntu, Red Hat, and Debian), Unix (such as Solaris, AIX, and HP-UX), FreeBSD(A Unix-like
operating system that is often used on servers, particularly for web hosting).


o

(F)
(a) Multithreaded Operating System

Introduction


o
 Threads are lightweight processes that share the same memory space and can
communicate with each other more efficiently than separate processes.

Definition


o
 A multithreaded operating system is an operating system that can handle multiple threads
of execution concurrently.
 A multithreaded operating system is a type of operating system that supports the
execution of multiple threads of execution within a single process.

Features


o
 Multithreaded OS allows different parts of a single program(thread) to run concurrently.
 In a multithreaded operating system, a single process can have multiple threads of
execution that can run simultaneously on different CPU cores or processors.
 For this OS, the programmer must carefully design the program in such a way that all the
threads can run at the same time without interfering with each other.
 In a multithreaded operating system, each thread can execute independently of the others,
allowing for improved performance and responsiveness.
 In addition to improving performance and responsiveness, multithreading also allows for
better resource utilization.
 With multiple threads of execution, an operating system can allocate resources more
efficiently, reducing the amount of time that a system spends idle or waiting for resources
to become available.
 Multithreading allows an operating system to handle multiple tasks simultaneously,
improving the overall performance and responsiveness of the system.
 Multithreaded operating systems are common in modern computing systems, including
desktop computers, servers, and mobile devices.
 The concept of multithreading allows a program to divide its work into smaller, more
manageable parts, and execute these parts concurrently. For example, in a web server, a
separate thread can be used to handle each incoming connection, allowing multiple clients
to be served simultaneously. Similarly, in a database management system, a separate
thread can be used to handle each query, improving the overall throughput of the system.
Similarly again, if a user is running a word processing application, a multithreaded
operating system can allow the user to type, while at the same time, the system can
perform background tasks such as saving the document, checking for spelling errors, and
updating the user interface.
 Examples of multithreaded operating systems are Linux, Windows, macOS, and Android.

UNIX

 UNIX operating systems are used in widely-sold workstation products from Sun Microsystems, Silicon
Graphics, IBM, and a number of other companies.
 The UNIX environment and the client/server program model were important elements in the development
of the Internet and the reshaping of computing as centered in networks rather than in individual
computers.
 Linux, a UNIX derivative available in both free software and commercial versions, is increasing in popularity
as an alternative to proprietary operating systems.
 UNIX is written in C.
 Both UNIX and C were developed by AT&T and freely distributed to government and academic institutions,
causing it to be ported to a wider variety of machine families than any other operating system. As a result,
UNIX became synonymous with open systems.
 UNIX is made up of the kernel, file system and shell (command line interface). The major shells are the
Bourne shell (original), C shell and Korn shell.
 The UNIX has more than 600 commands that manipulate data and text in every way conceivable.
 UNIX is widely used in mission critical applications for client/server and transaction processing systems.
 The multiple UNIX versions are widely used as Sun’s Solaris, Digital’s UNIX, HP’s HP-UX, IBM’s AIX and SCO’s
UnixWare.
 A large number of IBM mainframes also run UNIX applications, because the UNIX interfaces were added to
MVS and OS/390, which have obtained UNIX branding.

LINUX

Click this link for Linux details


Discover more
Computer programming

Programming

computers

Science

Computer

WINDOWS

 Windows is a personal computer operating system from Microsoft.


 Windows contains built-in networking, which allows users to share files
and applications with each other if their PC’s are connected to a network.
 In large enterprises, Windows clients are often connected to a network of UNIX and NetWare servers.
 The earlier server versions of Microsoft i.e. Windows NT and 2000 are gaining market share, providing a
Windows-only solution for both the client and server.
 Windows is the largest software company in the world, as well as the Windows industry at large, which
includes tens of thousands of software developers.

MACINTOSH

 The Macintosh (often called the Mac OS), introduced in 1984 by Apple Computer, was the first widely-sold
personal computer with a graphical user interface (GUI).
 The Mac OS was designed to provide users with a natural, intuitively understandable, and, in general, user-
friendly computer interface. This includes the mouse, the use of icons or small visual images to represent
objects or actions, the point-and-click and click-and-drag actions, and a number of window operation ideas.
 Microsoft was successful in adapting user interface concepts first made popular by the Mac in its first
Windows operating system.
 The primary disadvantage of the Mac is that there are fewer Mac applications on the market than for
Windows. However, all the fundamental applications are available, and the Macintosh is a perfectly useful
machine for almost everybody.
 The Macintosh has its own operating system, Mac OS which, in its latest version is called Mac OS X.
Originally built on Motorola’s 68000 series microprocessors.
 Mac versions today are powered by the PowerPC microprocessor, which was developed jointly by Apple,
Motorola, and IBM. While Mac users represent only about 5% of the total numbers of personal computer
users.
 Macs are highly popular and almost a cultural necessity among graphic designers and online visual artists
and the companies they work for.

Difference between DOS and Windows OS


Slno DOS Windows

Windows name due to its working principle, no specific


1. DOS stands for Disk Operating System.
form.
Slno DOS Windows

2. DOS is Single/ Uni Tasking OS. Windows is a Multi-Tasking OS.

3. DOS consumes comparatively quite low power. Windows consumes comparatively high power.

4. DOS has no support for networking. Windows OS supports networking.

5. DOS uses less memory. Windows uses comparatively high memory.

According to user point of view, DOS


Windows usages is user-friendly and is quite simple to
6. operation/usage is complex we need to remember
use due to GUI.
commands to operate DOS properly.

DOS is command line based/CUI(Character User


7. Windows is GUI(Graphical User Interface) based OS.
Interface) OS.

8. Multimedia operation is not supported in DOS. Multimedia operation is fully supported by Windows OS.

DOS commands execution is faster than Windows


9. Windows operations are comparatively slower than DOS.
operation.

DOS supports only single operation in single Windows supports single or multiple operations in
10. window/interface at a time called SDI (Single single/multiple windows/interfaces at a time called MDI
Document Interface). (Multiple Document Interface).

Difference between Deadlock and Starvation


Slno Deadlock Starvation

Deadlock is a situation in which no process/job got Starvation is a situation in which the low priority
1. blocked and no process/job proceeds i.e. they all are process/job got blocked and the high priority
inert. processes proceed.

2. Deadlock is an infinite waiting process and is uncertain. Starvation is a long waiting but certain and not infinite.

Every starvation of a process need not be deadlock


3. Every deadlock shows a starvation mechanism.
process.

In deadlock, the requested/used resource is blocked by In starvation, the requested resource is continuously
4.
the other process. be used by the higher priority processes.

Deadlock occurs when mutual exclusion, hold and wait,


It occurs due to the uncontrolled priority and resource
5. No preemption and circular wait occurs
management.
simultaneously.
Difference between Paging and Segmentation
slno Paging Segmentation

1. It is invisible to programmer. It is visible to programmer.

2. The size of pages are fixed. The size of segments are not fixed.

3. Here, procedures and data cannot be separated. Here, procedures and data can be separated.

It supports fast memory access as compared to


4. It has slower memory access as compared to paging.
segmentation.

5. Here, the type of the fragmentation is internal. Here, the type of fragmentation is external.

Here, the size of the page is determined by available Here, the size of the page is determined by the user
6.
memory. activity.

Difference between Multitasking and Multiprocessing


slno Multitasking multiprocessing

It executes multiple same or different tasks at a time It executes multiple same or different tasks at a time
1.
using a single processor. using multiple processors.

2. It contains only one CPU/Processor. It contains multiple CPUs/Processors.

3. It is comparatively more economical. It is comparatively less economical.

4. It is less efficient than multiprocessing. It is more efficient than multitasking.

5. It allows fast switching among various tasks. It allows smooth processing of multiple tasks at once.

It requires more time to execute multiple tasks as It requires less time for multiple jobs processing as
6.
compared to multiprocessing. compared to multitasking.

Difference between Process and Program


Slno Process Program

The process is an instance of computer A program is a collection of instructions that mainly performs a
1.
program that is being executed. specific task when executed by the computer.

2. A process has a shorter lifetime. A program has a longer lifetime.

A process is the running instance of the


3. The program is the executable code.
code.
Slno Process Program

A process requires resources such as


4. A program requires hard-disk resources mainly
memory, CPU, Input-Output devices.

5. It is a dynamic object. It is a static object.

What Is Open Source Software?

Open source software (OSS) is a type of software whose source code is available to the public. This means
that anyone can view, modify, and distribute the software as they see fit. OSS is an alternative to the
traditional proprietary software model, where the source code is kept secret and users are restricted in their
ability to modify or share the software.

OSS is rooted in the belief that software should be a community resource. Developers from around the
world can collaborate on OSS projects, making improvements and adding features that benefit everyone.
This collaborative model also allows for rapid innovation, as the combined efforts of many developers can
often outpace those of a single company.

However, it’s important to note that ‘open source’ doesn’t necessarily mean ‘free’. While many OSS
projects are available for free, developers can choose to charge for their software if they wish. The key
difference is that the source code must be available to users, allowing them to modify and distribute the
software as they see fit.

A Brief History of Open Source Software

The concept of open source software may seem like a new phenomenon, but its roots go back several
decades. In the early days of computing, software was often shared freely among academics and
researchers. The idea was to foster collaboration and accelerate innovation, much like the open source
movement today.

However, as the software industry began to take shape in the 1970s and 1980s, companies started to see the
value in proprietary software. They began to keep their source code secret, selling licenses to users that
allowed them to use the software but not to modify or distribute it. This shift towards proprietary software
marked a significant change in the software industry, and it was not without controversy.

In the late 1980s and early 1990s, a group of developers led by Richard Stallman began to push back
against this trend. They believed that software should be a communal resource, and they started to develop
free software that anyone could modify and distribute. This marked the beginning of the modern open
source movement, and it has been growing ever since.
Open Source vs. Closed Source Software

Closed source software (also called custom code or proprietary code) is protected, preventing unauthorized
users from using or viewing the source code. Any attempts to modify, delete, or copy closed code
components can result in legal repercussions or voiding the warranty.

In contrast, open source software allows users to copy, delete, or modify code components, keeping the
code open so that others can include this code in their program, according to the licensing granted by the
open source code creators. Let’s explore the key differences between open and closed source software.

Support

Closed source software is typically developed and maintained by a single company or organization. This
centralized development structure allows for dedicated customer support teams that can quickly address
any issues or concerns that users may encounter. Closed source software often comes with comprehensive
documentation, tutorials, and training resources to assist users in maximizing its potential.

On the other hand, open source software is developed by a community of contributors who collaborate to
improve and enhance the software. While this distributed development model fosters innovation and
creativity, it can sometimes lead to limited support options.

However, open source communities are known for their vibrant and helpful nature. Users can seek
assistance from forums, discussion groups, and online communities where experienced developers and
enthusiasts are eager to lend a helping hand. Open source software also benefits from continuous updates
and improvements driven by a diverse range of contributors.

Usability

Closed source software is often designed with a focus on user-friendliness and intuitive interfaces.
Extensive user testing and interface design considerations are conducted to ensure a smooth and seamless
user experience. Closed source software tends to have a consistent look and feel, making it easier for users
to navigate and accomplish their tasks efficiently.

Open source software, on the other hand, may have varying degrees of usability. Since it is developed by a
diverse community, usability can sometimes be a hit or miss. However, many open source projects have
made significant strides in improving their user interfaces and overall user experience. Some projects even
have dedicated teams focused on enhancing usability.

Moreover, open source software provides users with the freedom to customize and tailor the software to
their specific needs, which can greatly enhance usability for those willing to invest time and effort.

Security

Closed source software often benefits from a dedicated team of security experts who identify and patch
vulnerabilities. The proprietary nature of closed source software can make it more difficult for malicious
actors to exploit security loopholes, as the source code is not freely available for scrutiny. Additionally,
closed source software companies often prioritize security audits and regular updates to ensure that their
software remains robust against emerging threats.

Open source software involves a different approach to security. The transparency of the source code allows
a global community of developers to scrutinize it for vulnerabilities and suggest improvements. This
collaborative effort can lead to rapid identification and resolution of security issues.

Open source software communities often have a culture of sharing security best practices and collectively
addressing vulnerabilities. However, users must still exercise caution and ensure that they are using official
releases from trusted sources, and that the open source projects they are using are regularly maintained.

Cost

Closed source software is typically associated with licensing fees or subscription-based pricing models.
These costs can vary greatly depending on the complexity and intended use of the software. While closed
source software may require an upfront investment, it often comes bundled with customer support, regular
updates, and additional features.

Open source software is generally available for free. Users can download, use, and modify the software
without any licensing costs. This makes OSS an attractive option for individuals and organizations with
limited budgets. However, it is important to consider the total cost of ownership when evaluating open
source software. While the software itself may be free, there may be additional costs associated with
implementation, customization, and ongoing support.

Flexibility

Closed source software offers limited flexibility. Users are generally limited to the features and
functionalities provided by the software vendor. Customization options may be limited, and users may have
to rely on the vendor’s roadmap for future enhancements. While closed source software can often meet the
needs of a broad range of users, it may not be suitable for those seeking extensive customization or
integration capabilities.

By providing users with access to the source code, open source software allows for customization and
modification to meet specific needs. This flexibility is particularly valuable for organizations with unique
requirements or those seeking to integrate the software with existing systems and workflows. Users can
tailor the software to their precise needs, whether it involves adding new features, removing unnecessary
ones, or integrating with other software solutions.

What Are Open Source Licenses?

Open source licenses are legal agreements that specify how an OSS can be used, modified, and distributed.
These licenses are crucial for maintaining the open nature of OSS. Without them, developers could
potentially restrict how their software is used, undermining the whole concept of open source.
There are many different types of open source licenses, each with its own set of conditions and
permissions. Some licenses are very permissive, allowing users to do almost anything with the software.
Others, known collectively as ‘copyleft’ licenses, are more restrictive, placing certain limitations on how
the software can be modified or distributed. Including components with copyleft licenses in your software
can severely limit your ability to commercialize or monetize the software.

Popular Permissive Licenses

The Apache License

The Apache License is a permissive license created by the Apache Software Foundation. It allows users to
use, modify, and distribute the software, provided that they comply with the terms of the license. This
includes providing attribution to the original author and including a copy of the license in any distributions.

One of the notable features of the Apache License is its grant of a patent license. This means that
contributors automatically grant a license to their patents that would be infringed by the software. This
feature helps to protect users and developers from potential patent litigation.

MIT License

The MIT License is named after the Massachusetts Institute of Technology, where it originated. The MIT
License is simple and straightforward, allowing users to do whatever they want with the software, as long
as they provide attribution and include a copy of the license.

The MIT License does not include a patent license, which differentiates it from the Apache License.
However, its simplicity and permissiveness have made it a popular choice for many open source projects.

BSD License

The BSD License originated at the University of California, Berkeley. There are several variations of the
BSD License, but they all allow users to use, modify, and distribute the software, provided they meet
certain conditions.

These conditions usually involve providing attribution and including a copy of the license. Some versions
of the BSD License also include a non-endorsement clause, which prohibits the use of the names of the
contributors to endorse or promote products derived from the software.

Popular Copyleft Open Source Licenses

GNU General Public License (GPL)

The GNU General Public License (GPL) was created by Richard Stallman and the Free Software
Foundation, and it has been instrumental in the growth of the open source movement.
The GPL requires that any derivative works must also be licensed under the GPL. This ensures that the
software remains open and free for everyone to use, modify, and distribute. But at the same time, it
severely restricts the ability to commercialize any software based on GPL-licensed technology.
Affero GPL (AGPL)

The GNU Lesser General Public License (LGPL) is a less restrictive version of the GPL. It allows
developers to use LGPL-licensed code in proprietary software, provided that they make the source code for
the LGPL components available.
The LGPL is a popular choice for libraries and other software components that are designed to be used in a
variety of projects. It provides a balance between openness and flexibility. However, like the GPL, the
LGPL is still a copyleft license, which means that it imposes certain restrictions on how the software can
be used.

Eclipse Public License (EPL)

The Eclipse Public License (EPL) is used by the Eclipse Foundation for their widely-used Eclipse IDE,
among other projects. While the EPL is a copyleft license, it is less restrictive than the GPL. It allows
developers to use EPL-licensed code in proprietary software, without requiring that the entire software be
EPL-licensed.

Mozilla Public License (MPL)

The Mozilla Public License (MPL) is used by the Mozilla Foundation for their Firefox web browser and
other projects. The MPL is similar to the EPL in that it allows for the use of MPL-licensed code in
proprietary software.
The MPL has a unique feature called the ‘file-level copyleft’. This means that modifications to existing
MPL-licensed files must be released under the MPL, but new files can be licensed as the developer sees fit.

Business Source Licenses

The Business Source License (BSL) is a type of software license that offers a unique approach to balancing
the benefits of open source and proprietary software. It was created by MariaDB Corporation founder
Michael “Monty” Widenius. Here are some key features of the BSL:

 Time-delayed source code release: Under a BSL license, the source code of the software is eventually made
available as open source after a predetermined delay period. This period is typically a few years, after
which the software automatically converts to a standard open-source license, such as the General Public
License (GPL).
 Limited use rights initially: During the delay period, users have limited rights to use, modify, and share the
software. The license may impose certain restrictions, such as on the size of the organization that can use it
for free, or the types of uses (like non-commercial) that are permitted without a paid license.
 Commercial use: The BSL allows the original creators to monetize the software during the delay period.
Companies or individuals who wish to use the software for purposes beyond what is allowed for free under
the BSL typically need to purchase a commercial license.
 Promotion of open source ideals: After the delay period ends and the software becomes open source
under a traditional open-source license, the community benefits from access to the source code. This
delayed release mechanism promotes open source ideals while allowing the creators to derive commercial
benefits initially.
Key Use Cases for Open Source Software

Web Servers and Hosting

Open source plays an important role in the domain of web servers and hosting. The Apache HTTP Server,
one of the most prominent OSS projects, has been a cornerstone of the internet, powering a significant
portion of the web’s sites. Its success is attributed to its robustness, flexibility, and active community
support. Additionally, Nginx, another OSS web server, has gained popularity for its high performance,
scalability, and efficient handling of concurrent connections, making it an ideal choice for high-traffic
websites.

In hosting environments, open source tools like the LAMP stack (Linux, Apache, MySQL,
PHP/Python/Perl) enable businesses and developers to deploy web applications efficiently. The stack’s
components are all open source, ensuring a cohesive and cost-effective platform for web development and
hosting.

Database Management

In the realm of database management, OSS offers a range of solutions that cater to different needs, from
lightweight databases like SQLite to powerful, enterprise-grade systems like PostgreSQL and MySQL.
These open source databases provide users with the ability to handle data effectively, whether for small
personal projects or large, complex applications.

Open source databases offer high levels of customization and flexibility, allowing businesses to tailor the
database system to their specific requirements. The vibrant communities around these databases contribute
to their reliability and security, with regular updates and patches addressing emerging threats or issues.

Cloud Computing and Containerization

In cloud computing, open source technologies have been transformative. Notable examples are OpenStack
for cloud infrastructure management, Docker for containerization and Kubernetes for container
orchestration. These tools offer organizations the ability to build and manage scalable, flexible cloud
environments without being tied to proprietary solutions.

The collaborative nature of open source development accelerates innovation in the cloud computing space,
with new features and integrations being developed at a rapid pace. Furthermore, the transparency and
modifiability of open source software provide users with greater control over their cloud infrastructure.

Real-Time Operating Systems (RTOS)

Real-Time Operating Systems (RTOS) are crucial for applications requiring immediate processing and
response to external events. OSS projects like FreeRTOS and RTLinux provide the foundation for
developing real-time applications in areas such as embedded systems, automotive, and IoT devices.

These open source RTOS platforms allow developers to access and modify the source code, enabling them
to optimize and customize the operating system according to their project’s specific needs. The availability
of source code and a community of developers also helps in identifying and fixing bugs and security issues
quickly.

Learn more in the detailed guide to RTOS.

Security Tools

The open source community has contributed significantly to cybersecurity, offering a wide array of tools
for monitoring, penetration testing, and securing networks. Tools like Wireshark for network protocol
analysis, Zed Application Proxy (ZAP) for dynamic application testing, and Metasploit for security
vulnerability testing, are indispensable to security professionals.

Open source security tools benefit from the collective expertise of a global community. Additionally, these
tools can be customized to suit the unique security needs of each organization.

What Is an Open Source Software Policy?

An open source software policy is a set of rules and guidelines that govern how an organization or
individual uses and contributes to open source software. The policy outlines the practices and procedures
that need to be followed when dealing with open source software to ensure compliance with licenses,
protect intellectual property rights, and maintain the integrity of the software.

The policy also provides guidance on how to contribute to open source projects. This includes how to
submit changes, how to handle disputes, and how to acknowledge the work of others. It’s important to
remember that contributing to open source requires more than writing code. It can also involve reporting
bugs, improving documentation, and helping other users.

Keeping an open source software policy helps in managing risks associated with the use of open source
software. It ensures that the organization is aware of its responsibilities and obligations when using and
distributing open source software. A well-defined policy can also help in decision-making processes,
ensuring that the use of open source software aligns with the organization’s strategic goals.

Best Practices for Open Source Security and Compliance

Open source security is a growing concern in software development organizations, because most enterprise
software projects include thousands of open source components. Here are a few ways to ensure open
source software does not compromise the security of your applications.

Monitor for Updates

Securing open source software requires continuous monitoring for security updates. Many open-source
projects are updated regularly, and it’s crucial to keep track of these updates and apply them promptly.

Updates often contain security patches that fix known vulnerabilities in the software. Failing to apply these
patches can leave your systems exposed to potential threats. Therefore, it is essential to have a system in
place that alerts you when new updates or vulnerabilities are detected.
Implement Open Source Vulnerability Scanning

Vulnerability scanning is a proactive approach to identifying security weaknesses in your OSS. It involves
using specialized tools to scan your software for known vulnerabilities. These tools compare the
components of your software against databases of known vulnerabilities, such as the National Vulnerability
Database (NVD).

Open source vulnerability scanning helps you identify and fix vulnerabilities before they can be exploited.
Regular scanning can also help you understand your software better, allowing you to make informed
decisions about its security. New vulnerabilities are discovered regularly, so continuous scanning is
necessary to ensure your software remains secure.

Use a Binary Repository

A binary repository is a storage location where you can keep binary files, the compiled version of your
software. Using a binary repository can significantly improve the security of your open source software.

A binary repository allows you to keep track of all the versions of your software. This makes it easier to
manage updates and patches, ensuring that you are always using the latest, most secure version of your
software.

A binary repository can also help you control access to your software. You can set permissions to
determine who can access your software, preventing unauthorized access and potential security threats.

Software Composition Analysis

Software composition analysis (SCA) is a method used to identify open source components within your
software and assess their security risks. It provides a comprehensive view of your software’s composition,
allowing you to understand its security posture better.

SCA tools can identify known vulnerabilities in the open-source components of your software. They can
also check for compliance with licensing requirements, ensuring that you are not violating any open-source
licenses.

By providing a detailed view of your software’s composition, SCA can help you manage your open-source
usage effectively. It allows you to make informed decisions about the open-source components you use,
enhancing the security and compliance of your software.

Now that we’ve covered the important considerations for using open source software in your projects, let’s
review some of the world’s most popular open source software.

Implement GitOps

GitOps is an operational framework that takes DevOps practices a step further, using Git as the single
source of truth for managing infrastructure and application configurations. This approach enhances open
source security by introducing a more controlled, auditable, and automated deployment process.
When implementing GitOps, all changes to the infrastructure and application configurations are made via
Git pull requests. These changes are automatically applied to the production environment using continuous
deployment (CD) tools. This method ensures that every modification is tracked and reviewed, reducing the
risk of unauthorized changes or misconfigurations that could lead to security vulnerabilities.
GitOps minimizes the attack surface by limiting direct access to production environments. By enforcing
changes through a controlled Git workflow, it ensures that only approved and verified updates are
deployed, thereby reducing the chances of introducing vulnerabilities into your software ecosystem.

Learn more in the detailed guide to GitOps

Related product offering: Octopus Deploy | Continuous Delivery and Deployment Platform

Related technology updates:

[Blog] What is GitOps?

Top Open Source Projects: Content Management Systems


WordPress

Official project page: https://wordpress.org/


Repository: https://github.com/WordPress/WordPress
GitHub stars: 18.2K
Run it now in a free Acorn sandbox: Launch Acorn

WordPress is an open source content management system that powers approximately 40% of all websites.
It’s known for its simplicity, flexibility, and user-friendly interface. With WordPress, you can create any
type of website, from a personal blog to a full-fledged e-commerce site.

WordPress has an extensive ecosystem of plugins and themes. With thousands of options to choose from,
you can extensively customize your website. And because it’s open source, you have the freedom to
modify and extend WordPress to suit your specific needs.
Drupal

Official project page: https://www.drupal.org/


Repository: https://github.com/drupal/drupal
GitHub stars: 4K

Drupal is an open-source content management system (CMS) used to make websites and applications. It’s
flexible and customizable, allowing you to build and manage different kinds of sites—from simple blogs to
complex user communities.

One of the key strengths of Drupal is its scalability. It’s designed to handle high-traffic sites and has proven
its ability to scale in real-world scenarios at various organizations that manage large volumes of content.

The Drupal community is large and diverse, with hundreds of thousands of active contributors constantly
working on enhancing its features and performance. This active participation ensures that Drupal remains a
robust platform for web development.

Joomla
Official project page: https://www.joomla.org/
Repository: https://github.com/joomla/joomla-cms
GitHub stars: 4.4K

Joomla is another open-source CMS that empowers you to create dynamic websites and applications. It
offers a balance between ease-of-use and extensibility, making it a popular choice among both beginners
and experienced developers.

Joomla offers an application framework that allows developers to create add-ons, extending the power of
Joomla beyond a simple CMS. The Joomla community is large and active. They are committed to keeping
Joomla user-friendly, powerful, and up-to-date.

Ghost

Official project page: https://ghost.org/


Repository: https://github.com/TryGhost/Ghost
GitHub stars: 44.4K
Run it now in a free Acorn sandbox: Launch Acorn

Ghost is an open source blogging platform that’s gaining popularity for its focus on simplicity and
usability. Unlike WordPress, which has evolved into a full content management system, Ghost remains true
to its blogging roots.

Ghost is designed to make blogging as straightforward as possible. Its clean, clutter-free interface lets you
focus on your content. And while it may not have as many plugins and themes as WordPress, Ghost offers
enough customization options to make your blog distinct.
Strapi

Official project page: https://strapi.io/


Repository: https://github.com/strapi/strapi
GitHub stars: 57.4K
Run it now in a free Acorn sandbox: Launch Acorn

Strapi is an open-source headless CMS that allows developers to build, deploy, and manage content-rich
applications in a short time. It’s built on JavaScript, one of the most popular programming languages,
making it a familiar environment for many developers.

As a headless CMS, Strapi decouples the front-end and back-end development. This gives developers the
freedom to use any technology stack they prefer for the front-end, while Strapi manages the back-end.

Top Open Source Projects: Container Orchestration


Docker Containers

Official project page: https://www.docker.com/


Repository: https://github.com/docker/compose
GitHub stars: 31K
Run it now in a free Acorn sandbox: index.docker.io/tybalex/autogptjs-acorn

Docker is an open source platform that automates the deployment of applications inside software
containers. It provides an additional layer of abstraction and automation of operating-system-level
virtualization on Windows and Linux.

Docker utilizes the resource isolation features of the Linux kernel (such as cgroups and kernel namespaces)
and a union-capable file system (like OverlayFS) to allow independent containers to run within a single
Linux instance, avoiding the overhead of starting and maintaining virtual machines.

Docker can package and run an application in a loosely isolated environment called a container. This
isolation and security allow you to run many containers simultaneously on a given host. Containers are
lightweight and contain everything needed to run the application, ensuring that software runs reliably when
moved from one computing environment to another.

Learn more in the detailed guide to Docker Containers (coming soon)

Kubernetes

Official project page: https://kubernetes.io/


Repository: https://github.com/kubernetes/kubernetes
GitHub stars: 103K

Kubernetes is a portable, extensible, open source platform for managing containerized workloads and
services. It supports declarative configuration and highly flexible automation. It has a large, rapidly
growing ecosystem, with Kubernetes services, support, and tools widely available.

Kubernetes provides a platform for automating deployment, scaling, and operations of application
containers across clusters of hosts. Originally developed by Google and donated to the Cloud Native
Computing Foundation (CNCF), it offers a solution for container orchestration, increasing the scalability,
availability, and efficiency of applications.
**Learn more in these detailed guides:

 Introduction to Kubernetes
 Kubernetes architecture**

Openshift Container Platform

Official project page: https://www.redhat.com/en/technologies/cloud-computing/openshift


Repository: https://github.com/openshift/openshift-docs
GitHub stars: 698

OpenShift is a family of containerization software products developed by Red Hat. Its flagship product is
the OpenShift Container Platform—an on-premises platform as a service built around Docker containers,
which are orchestrated and managed by Kubernetes on a foundation of Red Hat Enterprise Linux.

OpenShift provides developers with an integrated development environment (IDE) for building and
deploying Docker-formatted containers, and then managing them with the open source Kubernetes
container orchestration platform. This platform has been built with enterprise requirements like security in
mind, offering automated updates and scaling.

Learn more in the detailed guide to the Openshift Container Platform

Rancher
Official project page: https://www.rancher.com/
Repository: https://github.com/rancher/rancher
GitHub stars: 21.8K

Rancher enables organizations to deploy and manage Kubernetes at scale. It’s designed to address the
operational and security challenges of managing multiple Kubernetes clusters across different
infrastructure providers.

Rancher offers a user-friendly approach to Kubernetes management. It provides a single, consistent


interface to deploy and manage all your Kubernetes clusters, regardless of where they are running.

The Rancher community helps make Kubernetes accessible to everyone. Their contributions focus on
simplifying the complexities of Kubernetes, making it easier for more organizations to adopt and benefit
from this technology.

Top Open Source Projects: Machine Learning and AI


TensorFlow

Official project page: https://www.tensorflow.org/


Repository: https://github.com/tensorflow/tensorflow
GitHub stars: 179K

TensorFlow is an open source software library for high performance numerical computation. Its flexible
architecture allows easy deployment of computation across a variety of platforms (CPUs, GPUs, TPUs),
and from desktops to clusters of servers to mobile and edge devices.

Originally developed by researchers and engineers from the Google Brain team, TensorFlow has become
popular among developers for machine learning and artificial intelligence projects. It has a broad
ecosystem of tools, libraries, and community resources that lets researchers push new experiments in
ML/AI and developers build and deploy ML/AI-powered applications.
PyTorch

Official project page: https://pytorch.org/


Repository: https://github.com/pytorch/pytorch
GitHub stars: 72.8K

PyTorch is an open source machine learning library developed by Facebook’s AI Research lab (FAIR). It
has gained popularity in the research community for its flexibility, ease of use, and dynamic computational
graph. PyTorch’s design is intuitive, particularly for those familiar with Python programming, making it a
preferred choice for both academic research and development in industrial applications.

One of the key strengths of PyTorch is its user-friendly interface. It offers a straightforward platform for
building deep learning models, allowing researchers and developers to focus more on the design aspect of
their models rather than the technical intricacies of the library. Its dynamic computational graph, where the
graph is built at runtime, offers more flexibility and ease for making changes and debugging. This feature
is particularly useful for complex models and novel architectures in research.

Official project page: https://redis.io/


Repository: https://github.com/redis/redis
GitHub stars: 62.3K
Keras

Official project page: https://keras.io/


Repository: https://github.com/keras-team/keras
GitHub stars: 60.8K

Keras is a high-level neural networks API, written in Python and capable of running on top of TensorFlow,
CNTK, or Theano. It was developed with a focus on enabling fast experimentation.

Keras is designed for human beings emphasizing usability and developer experience. Its API is intuitive
and easy to experiment with, making it approachable for newcomers while also robust enough for expert
practitioners. It provides clear and actionable feedback for user errors and has extensive documentation and
developer guides.

OpenCV

Official project page: https://opencv.org/


Repository: https://github.com/opencv/opencv
GitHub stars: 75.2K
OpenCV (Open Source Computer Vision Library) is an open-source computer vision and machine learning
software library. OpenCV was built to provide a common infrastructure for computer vision applications
and to accelerate the use of machine perception in commercial products.

The library has more than 2,500 optimized algorithms, which includes a comprehensive set of both classic
and state-of-the-art computer vision and machine learning algorithms. These algorithms can be used to
detect and recognize faces, identify objects, classify human actions in videos, track camera movements,
track moving objects, and extract 3D models of objects.

GPTScript

Official project page: https://github.com/gptscript-ai/gptscript


Repository: https://github.com/gptscript-ai/gptscript
GitHub stars: 2.4K

GPTScript is a scripting language designed to enable users to automate tasks and interact with a Large
Language Model (LLM) using OpenAI. It combines the simplicity of natural language with the power of
traditional scripting tools like Bash and Python, as well as the capability to make HTTP service calls. This
unique blend allows users to execute a wide range of tasks, from mundane automation to complex database
operations, using intuitive language commands.

The language’s primary strength lies in its natural language-based syntax, which significantly reduces the
learning curve for new users. This accessibility makes GPTScript an ideal tool for a variety of applications,
including retrieval-augmented generation (RAG), task automation, and the creation of agents and
assistants. Additionally, it can be used for data analysis and the integration of vision, image, and audio
processing tasks into scripts. Another notable feature is its ability to manage memory and construct
chatbots.
HuggingFace Transformers

Official project page: https://huggingface.co/transformers/


Repository: https://github.com/huggingface/transformers
GitHub stars: 124K

HuggingFace Transformers is a library that provides thousands of pre-trained models to perform tasks on
texts such as classification, information extraction, question answering, summarization, translation, and
text generation in over 100 languages. Its aim is to make state-of-the-art NLP easier to use for everyone.

Transformers provide a straightforward way to use models like BERT, GPT-2, T5, and others.
HuggingFace has become a go-to library for anyone working with textual data, thanks to its simplicity,
efficiency, and broad community support. Whether you’re a researcher, developer, or a company, it offers
cutting-edge capabilities with just a few lines of code.

Fast.ai
Official project page: https://www.fast.ai/
Repository: https://github.com/fastai/fastai
GitHub stars: 25.5K

Fast.ai is a deep learning library that provides high-level components aimed to enable fast experimentation
with deep neural networks. It sits on top of PyTorch and is designed to make deep learning more accessible
and easier to implement for practitioners.

Fastai’s library is structured around best practices with a focus on educational purposes, making it not just
a tool for production but also a learning platform for those new to deep learning. It automates many of the
tedious aspects of training deep learning models, making the process more intuitive and allowing
developers and researchers to move faster through their projects.

Top Open Source Projects: Databases


Redis

Official project page: https://redis.io/


Repository: https://github.com/redis/redis
GitHub stars: 62.3K

Redis, which stands for Remote Dictionary Server, is an open source, in-memory data structure store. It is
used as a database, cache, and message broker. One of the reasons for Redis’s popularity is its versatility. It
supports a wide range of data structures, including strings, hashes, lists, and sets.

Redis’s in-memory nature allows it to deliver ultra-fast read and write operations. This makes it an
appropriate choice for high-performance applications. With numerous contributors from around the world,
the Redis community is continually improving and innovating.
PostgreSQL

Official project page: https://www.postgresql.org/


Repository: https://github.com/postgres/postgres
GitHub stars: 13.6K
Run it now in a free Acorn sandbox: Launch Acorn

PostgreSQL is an open source relational database system. It is known for its robustness, scalability, and full
compliance with SQL standards. PostgreSQL supports a broad array of data types, including complex ones
like arrays and hstore (for storing key-value pairs).

One of the key features of PostgreSQL is its extensibility. You can define your own data types, operators,
and functions. This allows you to tailor the database system to your specific needs. And like Redis,
PostgreSQL has a strong community backing it, ensuring its continuous development and improvement.

MongoDB

Official project page: https://www.mongodb.com/


Repository: https://github.com/mongodb/mongo
GitHub stars: 24.7K
Run it now in a free Acorn sandbox: Launch Acorn

MongoDB is an open source NoSQL database that provides high performance, high availability, and easy
scalability. It works on the concept of collections and documents, which makes it flexible and adaptable to
real-world data.

MongoDB offers the ability to handle large amounts of data with diverse structures. It’s suitable for dealing
with big data applications and real-time analytics. MongoDB’s horizontal scaling capability ensures that as
your data grows, your database can grow with it.

MariaDB

Official project page: https://mariadb.org/


Repository: https://github.com/MariaDB/server
GitHub stars: 5K
Run it now in a free Acorn sandbox: Launch Acorn

MariaDB is an open source relational database management system that is a fork of MySQL. It was created
by the original developers of MySQL after concerns over its acquisition by Oracle Corporation. MariaDB
is designed to maintain high compatibility with MySQL, ensuring a drop-in replacement capability with
library binary parity and exact matching with MySQL APIs and commands.

MariaDB has a few features that set it apart from MySQL. It includes a variety of storage engines,
including high-performance ones like Aria, ColumnStore, and Spider. It also offers advanced replication
for scaling.
Cassandra

Official project page: https://cassandra.apache.org/


Repository: https://github.com/apache/cassandra
GitHub stars: 8.3K

Apache Cassandra is an open source distributed database system designed for managing large amounts of
data across many commodity servers, providing high availability with no single point of failure. Cassandra
offers robust support for clusters spanning multiple datacenters, with asynchronous masterless replication
allowing low latency operations for all clients.

Cassandra’s strengths revolve around its ability to handle large amounts of data, its resilient nature, and its
exceptional performance. Because it’s designed for distributed environments, it’s highly scalable and can
seamlessly grow with your data.

Related product offering: Configu: NetApp Instaclustr Data Platform | Open-Source Data Infrastructure
Platform

Related technology updates:


Cassandra vnodes: How Many Should I Use?
Apache Cassandra® Connector for Apache Spark™: 5 Tips for Success
Top Open Source Projects: Big Data
Hadoop

Official project page: https://hadoop.apache.org/


Repository: https://github.com/apache/hadoop
GitHub stars: 14K

Apache Hadoop is an open-source framework designed for distributed storage and processing of large data
sets across clusters of computers using simple programming models. It is particularly known for its ability
to handle petabytes and exabytes of data. Hadoop breaks down big data into smaller pieces to be processed
in parallel, significantly speeding up data processing.

A key feature of Hadoop is its Hadoop Distributed File System (HDFS), which allows for high throughput
access to application data and is suitable for applications with large data sets. The framework also includes
Hadoop YARN, a job scheduling and cluster resource management system, and Hadoop MapReduce, a
programming model for large-scale data processing.

Learn more in the detailed guide to Hadoop


Apache Spark

Official project page: https://spark.apache.org/


Repository: https://github.com/apache/spark
GitHub stars: 37.2K

Apache Spark is an open source, distributed, general-purpose cluster-computing framework. Initially


developed at UC Berkeley’s AMPLab, Spark provides an interface for programming entire clusters with
implicit data parallelism and fault tolerance.

Spark is known for its speed, ease of use, and general-purpose nature. It can run programs up to 100x faster
than Hadoop MapReduce in memory, or 10x faster on disk. Spark also supports a wide array of tasks,
including SQL queries, streaming data, machine learning, and graph processing.

Learn more in the detailed guides to:

 Apache Spark
 PySpark
Elasticsearch

Official project page: https://www.elastic.co/elasticsearch/


Repository: https://github.com/elastic/elasticsearch
GitHub stars: 67.3K

Elasticsearch is a highly scalable open-source search engine and analytics engine. It allows you to store,
search, and analyze big volumes of data quickly and in near real time. Elasticsearch is generally used as the
underlying engine/technology that powers applications with complex search features and requirements.

Elasticsearch uses a document-oriented approach, storing data in JSON format. This makes it easy to store,
search, and manage complex data structures. It’s built on top of the Apache Lucene library, offering a full-
text search engine with a powerful combination of features for search queries.

Elasticsearch is part of the ELK Stack (Elasticsearch, Logstash, Kibana), which is widely used for log
analysis in IT environments. This stack provides a powerful platform for searching, analyzing, and
visualizing data in real-time.

Note: In 2021 Elasticsearch transitioned from an Apache 2.0 open source license to the SSPL 1.0 license,
which is more restrictive. The software is still free and source code is available, but there are some
limitations on how it can be deployed in production.

Learn more in the detailed guide to Elasticsearch.


OpenSearch

Official project page: https://opensearch.org/


Repository: https://github.com/opensearch-project/OpenSearch
GitHub stars: 9.2K

OpenSearch is an open source search and analytics suite derived from Elasticsearch and Kibana. It provides
a scalable solution for search, observability, and data analysis across various types of datasets. OpenSearch
offers powerful full-text search capabilities, real-time data analysis, and advanced visualization tools.

One of OpenSearch’s key strengths is its flexibility and extensibility, allowing users to tailor it to their
specific needs. It supports a wide range of plugins and integrations, making it suitable for diverse use cases
such as log analytics, security monitoring, and more. The project is actively maintained by a large
community, ensuring ongoing improvements and feature additions.

Learn more in the detailed guide to OpenSearch

Kafka
Official project page: https://kafka.apache.org/
Repository: https://github.com/apache/kafka
GitHub stars: 26.3K

Apache Kafka is an open source streaming platform that provides real-time data feeds. It’s designed to
handle data streams from multiple sources and deliver them to multiple consumers. Kafka is known for its
high throughput, reliability, and replication capabilities, making it a popular choice for big data and real-
time analytics applications.

Kafka’s distributed architecture ensures that it can handle massive amounts of data. It also provides fault
tolerance, ensuring that data feeds remain up and running even in the event of a failure. Kafka’s
community is active and enthusiastic, continually contributing to its development and refinement.

Related product offering: Configu: NetApp Instaclustr Data Platform | Open-Source Data Infrastructure
Platform

Related technology update: [Blog] How to Get the Most out of Your Kafka Cluster

Splunk

Official project page: https://www.splunk.com/


Repository: https://github.com/splunk/attack_range
GitHub stars: 1.8K

Splunk is a software platform widely used for monitoring, searching, analyzing, and visualizing machine-
generated data in real time. It processes and indexes the data to make it searchable, and then enables users
to create graphs, reports, alerts, dashboards, and visualizations.

Although not entirely open source, Splunk offers a free version with limited functionality, popular in the
community for data analysis and operational intelligence. It’s particularly valued for its ability to make
sense of large amounts of unstructured data, providing insights that can drive operational performance and
business results.
Learn more in the detailed guide to Splunk Cloud

Slurm

Official project page: https://www.schedmd.com/


Repository: https://github.com/SchedMD/slurm
GitHub stars: 2.1K

Slurm (Simple Linux Utility for Resource Management) is an open source, fault-tolerant, and highly
scalable cluster management and job scheduling system for large and small Linux clusters. Slurm is used
by many of the world’s supercomputers and computer clusters to manage job scheduling.

Slurm prioritizes scalability and portability. It allocates exclusive and/or non-exclusive access to resources
(compute nodes) to users for some duration of time. It also provides a framework for starting, executing,
and monitoring work on the set of allocated nodes. Finally, it arbitrates contention for resources by
managing a queue of pending work.

Learn more in the detailed guide to Slurm


Top Open Source Projects: Other Notable Mentions
OpenTelemetry

Official project page: https://opentelemetry.io/


Repository: https://github.com/open-telemetry
GitHub stars: 4K
OpenTelemetry is an open source project that provides a set of APIs, libraries, agents, and instrumentation
to enable observability in your applications. It includes tools, APIs, and SDKs that can be used to
instrument, generate, collect, and export telemetry data (metrics, logs, and traces) for analysis to
understand your software’s performance and behavior.

OpenTelemetry provides a unified standard for telemetry data collection across various programming
languages and platforms. This makes it easier for developers to implement observability and maintain
consistency in their monitoring practices.

The project supports multiple data sources and export formats, making it adaptable to different monitoring
backends such as Prometheus, Jaeger, and Zipkin. It is backed by a large community and achieved
Graduated status in the Cloud Native Computing Foundation (CNCF).

Learn more in the detailed guide to the OpenTelemetry.

Zipkin

Official project page: https://zipkin.io/


Repository: https://github.com/openzipkin/zipkin
GitHub stars: 16.9K

Zipkin is an open source distributed tracing system that helps developers monitor and troubleshoot latency
issues in microservice architectures. It collects and visualizes trace data, allowing teams to understand the
flow of requests through their systems and identify performance bottlenecks.
Zipkin supports various data collection methods and integrates with numerous platforms, making it a
versatile tool for observing complex, distributed systems. It provides an intuitive UI for viewing traces and
includes powerful features like trace sampling and customizable data storage options. Zipkin is widely used
in the industry and is backed by a robust community of contributors.

Learn more in the detailed guide to Zipkin

Vault HashiCorp

Official project page: https://www.vaultproject.io/


Repository: https://github.com/hashicorp/vault
GitHub stars: 30.7K

Vault by HashiCorp is an open source tool designed to securely manage secrets and protect sensitive data.
It allows organizations to control access to passwords, API keys, certificates, and other secrets in a
centralized and auditable manner. Vault offers robust features like dynamic secrets, encryption as a service,
and secret leasing and revocation, making it an essential tool for managing secrets in modern infrastructure.

Vault supports a wide range of authentication methods and provides fine-grained access control through
policies. It also offers high availability, scaling to meet the needs of large organizations, and is backed by
an active community of contributors and users.

Learn more in the detailed guide to Vault HashiCorp

Related product offering: Configu: Configuration Management Platform | Configuration-as-Code


Automation for Secure Collaboration

Related technology update: [Webinar] Secure CD at scale with Octopus Deploy and HashiCorp Vault

Definition

Open source software (OSS) is software that is distributed with its source code, making it available for use,
modification, and distribution with its original rights. Source code is the part of software that most
computer users don’t ever see; it’s the code computer programmers manipulate to control how a program
or application behaves. Programmers who have access to source code can change a program by adding to
it, changing it, or fixing parts of it that aren’t working properly. OSS typically includes a license that
allows programmers to modify the software to best fit their needs and control how the software can be
distributed.
What's in your code?

Explore insights into the current state of open source security and get recommendations for securing your
open source supply chain

Download the report

What is the history of open source software?

The idea of making source code freely available originated in 1983 from an ideological movement
informally founded by Richard Stallman, a programmer at MIT. Stallman believed that software should be
accessible to programmers so they could modify it as they wished, with the goal of understanding it,
learning about it, and improving it.i Stallman began releasing free code under his own license, called the
GNU Public License. This new approach and ideology surrounding software creation took hold and
eventually led to the formation of the Open Source Initiative in 1998.i

What is the Open Source Initiative?

The Open Source Initiative (OSI) was created to promote and protect open source software and
communities.ii In short, the OSI acts as a central informational and governing repository of open source
software. It provides rules and guidelines for how to use and interact with OSS, as well as providing code
licensing information, support, definitions, and general community collaboration to help make the use and
treatment of open source understandable and ethical.ii

How does open source software work?

Open source code is usually stored in a public repository and shared publicly. Anyone can access the
repository to use the code independently or contribute improvements to the design and functionality of the
overall project.

OSS usually comes with a distribution license. This license includes terms that define how developers can
use, study, modify, and most importantly, distribute the software.iii According to the Black Duck®
KnowledgeBase, five of the most popular licenses are:

 MIT License
 GNU General Public License (GPL) 2.0—this is more restrictive and requires that copies of modified code
are made available for public use
 Apache License 2.0
 GNU General Public License (GPL) 3.0
 BSD License 2.0 (3-clause, New or Revised)—this is less restrictiveiv

When source code is changed, OSS must include what was altered as well as the methods involved. Depending on
the license terms, the software resulting from these modifications may or may not be required to be made
available for free.iii

What are some examples of open source software?

 GNU/Linux
 Mozilla Firefox
 VLC media player
 SugarCRM
 GIMP
 VNC
 Apache web server
 LibreOffice
 jQuery
Is open source software bug-free?

The short answer is no. With multiple parties making modifications and improvements, it’s inevitable that
open source software will contain quality, performance, and security flaws. However, the broad base of
code contributors can also mean that bugs are identified and fixed faster.

No matter the type of software—open source or commercial—code flaws will exist. The main difference is
who is responsible for fixing the bugs; for commercial software, vendors are responsible, whereas the
consumer is responsible for open source software. With a robust set of AppSec tools and practices in place,
OSS can be easily secured.

What are the differences between open source and closed source software?
Factors Open source Closed source
Price Available for nominal or zero Cost varies based upon the scale of the
licensing and usage charges. software.
Freedom to Completely customizable but it Change requests must be made to the company
customize depends on the open source license. selling the software. This includes bug fixes,
Requires in-house expertise. features, and enhancements.
User-friendliness Typically less user-friendly, but it can Typically more user-friendly. As a for-profit
depend on the goals of the project and product, adoptability and user experience are
those maintaining it. often key considerations.
After-sales support Some very popular pieces of open Dedicated support teams are in place. The level
source software (e.g., OSS distributed of service available depends on the service-
by Red Hat or SUSE) have plenty of level agreement (SLA).
support. Otherwise, users can find help
through user forums and mailing lists.
Security Source code is open for review by The company distributing the software (i.e.,
anyone and everyone. There is a software owner) guarantees a certain level of
widespread theory that more eyes on support, depending on the terms of the SLA.
the code makes it harder for bugs to Because the source code is closed for review,
survive. However, security bugs and there can be security issues. If issues are found,
flaws may still exist and pose the software distributor is responsible for fixing
significant risk. them.
Vendor lock-in No vendor lock-in due to the In most cases, large investments are made in
associated cost. Integration into proprietary software. Switching to a different
systems may create technical vendor or to an open source solution can be
dependency. costly.
Stability This will depend on the current user Older, market-based solutions are more stable.
base, the parties maintaining the New products have similar challenges as open
software, and the number of years in source products. If a distributor discontinues an
the market. application, the customer may be out of luck.
Popularity Some open source solutions are very In some industries, proprietary software is
popular and are even market leaders more popular, especially if it has been in the
(e.g., Linux, Apache). market for many years.
Total cost of TCO is lower and upfront due to TCO is much higher and depends on the size of
ownership (TCO) minimal or no usage cost, and depends the user base.
on the level of maintenance required.
Community The community participating in Closed community.
participation development, review, critique, and
enhancement of the software is the
essence of open source.
Interoperability This will depend on the level of This will depend on the development standards.
with other open maintenance and goals of the group,
source software but it is typically better than closed
source software.
Tax calculation Difficult due to undefined monetary Definite.
value.
Enhancements or Can be developed by the user if Request must be made to the software owner.
new features needed.
Suitability for OSS might not be technically well- Most proprietary software goes through
production designed or tested in a large-scale multiple rounds of testing. However, things can
environment production environment. still go wrong when deployed in a production
environment.
Financial The financial industry tends to avoid Financial institutions prefer proprietary
institution open source solutions. If used, a software.
considerations vetting process must take place.
Warranty No warranty available. Best for companies with security policies
requiring a warranty and liability indemnity.

What are the pros and cons of open source software?

Pros of open source software

 Open source software is free.


 Open source is flexible; developers can examine how the code works and freely make changes to
dysfunctional or problematic aspects of the application to better fit their unique needs.
 Open source is stable; the source code is publicly distributed, so users can depend on it for their long-term
projects since they know that the code’s creators cannot simply discontinue the project or let it fall into
disrepair.
 Open source fosters ingenuity; programmers can use pre-existing code to improve the software and even
come up with their own innovations.
 Open source comes with a built-in community that continuously modifies and improves the source code.
 Open source provides great learning opportunities for new programmers.v

Cons of open source software


 Open source can be harder to use and adopt due to difficulty setting it up and the lack of friendly user
interfaces.
 Open source can pose compatibility issues. When attempting to program proprietary hardware with OSS,
there is often a need for specialized drivers that are typically only available from the hardware
manufacturer.
 Open source software can pose liability issues. Unlike commercial software, which is fully controlled by the
vendor, open source rarely contains any warranty, liability, or infringement indemnity protection. This
leaves the consumer of the OSS responsible for maintaining compliance with legal obligations.
 Open source can incur unexpected costs in training users, importing data, and setting up required
hardware.vi

How can you ensure open source software security?

While open source software offers a multitude of benefits, it introduces a whole new level of software risk
management. It is critical that an organization utilizing OSS, or acquiring codebases that contain OSS in a
merger or acquisition, truly understand what is in their code so they can effectively manage and secure it.
The Black Duck solution suite offers complete open source coverage, so you can use OSS confidently.

If you want to learn more about open source risk and how to mitigate it, here are some steps you can take:

1. Read the annual "Open Source Security and Risk Analysis" (OSSRA) report to understand the current state
of open source vulnerabilities and risks.
2. Research open source risk management organizations and consulting firms that can provide guidance and
tools for identifying and addressing open source risks in your own organization.
3. Look for articles, blogs, and webinars online that offer tips and best practices for managing open source
risk.
4. Get in touch with experts in the field of open source risk management, to get personalized advice and
guidance tailored to your organization's specific needs.
5. Consider implementing automated solutions for open source management and security, to help you detect
and resolve vulnerabilities, and to stay compliant with open source licenses.

By taking these steps, you can learn more about open source risk and take the necessary steps to mitigate it,
ensuring the security and compliance of your organization's software.
What are the Black Duck offerings for open source software security?

Software composition analysis (SCA) tools help teams manage the security, quality, and license
compliance risks that come with the use of open source and third-party code in applications and containers.
SCA helps you understand what’s in your code, and provides a comprehensive Software Bill of Materials
(SBOM).

Black Duck Audit Services provide fast analysis of open source, legal, security, and quality risks for
merger and acquisition due diligence or internal reporting. Black Duck offers several audits.

 Open source and third-party code audit. This provides a complete open source bill of materials for the
target codebase, and shows all open source components and associated license obligations and conflict
analysis.
 Open source risk assessment. This uses Black Duck Security Advisories to deliver a detailed view of open
source risks in the codebase, including known security vulnerabilities. The assessment result can serve as a
high-level action plan to prioritize research and potential remediation actions.
 Web services and API risk audit. This lists the external web services used by an application, offering insight
into potential legal and data privacy risks. Armed with this data, you can quickly evaluate web services risks
across three key categories: governance, data privacy, and quality.

What Is Open Source Software?

Open source software (OSS) is a type of software whose source code is available to the public. This means
that anyone can view, modify, and distribute the software as they see fit. OSS is an alternative to the
traditional proprietary software model, where the source code is kept secret and users are restricted in their
ability to modify or share the software.

OSS is rooted in the belief that software should be a community resource. Developers from around the
world can collaborate on OSS projects, making improvements and adding features that benefit everyone.
This collaborative model also allows for rapid innovation, as the combined efforts of many developers can
often outpace those of a single company.

However, it’s important to note that ‘open source’ doesn’t necessarily mean ‘free’. While many OSS
projects are available for free, developers can choose to charge for their software if they wish. The key
difference is that the source code must be available to users, allowing them to modify and distribute the
software as they see fit.

A Brief History of Open Source Software

The concept of open source software may seem like a new phenomenon, but its roots go back several
decades. In the early days of computing, software was often shared freely among academics and
researchers. The idea was to foster collaboration and accelerate innovation, much like the open source
movement today.

However, as the software industry began to take shape in the 1970s and 1980s, companies started to see the
value in proprietary software. They began to keep their source code secret, selling licenses to users that
allowed them to use the software but not to modify or distribute it. This shift towards proprietary software
marked a significant change in the software industry, and it was not without controversy.

In the late 1980s and early 1990s, a group of developers led by Richard Stallman began to push back
against this trend. They believed that software should be a communal resource, and they started to develop
free software that anyone could modify and distribute. This marked the beginning of the modern open
source movement, and it has been growing ever since.

Open Source vs. Closed Source Software

Closed source software (also called custom code or proprietary code) is protected, preventing unauthorized
users from using or viewing the source code. Any attempts to modify, delete, or copy closed code
components can result in legal repercussions or voiding the warranty.

In contrast, open source software allows users to copy, delete, or modify code components, keeping the
code open so that others can include this code in their program, according to the licensing granted by the
open source code creators. Let’s explore the key differences between open and closed source software.

Support

Closed source software is typically developed and maintained by a single company or organization. This
centralized development structure allows for dedicated customer support teams that can quickly address
any issues or concerns that users may encounter. Closed source software often comes with comprehensive
documentation, tutorials, and training resources to assist users in maximizing its potential.

On the other hand, open source software is developed by a community of contributors who collaborate to
improve and enhance the software. While this distributed development model fosters innovation and
creativity, it can sometimes lead to limited support options.

However, open source communities are known for their vibrant and helpful nature. Users can seek
assistance from forums, discussion groups, and online communities where experienced developers and
enthusiasts are eager to lend a helping hand. Open source software also benefits from continuous updates
and improvements driven by a diverse range of contributors.

Usability

Closed source software is often designed with a focus on user-friendliness and intuitive interfaces.
Extensive user testing and interface design considerations are conducted to ensure a smooth and seamless
user experience. Closed source software tends to have a consistent look and feel, making it easier for users
to navigate and accomplish their tasks efficiently.
Open source software, on the other hand, may have varying degrees of usability. Since it is developed by a
diverse community, usability can sometimes be a hit or miss. However, many open source projects have
made significant strides in improving their user interfaces and overall user experience. Some projects even
have dedicated teams focused on enhancing usability.

Moreover, open source software provides users with the freedom to customize and tailor the software to
their specific needs, which can greatly enhance usability for those willing to invest time and effort.

Security

Closed source software often benefits from a dedicated team of security experts who identify and patch
vulnerabilities. The proprietary nature of closed source software can make it more difficult for malicious
actors to exploit security loopholes, as the source code is not freely available for scrutiny. Additionally,
closed source software companies often prioritize security audits and regular updates to ensure that their
software remains robust against emerging threats.

Open source software involves a different approach to security. The transparency of the source code allows
a global community of developers to scrutinize it for vulnerabilities and suggest improvements. This
collaborative effort can lead to rapid identification and resolution of security issues.

Open source software communities often have a culture of sharing security best practices and collectively
addressing vulnerabilities. However, users must still exercise caution and ensure that they are using official
releases from trusted sources, and that the open source projects they are using are regularly maintained.

Cost

Closed source software is typically associated with licensing fees or subscription-based pricing models.
These costs can vary greatly depending on the complexity and intended use of the software. While closed
source software may require an upfront investment, it often comes bundled with customer support, regular
updates, and additional features.

Open source software is generally available for free. Users can download, use, and modify the software
without any licensing costs. This makes OSS an attractive option for individuals and organizations with
limited budgets. However, it is important to consider the total cost of ownership when evaluating open
source software. While the software itself may be free, there may be additional costs associated with
implementation, customization, and ongoing support.

Flexibility

Closed source software offers limited flexibility. Users are generally limited to the features and
functionalities provided by the software vendor. Customization options may be limited, and users may have
to rely on the vendor’s roadmap for future enhancements. While closed source software can often meet the
needs of a broad range of users, it may not be suitable for those seeking extensive customization or
integration capabilities.
By providing users with access to the source code, open source software allows for customization and
modification to meet specific needs. This flexibility is particularly valuable for organizations with unique
requirements or those seeking to integrate the software with existing systems and workflows. Users can
tailor the software to their precise needs, whether it involves adding new features, removing unnecessary
ones, or integrating with other software solutions.

What Are Open Source Licenses?

Open source licenses are legal agreements that specify how an OSS can be used, modified, and distributed.
These licenses are crucial for maintaining the open nature of OSS. Without them, developers could
potentially restrict how their software is used, undermining the whole concept of open source.
There are many different types of open source licenses, each with its own set of conditions and
permissions. Some licenses are very permissive, allowing users to do almost anything with the software.
Others, known collectively as ‘copyleft’ licenses, are more restrictive, placing certain limitations on how
the software can be modified or distributed. Including components with copyleft licenses in your software
can severely limit your ability to commercialize or monetize the software.

Popular Permissive Licenses

The Apache License

The Apache License is a permissive license created by the Apache Software Foundation. It allows users to
use, modify, and distribute the software, provided that they comply with the terms of the license. This
includes providing attribution to the original author and including a copy of the license in any distributions.

One of the notable features of the Apache License is its grant of a patent license. This means that
contributors automatically grant a license to their patents that would be infringed by the software. This
feature helps to protect users and developers from potential patent litigation.

MIT License

The MIT License is named after the Massachusetts Institute of Technology, where it originated. The MIT
License is simple and straightforward, allowing users to do whatever they want with the software, as long
as they provide attribution and include a copy of the license.

The MIT License does not include a patent license, which differentiates it from the Apache License.
However, its simplicity and permissiveness have made it a popular choice for many open source projects.

BSD License

The BSD License originated at the University of California, Berkeley. There are several variations of the
BSD License, but they all allow users to use, modify, and distribute the software, provided they meet
certain conditions.
These conditions usually involve providing attribution and including a copy of the license. Some versions
of the BSD License also include a non-endorsement clause, which prohibits the use of the names of the
contributors to endorse or promote products derived from the software.

Popular Copyleft Open Source Licenses

GNU General Public License (GPL)

The GNU General Public License (GPL) was created by Richard Stallman and the Free Software
Foundation, and it has been instrumental in the growth of the open source movement.
The GPL requires that any derivative works must also be licensed under the GPL. This ensures that the
software remains open and free for everyone to use, modify, and distribute. But at the same time, it
severely restricts the ability to commercialize any software based on GPL-licensed technology.

Affero GPL (AGPL)

The GNU Lesser General Public License (LGPL) is a less restrictive version of the GPL. It allows
developers to use LGPL-licensed code in proprietary software, provided that they make the source code for
the LGPL components available.
The LGPL is a popular choice for libraries and other software components that are designed to be used in a
variety of projects. It provides a balance between openness and flexibility. However, like the GPL, the
LGPL is still a copyleft license, which means that it imposes certain restrictions on how the software can
be used.

Eclipse Public License (EPL)

The Eclipse Public License (EPL) is used by the Eclipse Foundation for their widely-used Eclipse IDE,
among other projects. While the EPL is a copyleft license, it is less restrictive than the GPL. It allows
developers to use EPL-licensed code in proprietary software, without requiring that the entire software be
EPL-licensed.

Mozilla Public License (MPL)

The Mozilla Public License (MPL) is used by the Mozilla Foundation for their Firefox web browser and
other projects. The MPL is similar to the EPL in that it allows for the use of MPL-licensed code in
proprietary software.
The MPL has a unique feature called the ‘file-level copyleft’. This means that modifications to existing
MPL-licensed files must be released under the MPL, but new files can be licensed as the developer sees fit.

Business Source Licenses

The Business Source License (BSL) is a type of software license that offers a unique approach to balancing
the benefits of open source and proprietary software. It was created by MariaDB Corporation founder
Michael “Monty” Widenius. Here are some key features of the BSL:
 Time-delayed source code release: Under a BSL license, the source code of the software is eventually made
available as open source after a predetermined delay period. This period is typically a few years, after
which the software automatically converts to a standard open-source license, such as the General Public
License (GPL).
 Limited use rights initially: During the delay period, users have limited rights to use, modify, and share the
software. The license may impose certain restrictions, such as on the size of the organization that can use it
for free, or the types of uses (like non-commercial) that are permitted without a paid license.
 Commercial use: The BSL allows the original creators to monetize the software during the delay period.
Companies or individuals who wish to use the software for purposes beyond what is allowed for free under
the BSL typically need to purchase a commercial license.
 Promotion of open source ideals: After the delay period ends and the software becomes open source
under a traditional open-source license, the community benefits from access to the source code. This
delayed release mechanism promotes open source ideals while allowing the creators to derive commercial
benefits initially.

Key Use Cases for Open Source Software

Web Servers and Hosting

Open source plays an important role in the domain of web servers and hosting. The Apache HTTP Server,
one of the most prominent OSS projects, has been a cornerstone of the internet, powering a significant
portion of the web’s sites. Its success is attributed to its robustness, flexibility, and active community
support. Additionally, Nginx, another OSS web server, has gained popularity for its high performance,
scalability, and efficient handling of concurrent connections, making it an ideal choice for high-traffic
websites.

In hosting environments, open source tools like the LAMP stack (Linux, Apache, MySQL,
PHP/Python/Perl) enable businesses and developers to deploy web applications efficiently. The stack’s
components are all open source, ensuring a cohesive and cost-effective platform for web development and
hosting.

Database Management

In the realm of database management, OSS offers a range of solutions that cater to different needs, from
lightweight databases like SQLite to powerful, enterprise-grade systems like PostgreSQL and MySQL.
These open source databases provide users with the ability to handle data effectively, whether for small
personal projects or large, complex applications.

Open source databases offer high levels of customization and flexibility, allowing businesses to tailor the
database system to their specific requirements. The vibrant communities around these databases contribute
to their reliability and security, with regular updates and patches addressing emerging threats or issues.

Cloud Computing and Containerization

In cloud computing, open source technologies have been transformative. Notable examples are OpenStack
for cloud infrastructure management, Docker for containerization and Kubernetes for container
orchestration. These tools offer organizations the ability to build and manage scalable, flexible cloud
environments without being tied to proprietary solutions.

The collaborative nature of open source development accelerates innovation in the cloud computing space,
with new features and integrations being developed at a rapid pace. Furthermore, the transparency and
modifiability of open source software provide users with greater control over their cloud infrastructure.

Real-Time Operating Systems (RTOS)

Real-Time Operating Systems (RTOS) are crucial for applications requiring immediate processing and
response to external events. OSS projects like FreeRTOS and RTLinux provide the foundation for
developing real-time applications in areas such as embedded systems, automotive, and IoT devices.

These open source RTOS platforms allow developers to access and modify the source code, enabling them
to optimize and customize the operating system according to their project’s specific needs. The availability
of source code and a community of developers also helps in identifying and fixing bugs and security issues
quickly.

Learn more in the detailed guide to RTOS.

Security Tools

The open source community has contributed significantly to cybersecurity, offering a wide array of tools
for monitoring, penetration testing, and securing networks. Tools like Wireshark for network protocol
analysis, Zed Application Proxy (ZAP) for dynamic application testing, and Metasploit for security
vulnerability testing, are indispensable to security professionals.

Open source security tools benefit from the collective expertise of a global community. Additionally, these
tools can be customized to suit the unique security needs of each organization.

What Is an Open Source Software Policy?

An open source software policy is a set of rules and guidelines that govern how an organization or
individual uses and contributes to open source software. The policy outlines the practices and procedures
that need to be followed when dealing with open source software to ensure compliance with licenses,
protect intellectual property rights, and maintain the integrity of the software.

The policy also provides guidance on how to contribute to open source projects. This includes how to
submit changes, how to handle disputes, and how to acknowledge the work of others. It’s important to
remember that contributing to open source requires more than writing code. It can also involve reporting
bugs, improving documentation, and helping other users.

Keeping an open source software policy helps in managing risks associated with the use of open source
software. It ensures that the organization is aware of its responsibilities and obligations when using and
distributing open source software. A well-defined policy can also help in decision-making processes,
ensuring that the use of open source software aligns with the organization’s strategic goals.
Best Practices for Open Source Security and Compliance

Open source security is a growing concern in software development organizations, because most enterprise
software projects include thousands of open source components. Here are a few ways to ensure open
source software does not compromise the security of your applications.

Monitor for Updates

Securing open source software requires continuous monitoring for security updates. Many open-source
projects are updated regularly, and it’s crucial to keep track of these updates and apply them promptly.

Updates often contain security patches that fix known vulnerabilities in the software. Failing to apply these
patches can leave your systems exposed to potential threats. Therefore, it is essential to have a system in
place that alerts you when new updates or vulnerabilities are detected.

Implement Open Source Vulnerability Scanning

Vulnerability scanning is a proactive approach to identifying security weaknesses in your OSS. It involves
using specialized tools to scan your software for known vulnerabilities. These tools compare the
components of your software against databases of known vulnerabilities, such as the National Vulnerability
Database (NVD).

Open source vulnerability scanning helps you identify and fix vulnerabilities before they can be exploited.
Regular scanning can also help you understand your software better, allowing you to make informed
decisions about its security. New vulnerabilities are discovered regularly, so continuous scanning is
necessary to ensure your software remains secure.

Use a Binary Repository

A binary repository is a storage location where you can keep binary files, the compiled version of your
software. Using a binary repository can significantly improve the security of your open source software.

A binary repository allows you to keep track of all the versions of your software. This makes it easier to
manage updates and patches, ensuring that you are always using the latest, most secure version of your
software.

A binary repository can also help you control access to your software. You can set permissions to
determine who can access your software, preventing unauthorized access and potential security threats.

Software Composition Analysis

Software composition analysis (SCA) is a method used to identify open source components within your
software and assess their security risks. It provides a comprehensive view of your software’s composition,
allowing you to understand its security posture better.
SCA tools can identify known vulnerabilities in the open-source components of your software. They can
also check for compliance with licensing requirements, ensuring that you are not violating any open-source
licenses.

By providing a detailed view of your software’s composition, SCA can help you manage your open-source
usage effectively. It allows you to make informed decisions about the open-source components you use,
enhancing the security and compliance of your software.

Now that we’ve covered the important considerations for using open source software in your projects, let’s
review some of the world’s most popular open source software.

Implement GitOps

GitOps is an operational framework that takes DevOps practices a step further, using Git as the single
source of truth for managing infrastructure and application configurations. This approach enhances open
source security by introducing a more controlled, auditable, and automated deployment process.
When implementing GitOps, all changes to the infrastructure and application configurations are made via
Git pull requests. These changes are automatically applied to the production environment using continuous
deployment (CD) tools. This method ensures that every modification is tracked and reviewed, reducing the
risk of unauthorized changes or misconfigurations that could lead to security vulnerabilities.
GitOps minimizes the attack surface by limiting direct access to production environments. By enforcing
changes through a controlled Git workflow, it ensures that only approved and verified updates are
deployed, thereby reducing the chances of introducing vulnerabilities into your software ecosystem.

Learn more in the detailed guide to GitOps

Related product offering: Octopus Deploy | Continuous Delivery and Deployment Platform

Related technology updates:

[Blog] What is GitOps?


Top Open Source Projects: Content Management Systems
WordPress

Official project page: https://wordpress.org/


Repository: https://github.com/WordPress/WordPress
GitHub stars: 18.2K
Run it now in a free Acorn sandbox: Launch Acorn

WordPress is an open source content management system that powers approximately 40% of all websites.
It’s known for its simplicity, flexibility, and user-friendly interface. With WordPress, you can create any
type of website, from a personal blog to a full-fledged e-commerce site.

WordPress has an extensive ecosystem of plugins and themes. With thousands of options to choose from,
you can extensively customize your website. And because it’s open source, you have the freedom to
modify and extend WordPress to suit your specific needs.

Drupal
Official project page: https://www.drupal.org/
Repository: https://github.com/drupal/drupal
GitHub stars: 4K

Drupal is an open-source content management system (CMS) used to make websites and applications. It’s
flexible and customizable, allowing you to build and manage different kinds of sites—from simple blogs to
complex user communities.

One of the key strengths of Drupal is its scalability. It’s designed to handle high-traffic sites and has proven
its ability to scale in real-world scenarios at various organizations that manage large volumes of content.

The Drupal community is large and diverse, with hundreds of thousands of active contributors constantly
working on enhancing its features and performance. This active participation ensures that Drupal remains a
robust platform for web development.

Joomla

Official project page: https://www.joomla.org/


Repository: https://github.com/joomla/joomla-cms
GitHub stars: 4.4K

Joomla is another open-source CMS that empowers you to create dynamic websites and applications. It
offers a balance between ease-of-use and extensibility, making it a popular choice among both beginners
and experienced developers.

Joomla offers an application framework that allows developers to create add-ons, extending the power of
Joomla beyond a simple CMS. The Joomla community is large and active. They are committed to keeping
Joomla user-friendly, powerful, and up-to-date.
Ghost

Official project page: https://ghost.org/


Repository: https://github.com/TryGhost/Ghost
GitHub stars: 44.4K
Run it now in a free Acorn sandbox: Launch Acorn

Ghost is an open source blogging platform that’s gaining popularity for its focus on simplicity and
usability. Unlike WordPress, which has evolved into a full content management system, Ghost remains true
to its blogging roots.

Ghost is designed to make blogging as straightforward as possible. Its clean, clutter-free interface lets you
focus on your content. And while it may not have as many plugins and themes as WordPress, Ghost offers
enough customization options to make your blog distinct.

Strapi

Official project page: https://strapi.io/


Repository: https://github.com/strapi/strapi
GitHub stars: 57.4K
Run it now in a free Acorn sandbox: Launch Acorn

Strapi is an open-source headless CMS that allows developers to build, deploy, and manage content-rich
applications in a short time. It’s built on JavaScript, one of the most popular programming languages,
making it a familiar environment for many developers.

As a headless CMS, Strapi decouples the front-end and back-end development. This gives developers the
freedom to use any technology stack they prefer for the front-end, while Strapi manages the back-end.

Top Open Source Projects: Container Orchestration


Docker Containers

Official project page: https://www.docker.com/


Repository: https://github.com/docker/compose
GitHub stars: 31K
Run it now in a free Acorn sandbox: index.docker.io/tybalex/autogptjs-acorn

Docker is an open source platform that automates the deployment of applications inside software
containers. It provides an additional layer of abstraction and automation of operating-system-level
virtualization on Windows and Linux.

Docker utilizes the resource isolation features of the Linux kernel (such as cgroups and kernel namespaces)
and a union-capable file system (like OverlayFS) to allow independent containers to run within a single
Linux instance, avoiding the overhead of starting and maintaining virtual machines.

Docker can package and run an application in a loosely isolated environment called a container. This
isolation and security allow you to run many containers simultaneously on a given host. Containers are
lightweight and contain everything needed to run the application, ensuring that software runs reliably when
moved from one computing environment to another.

Learn more in the detailed guide to Docker Containers (coming soon)


Kubernetes

Official project page: https://kubernetes.io/


Repository: https://github.com/kubernetes/kubernetes
GitHub stars: 103K

Kubernetes is a portable, extensible, open source platform for managing containerized workloads and
services. It supports declarative configuration and highly flexible automation. It has a large, rapidly
growing ecosystem, with Kubernetes services, support, and tools widely available.

Kubernetes provides a platform for automating deployment, scaling, and operations of application
containers across clusters of hosts. Originally developed by Google and donated to the Cloud Native
Computing Foundation (CNCF), it offers a solution for container orchestration, increasing the scalability,
availability, and efficiency of applications.

**Learn more in these detailed guides:

 Introduction to Kubernetes
 Kubernetes architecture**
Openshift Container Platform

Official project page: https://www.redhat.com/en/technologies/cloud-computing/openshift


Repository: https://github.com/openshift/openshift-docs
GitHub stars: 698

OpenShift is a family of containerization software products developed by Red Hat. Its flagship product is
the OpenShift Container Platform—an on-premises platform as a service built around Docker containers,
which are orchestrated and managed by Kubernetes on a foundation of Red Hat Enterprise Linux.

OpenShift provides developers with an integrated development environment (IDE) for building and
deploying Docker-formatted containers, and then managing them with the open source Kubernetes
container orchestration platform. This platform has been built with enterprise requirements like security in
mind, offering automated updates and scaling.

Learn more in the detailed guide to the Openshift Container Platform

Rancher

Official project page: https://www.rancher.com/


Repository: https://github.com/rancher/rancher
GitHub stars: 21.8K
Rancher enables organizations to deploy and manage Kubernetes at scale. It’s designed to address the
operational and security challenges of managing multiple Kubernetes clusters across different
infrastructure providers.

Rancher offers a user-friendly approach to Kubernetes management. It provides a single, consistent


interface to deploy and manage all your Kubernetes clusters, regardless of where they are running.

The Rancher community helps make Kubernetes accessible to everyone. Their contributions focus on
simplifying the complexities of Kubernetes, making it easier for more organizations to adopt and benefit
from this technology.

Top Open Source Projects: Machine Learning and AI


TensorFlow

Official project page: https://www.tensorflow.org/


Repository: https://github.com/tensorflow/tensorflow
GitHub stars: 179K

TensorFlow is an open source software library for high performance numerical computation. Its flexible
architecture allows easy deployment of computation across a variety of platforms (CPUs, GPUs, TPUs),
and from desktops to clusters of servers to mobile and edge devices.

Originally developed by researchers and engineers from the Google Brain team, TensorFlow has become
popular among developers for machine learning and artificial intelligence projects. It has a broad
ecosystem of tools, libraries, and community resources that lets researchers push new experiments in
ML/AI and developers build and deploy ML/AI-powered applications.
PyTorch

Official project page: https://pytorch.org/


Repository: https://github.com/pytorch/pytorch
GitHub stars: 72.8K

PyTorch is an open source machine learning library developed by Facebook’s AI Research lab (FAIR). It
has gained popularity in the research community for its flexibility, ease of use, and dynamic computational
graph. PyTorch’s design is intuitive, particularly for those familiar with Python programming, making it a
preferred choice for both academic research and development in industrial applications.

One of the key strengths of PyTorch is its user-friendly interface. It offers a straightforward platform for
building deep learning models, allowing researchers and developers to focus more on the design aspect of
their models rather than the technical intricacies of the library. Its dynamic computational graph, where the
graph is built at runtime, offers more flexibility and ease for making changes and debugging. This feature
is particularly useful for complex models and novel architectures in research.

Official project page: https://redis.io/


Repository: https://github.com/redis/redis
GitHub stars: 62.3K
Keras

Official project page: https://keras.io/


Repository: https://github.com/keras-team/keras
GitHub stars: 60.8K

Keras is a high-level neural networks API, written in Python and capable of running on top of TensorFlow,
CNTK, or Theano. It was developed with a focus on enabling fast experimentation.

Keras is designed for human beings emphasizing usability and developer experience. Its API is intuitive
and easy to experiment with, making it approachable for newcomers while also robust enough for expert
practitioners. It provides clear and actionable feedback for user errors and has extensive documentation and
developer guides.

OpenCV

Official project page: https://opencv.org/


Repository: https://github.com/opencv/opencv
GitHub stars: 75.2K
OpenCV (Open Source Computer Vision Library) is an open-source computer vision and machine learning
software library. OpenCV was built to provide a common infrastructure for computer vision applications
and to accelerate the use of machine perception in commercial products.

The library has more than 2,500 optimized algorithms, which includes a comprehensive set of both classic
and state-of-the-art computer vision and machine learning algorithms. These algorithms can be used to
detect and recognize faces, identify objects, classify human actions in videos, track camera movements,
track moving objects, and extract 3D models of objects.

GPTScript

Official project page: https://github.com/gptscript-ai/gptscript


Repository: https://github.com/gptscript-ai/gptscript
GitHub stars: 2.4K

GPTScript is a scripting language designed to enable users to automate tasks and interact with a Large
Language Model (LLM) using OpenAI. It combines the simplicity of natural language with the power of
traditional scripting tools like Bash and Python, as well as the capability to make HTTP service calls. This
unique blend allows users to execute a wide range of tasks, from mundane automation to complex database
operations, using intuitive language commands.

The language’s primary strength lies in its natural language-based syntax, which significantly reduces the
learning curve for new users. This accessibility makes GPTScript an ideal tool for a variety of applications,
including retrieval-augmented generation (RAG), task automation, and the creation of agents and
assistants. Additionally, it can be used for data analysis and the integration of vision, image, and audio
processing tasks into scripts. Another notable feature is its ability to manage memory and construct
chatbots.
HuggingFace Transformers

Official project page: https://huggingface.co/transformers/


Repository: https://github.com/huggingface/transformers
GitHub stars: 124K

HuggingFace Transformers is a library that provides thousands of pre-trained models to perform tasks on
texts such as classification, information extraction, question answering, summarization, translation, and
text generation in over 100 languages. Its aim is to make state-of-the-art NLP easier to use for everyone.

Transformers provide a straightforward way to use models like BERT, GPT-2, T5, and others.
HuggingFace has become a go-to library for anyone working with textual data, thanks to its simplicity,
efficiency, and broad community support. Whether you’re a researcher, developer, or a company, it offers
cutting-edge capabilities with just a few lines of code.

Fast.ai
Official project page: https://www.fast.ai/
Repository: https://github.com/fastai/fastai
GitHub stars: 25.5K

Fast.ai is a deep learning library that provides high-level components aimed to enable fast experimentation
with deep neural networks. It sits on top of PyTorch and is designed to make deep learning more accessible
and easier to implement for practitioners.

Fastai’s library is structured around best practices with a focus on educational purposes, making it not just
a tool for production but also a learning platform for those new to deep learning. It automates many of the
tedious aspects of training deep learning models, making the process more intuitive and allowing
developers and researchers to move faster through their projects.

Top Open Source Projects: Databases


Redis

Official project page: https://redis.io/


Repository: https://github.com/redis/redis
GitHub stars: 62.3K

Redis, which stands for Remote Dictionary Server, is an open source, in-memory data structure store. It is
used as a database, cache, and message broker. One of the reasons for Redis’s popularity is its versatility. It
supports a wide range of data structures, including strings, hashes, lists, and sets.

Redis’s in-memory nature allows it to deliver ultra-fast read and write operations. This makes it an
appropriate choice for high-performance applications. With numerous contributors from around the world,
the Redis community is continually improving and innovating.
PostgreSQL

Official project page: https://www.postgresql.org/


Repository: https://github.com/postgres/postgres
GitHub stars: 13.6K
Run it now in a free Acorn sandbox: Launch Acorn

PostgreSQL is an open source relational database system. It is known for its robustness, scalability, and full
compliance with SQL standards. PostgreSQL supports a broad array of data types, including complex ones
like arrays and hstore (for storing key-value pairs).

One of the key features of PostgreSQL is its extensibility. You can define your own data types, operators,
and functions. This allows you to tailor the database system to your specific needs. And like Redis,
PostgreSQL has a strong community backing it, ensuring its continuous development and improvement.

MongoDB

Official project page: https://www.mongodb.com/


Repository: https://github.com/mongodb/mongo
GitHub stars: 24.7K
Run it now in a free Acorn sandbox: Launch Acorn

MongoDB is an open source NoSQL database that provides high performance, high availability, and easy
scalability. It works on the concept of collections and documents, which makes it flexible and adaptable to
real-world data.

MongoDB offers the ability to handle large amounts of data with diverse structures. It’s suitable for dealing
with big data applications and real-time analytics. MongoDB’s horizontal scaling capability ensures that as
your data grows, your database can grow with it.

MariaDB

Official project page: https://mariadb.org/


Repository: https://github.com/MariaDB/server
GitHub stars: 5K
Run it now in a free Acorn sandbox: Launch Acorn

MariaDB is an open source relational database management system that is a fork of MySQL. It was created
by the original developers of MySQL after concerns over its acquisition by Oracle Corporation. MariaDB
is designed to maintain high compatibility with MySQL, ensuring a drop-in replacement capability with
library binary parity and exact matching with MySQL APIs and commands.

MariaDB has a few features that set it apart from MySQL. It includes a variety of storage engines,
including high-performance ones like Aria, ColumnStore, and Spider. It also offers advanced replication
for scaling.
Cassandra

Official project page: https://cassandra.apache.org/


Repository: https://github.com/apache/cassandra
GitHub stars: 8.3K

Apache Cassandra is an open source distributed database system designed for managing large amounts of
data across many commodity servers, providing high availability with no single point of failure. Cassandra
offers robust support for clusters spanning multiple datacenters, with asynchronous masterless replication
allowing low latency operations for all clients.

Cassandra’s strengths revolve around its ability to handle large amounts of data, its resilient nature, and its
exceptional performance. Because it’s designed for distributed environments, it’s highly scalable and can
seamlessly grow with your data.

Related product offering: Configu: NetApp Instaclustr Data Platform | Open-Source Data Infrastructure
Platform

Related technology updates:


Cassandra vnodes: How Many Should I Use?
Apache Cassandra® Connector for Apache Spark™: 5 Tips for Success
Top Open Source Projects: Big Data
Hadoop

Official project page: https://hadoop.apache.org/


Repository: https://github.com/apache/hadoop
GitHub stars: 14K

Apache Hadoop is an open-source framework designed for distributed storage and processing of large data
sets across clusters of computers using simple programming models. It is particularly known for its ability
to handle petabytes and exabytes of data. Hadoop breaks down big data into smaller pieces to be processed
in parallel, significantly speeding up data processing.

A key feature of Hadoop is its Hadoop Distributed File System (HDFS), which allows for high throughput
access to application data and is suitable for applications with large data sets. The framework also includes
Hadoop YARN, a job scheduling and cluster resource management system, and Hadoop MapReduce, a
programming model for large-scale data processing.

Learn more in the detailed guide to Hadoop


Apache Spark

Official project page: https://spark.apache.org/


Repository: https://github.com/apache/spark
GitHub stars: 37.2K

Apache Spark is an open source, distributed, general-purpose cluster-computing framework. Initially


developed at UC Berkeley’s AMPLab, Spark provides an interface for programming entire clusters with
implicit data parallelism and fault tolerance.

Spark is known for its speed, ease of use, and general-purpose nature. It can run programs up to 100x faster
than Hadoop MapReduce in memory, or 10x faster on disk. Spark also supports a wide array of tasks,
including SQL queries, streaming data, machine learning, and graph processing.

Learn more in the detailed guides to:

 Apache Spark
 PySpark
Elasticsearch

Official project page: https://www.elastic.co/elasticsearch/


Repository: https://github.com/elastic/elasticsearch
GitHub stars: 67.3K

Elasticsearch is a highly scalable open-source search engine and analytics engine. It allows you to store,
search, and analyze big volumes of data quickly and in near real time. Elasticsearch is generally used as the
underlying engine/technology that powers applications with complex search features and requirements.

Elasticsearch uses a document-oriented approach, storing data in JSON format. This makes it easy to store,
search, and manage complex data structures. It’s built on top of the Apache Lucene library, offering a full-
text search engine with a powerful combination of features for search queries.

Elasticsearch is part of the ELK Stack (Elasticsearch, Logstash, Kibana), which is widely used for log
analysis in IT environments. This stack provides a powerful platform for searching, analyzing, and
visualizing data in real-time.

Note: In 2021 Elasticsearch transitioned from an Apache 2.0 open source license to the SSPL 1.0 license,
which is more restrictive. The software is still free and source code is available, but there are some
limitations on how it can be deployed in production.

Learn more in the detailed guide to Elasticsearch.


OpenSearch

Official project page: https://opensearch.org/


Repository: https://github.com/opensearch-project/OpenSearch
GitHub stars: 9.2K

OpenSearch is an open source search and analytics suite derived from Elasticsearch and Kibana. It provides
a scalable solution for search, observability, and data analysis across various types of datasets. OpenSearch
offers powerful full-text search capabilities, real-time data analysis, and advanced visualization tools.

One of OpenSearch’s key strengths is its flexibility and extensibility, allowing users to tailor it to their
specific needs. It supports a wide range of plugins and integrations, making it suitable for diverse use cases
such as log analytics, security monitoring, and more. The project is actively maintained by a large
community, ensuring ongoing improvements and feature additions.

Learn more in the detailed guide to OpenSearch

Kafka
Official project page: https://kafka.apache.org/
Repository: https://github.com/apache/kafka
GitHub stars: 26.3K

Apache Kafka is an open source streaming platform that provides real-time data feeds. It’s designed to
handle data streams from multiple sources and deliver them to multiple consumers. Kafka is known for its
high throughput, reliability, and replication capabilities, making it a popular choice for big data and real-
time analytics applications.

Kafka’s distributed architecture ensures that it can handle massive amounts of data. It also provides fault
tolerance, ensuring that data feeds remain up and running even in the event of a failure. Kafka’s
community is active and enthusiastic, continually contributing to its development and refinement.

Related product offering: Configu: NetApp Instaclustr Data Platform | Open-Source Data Infrastructure
Platform

Related technology update: [Blog] How to Get the Most out of Your Kafka Cluster

Splunk

Official project page: https://www.splunk.com/


Repository: https://github.com/splunk/attack_range
GitHub stars: 1.8K

Splunk is a software platform widely used for monitoring, searching, analyzing, and visualizing machine-
generated data in real time. It processes and indexes the data to make it searchable, and then enables users
to create graphs, reports, alerts, dashboards, and visualizations.

Although not entirely open source, Splunk offers a free version with limited functionality, popular in the
community for data analysis and operational intelligence. It’s particularly valued for its ability to make
sense of large amounts of unstructured data, providing insights that can drive operational performance and
business results.
Learn more in the detailed guide to Splunk Cloud

Slurm

Official project page: https://www.schedmd.com/


Repository: https://github.com/SchedMD/slurm
GitHub stars: 2.1K

Slurm (Simple Linux Utility for Resource Management) is an open source, fault-tolerant, and highly
scalable cluster management and job scheduling system for large and small Linux clusters. Slurm is used
by many of the world’s supercomputers and computer clusters to manage job scheduling.

Slurm prioritizes scalability and portability. It allocates exclusive and/or non-exclusive access to resources
(compute nodes) to users for some duration of time. It also provides a framework for starting, executing,
and monitoring work on the set of allocated nodes. Finally, it arbitrates contention for resources by
managing a queue of pending work.

Learn more in the detailed guide to Slurm


Top Open Source Projects: Other Notable Mentions
OpenTelemetry

Official project page: https://opentelemetry.io/


Repository: https://github.com/open-telemetry
GitHub stars: 4K
OpenTelemetry is an open source project that provides a set of APIs, libraries, agents, and instrumentation
to enable observability in your applications. It includes tools, APIs, and SDKs that can be used to
instrument, generate, collect, and export telemetry data (metrics, logs, and traces) for analysis to
understand your software’s performance and behavior.

OpenTelemetry provides a unified standard for telemetry data collection across various programming
languages and platforms. This makes it easier for developers to implement observability and maintain
consistency in their monitoring practices.

The project supports multiple data sources and export formats, making it adaptable to different monitoring
backends such as Prometheus, Jaeger, and Zipkin. It is backed by a large community and achieved
Graduated status in the Cloud Native Computing Foundation (CNCF).

Learn more in the detailed guide to the OpenTelemetry.

Zipkin

Official project page: https://zipkin.io/


Repository: https://github.com/openzipkin/zipkin
GitHub stars: 16.9K

Zipkin is an open source distributed tracing system that helps developers monitor and troubleshoot latency
issues in microservice architectures. It collects and visualizes trace data, allowing teams to understand the
flow of requests through their systems and identify performance bottlenecks.
Zipkin supports various data collection methods and integrates with numerous platforms, making it a
versatile tool for observing complex, distributed systems. It provides an intuitive UI for viewing traces and
includes powerful features like trace sampling and customizable data storage options. Zipkin is widely used
in the industry and is backed by a robust community of contributors.

Learn more in the detailed guide to Zipkin

Vault HashiCorp

Official project page: https://www.vaultproject.io/


Repository: https://github.com/hashicorp/vault
GitHub stars: 30.7K

Vault by HashiCorp is an open source tool designed to securely manage secrets and protect sensitive data.
It allows organizations to control access to passwords, API keys, certificates, and other secrets in a
centralized and auditable manner. Vault offers robust features like dynamic secrets, encryption as a service,
and secret leasing and revocation, making it an essential tool for managing secrets in modern infrastructure.

Vault supports a wide range of authentication methods and provides fine-grained access control through
policies. It also offers high availability, scaling to meet the needs of large organizations, and is backed by
an active community of contributors and users.

Learn more in the detailed guide to Vault HashiCorp

Related product offering: Configu: Configuration Management Platform | Configuration-as-Code


Automation for Secure Collaboration

Related technology update: [Webinar] Secure CD at scale with Octopus Deploy and HashiCorp Vault

Open source software (OSS) refers to software whose source code is publicly available and can be freely
used, modified, and shared by anyone. The source code is the human-readable instructions and statements
that make up a software program. By making the source code openly accessible, open source software
allows for transparency, collaboration, and continuous improvement by a global community of developers.

The core principles behind open source software include:

1. Open Collaboration: Anyone can contribute to the development, modification, and improvement of the
software by submitting code changes, bug fixes, or new features.

2. Free Distribution: Open source software can be freely distributed, copied, and used without paying
licensing fees or royalties.

3. Access to Source Code: The source code is openly available, allowing users to inspect, modify, and learn
from it.
4. Community-Driven Development: Open source projects often have a vibrant community of developers,
users, and enthusiasts who collaborate, provide feedback, and drive the software's evolution.

Open source software has gained widespread adoption across various domains, including operating systems
(e.g., Linux), web browsers (e.g., Mozilla Firefox), office suites (e.g., LibreOffice), source code managers,
(e.g., Gitness, GitHub) and programming languages (e.g., Python, Ruby). Many companies, organizations,
and individuals contribute to and benefit from open source projects, as it promotes innovation, cost-
effectiveness, and the sharing of knowledge.

The open source movement has had a significant impact on the software industry, fostering transparency,
collaboration, and rapid innovation. It empowers users to have control over the software they use and
encourages the development of robust, secure, and adaptable solutions.

How does open source software work?

The development process of open source software is a collaborative endeavor that harnesses the collective
efforts of a global community. Unlike proprietary software, where the source code is closely guarded, open
source projects embrace transparency by making their code openly available to anyone interested. This
accessibility allows developers from around the world to contribute their skills, expertise, and ideas
towards improving and enhancing the software.

At the core of open source software lies a vibrant ecosystem of passionate individuals who voluntarily
dedicate their time and effort to the project. These contributors can range from seasoned professionals to
hobbyists and students, each bringing their unique perspectives and experiences to the table. They work
together, reviewing each other's code, identifying and fixing bugs, proposing new features, and refining
existing functionalities.

Many open source projects have established robust governance models and guidelines to manage and
coordinate the development efforts effectively. These models often involve a core team of maintainers who
oversee the project's direction, review code contributions, and ensure adherence to coding standards and
best practices. Additionally, open source communities foster open discussions, allowing users and
developers to provide feedback, report issues, and share ideas for future development.

The power of open source software lies in its ability to leverage the collective intelligence and diverse
perspectives of its contributors. By embracing transparency, collaboration, and continuous improvement,
open source projects can rapidly evolve, adapt to changing needs, and produce high-quality software that
benefits users worldwide.

Benefits of Open Source Software

Open source software offers a multitude of advantages that have contributed to its widespread adoption and
success. At its core, the open and collaborative nature of open source development fosters innovation,
flexibility, and cost-effectiveness. By making the source code freely available, open source software
empowers users and developers alike, unlocking a world of possibilities.

One of the most significant benefits of open source software is the ability to scrutinize and modify the code
to suit specific needs. This level of transparency and customizability ensures that the software can be
tailored to meet unique requirements, whether it's adding new features, optimizing performance, or
enhancing security. The freedom to adapt the software eliminates the constraints often associated with
proprietary systems, allowing for greater flexibility and control.

From a financial perspective, open source software offers significant cost savings compared to proprietary
alternatives. With no licensing fees or expensive maintenance contracts, open source solutions provide a
cost-effective option, particularly for organizations with limited budgets. This accessibility democratizes
software development and empowers individuals and businesses to leverage powerful tools without
substantial financial barriers.

Open source software often exhibits increased interoperability and compatibility with other systems and
platforms. This interoperability is facilitated by the use of open standards and protocols, allowing for
seamless integration and data exchange across different environments. Consequently, organizations can
avoid vendor lock-in and enjoy greater flexibility in their technology stack.

The benefits of open source software extend beyond the technical realm. The open source movement has
fostered a vibrant community of individuals who collaborate, share knowledge, and contribute to the
collective advancement of software development. This community-driven approach promotes transparency,
fosters a culture of learning, and encourages the free exchange of ideas, ultimately driving innovation and
progress.

Challenges with Open Source Software

While open source software offers numerous benefits, it also presents a set of challenges that must be
carefully navigated. One of the primary concerns revolves around the potential lack of centralized support
and maintenance. Unlike proprietary software, where a dedicated team is responsible for providing
technical assistance and regular updates, open source projects often rely on the voluntary efforts of a
dispersed community. This decentralized approach can lead to inconsistent or delayed support, particularly
for niche projects with smaller communities.

Another challenge lies in the complexities associated with managing and coordinating the contributions
from a diverse global community. Open source projects can receive code submissions from developers
with varying skill levels and coding styles, which can make it difficult to maintain a cohesive codebase and
ensure adherence to established standards and best practices. Effective governance and quality control
mechanisms become crucial to mitigate these challenges and ensure the overall integrity of the software.

Security is another area of concern that requires vigilance in the open source ecosystem. While the open
nature of the code allows for transparency and peer review, it also exposes the software to potential
vulnerabilities if not properly maintained and monitored. Malicious actors may attempt to introduce
security flaws or backdoors, compromising the integrity of the software. Consequently, open source
projects must prioritize security audits, prompt patching, and proactive measures to safeguard against
potential threats.

Furthermore, open source software can sometimes lack comprehensive documentation and user support
resources. As contributions come from various individuals, documentation may be incomplete or
inconsistent, making it challenging for users, particularly those with limited technical expertise, to
effectively utilize and troubleshoot the software. Clear and well-maintained documentation is essential for
widespread adoption and user satisfaction.

Lastly, the open source model can present challenges related to intellectual property rights and licensing
compliance. With multiple contributors and different licenses involved, it becomes crucial to ensure that all
code contributions adhere to the project's licensing terms and do not infringe on any third-party intellectual
property rights. Failure to properly manage licensing and legal aspects can lead to potential legal disputes
and hinder the project's progress.

While open source software offers significant advantages, addressing these challenges requires a proactive
approach, effective governance, and a strong commitment from the community to ensure the long-term
success and sustainability of open source projects.

Differences between open source and closed source software

Open source and closed source software represent two contrasting approaches to software development and
distribution. The fundamental distinction lies in the accessibility and transparency of the source code,
which shapes the development process, licensing models, and overall philosophy behind each approach.

Open source software embraces a collaborative and transparent model, where the source code is freely
available for anyone to inspect, modify, and distribute. This openness fosters a vibrant community of
developers who can contribute to the software's improvement, identify and fix bugs, and propose new
features. The open nature of the code allows for peer review, promoting quality assurance and security
through collective scrutiny.

In contrast, closed source software, also known as proprietary software, keeps the source code tightly
guarded and inaccessible to the general public. The code is considered a trade secret, owned and controlled
by the software company or individual developer. Users of closed source software are typically granted a
license to use the software under specific terms and conditions, but they do not have the ability to modify
or redistribute the code.

The development process for open source software is decentralized and driven by a global community of
contributors, while closed source software is typically developed by a dedicated team within a company or
organization. This centralized approach in closed source development allows for tighter control over the
software's direction and roadmap but may limit the diversity of ideas and contributions.
Licensing models also differ significantly between open source and closed source software. Open source
projects often utilize licenses that encourage free distribution and modification, such as the GNU General
Public License (GPL) or the MIT License. These licenses ensure that the software remains free and open
for future generations. In contrast, closed source software is typically distributed under proprietary licenses
that restrict modification, redistribution, and reverse engineering.

Open source software tends to prioritize interoperability and adherence to open standards, promoting
compatibility across different platforms and systems. Closed source software, on the other hand, may
prioritize vendor lock-in strategies, making it more challenging to integrate with other systems or migrate
data to alternative solutions.

The philosophical underpinnings of open source and closed source software also diverge. Open source
advocates promote the free sharing of knowledge, collaboration, and community-driven development,
aligning with values of transparency and freedom. Closed source models often prioritize commercial
interests, intellectual property protection, and maintaining competitive advantages through proprietary
technologies.

While both approaches have their merits and suit different needs, the choice between open source and
closed source software ultimately depends on an organization's or individual's requirements, priorities, and
alignment with the respective philosophies and development models.

What is the Open Source Initiative?

The Open Source Initiative (OSI) is a globally recognized non-profit organization dedicated to promoting
and advocating for open source software. Founded in 1998, the OSI plays a pivotal role in shaping the open
source movement and setting standards for what qualifies as truly open source.

At the core of the OSI's mission lies the Open Source Definition, a set of criteria that establishes the
fundamental principles and requirements for software to be considered open source. This definition serves
as a guideline for developers, ensuring that open source projects adhere to principles of free redistribution,
access to source code, derived works, non-discrimination, and the absence of restrictive license terms.

The OSI's efforts extend beyond defining open source software; it also serves as a steward of the open
source community. The organization maintains a widely recognized list of open source licenses that
comply with the Open Source Definition, providing a reference for both developers and users to ensure
compliance and promote legal certainty.

The OSI actively campaigns for the adoption and use of open source software across various sectors,
including government, education, and industry. It works to raise awareness about the benefits and
advantages of open source solutions, fostering a culture of collaboration, transparency, and innovation.

Through educational initiatives, events, and advocacy efforts, the OSI aims to empower individuals,
organizations, and communities to embrace open source practices. It provides resources, guidance, and
support to help navigate the complexities of open source licensing, governance, and best practices.
The OSI's role as a neutral and independent authority in the open source ecosystem is crucial. It serves as a
trusted voice, promoting the principles of open source and facilitating collaboration among stakeholders,
including developers, businesses, and policymakers.

By upholding the ideals of open source software and fostering a vibrant community, the Open Source
Initiative plays a vital role in shaping the future of software development and driving innovation through
open and collaborative practices.

What Is Open Source Software? Meaning, Working, Importance, and Examples

Open source software are programs whose source code is freely available for anyone to view, modify, and
distribute. Read on to learn more about open source software, how it works, and a few examples of such
software.

Open source software refers to computer programs whose source code is freely available on repositories
like GitHub for anyone to view, use, modify, and distribute.
From powering smartphones to running critical infrastructure systems worldwide, open source plays an
indispensable role in our digital lives.
This guide explains the meaning of open source software, how it works, its applications, and its key
differences from closed source software. It also discusses the importance of open source and its pros and
cons.

What Is Open Source Software?

Open source software are computer programs whose source code is available for anyone to view, modify,
and distribute. Unlike closed source software, which keeps its code hidden from users, open source
software encourages collaboration and transparency among developers.

This means individuals or organizations can freely access the underlying code of an open source program,
making it customizable and adaptable to meet specific needs.

The concept of open source software traces back to the late 20th century when Richard Stallman launched
the Free Software Movement in 1983. It aimed to promote user freedom by providing access to the
software’s source code. The movement gained momentum with Linus Torvalds’ development of Linux in
1991, marking a significant milestone in open source history.

Since then, numerous projects have emerged under various open source licenses, such as GNU General
Public License (GPL) and Apache License. Today, open source software is crucial in powering many
technological advancements across industries worldwide.
How Does Open Source Software Work?

Open source software operates on a collaborative model, where the source code is freely available to
users. This accessibility allows developers to study how the software functions, identify and fix bugs, and
add new features. Communities of developers, enthusiasts, and users form around projects, working
together to improve the software.

Open source collaboration takes various forms, such as contributing code changes, suggesting
improvements, creating documentation, or providing support to others. By pooling diverse skills and
perspectives, these communities can evolve software more effectively.

To facilitate collaboration, open source projects utilize version control systems like Git. Version control
systems allow multiple developers to work on the same codebase simultaneously, track changes, and
manage contributions. Public code repositories, such as GitHub or GitLab, serve as platforms for hosting
open source projects.

These repositories provide a central location where developers can share their code, manage issues, and
collaborate. Users can report bugs, suggest new features, or engage in discussions, fostering a sense of
community participation and feedback. Further, through forking and branching, contributors can create
independent copies of the software, enabling experimentation and the development of alternative
versions.

Open source projects typically have structured release management processes. This involves testing,
documentation updates, and ensuring compatibility across various platforms. Regular releases ensure that
users have access to stable and reliable software while allowing contributors to showcase their
contributions.

The open source philosophy embraces continuous improvement. Feedback drives the evolution of open
source software, motivating developers to refine existing features, fix bugs, and enhance cyber security.

See More: What Is Network Software? Definition, Types, Components, and Best Practices
Open Source vs. Closed Source Software — 6 Key Differences

Open source and closed source software are two distinct approaches to developing and distributing
computer programs. Here are six key differences between the two:
1. Access to source code

In open source software, the source code is freely available for users to view, modify, and distribute. This
allows developers to customize the software according to their needs and contribute improvements back
to the community.

On the other hand, closed source or proprietary software keeps its source code hidden from users. Only the
compiled version of the software is provided, making it difficult for users to understand how it works or
make any modifications. This lack of transparency can be limiting for developers who want more control
over their software.
2. Availability of features

Closed source software often has more features than open source software because the companies or
teams behind closed source software have dedicated resources and expertise. They can invest a lot of time,
money, and specialized knowledge into developing and improving their software, allowing them to
continuously add new features and enhance user experience.

Additionally, closed source software companies sometimes integrate their products with other proprietary
solutions or services, providing additional functionalities that make the software seem more feature-rich.

On the other hand, open source software relies on community collaboration. While open source software
may not have as many built-in features as closed source software, it offers other advantages such as
reliability, stability, security, and the flexibility for users to modify and customize it to suit their needs
3. Transparency of functionality

By providing transparency in functionality, open source software promotes trust and allows users to
understand how their applications work on a deeper level. They can examine every line of code and ensure
no malicious activities occur within the software.

Openness fosters collaboration among developers as they can review each other’s work and identify bugs
or issues more effectively.

Also, closed source software keeps its source code hidden from users. This lack of transparency raises
questions about what exactly is happening behind the scenes. Users cannot inspect the inner workings of
closed source software and may have concerns regarding potential security vulnerabilities or hidden
functionalities.
In contrast, with closed source software, users must rely solely on the developer’s claims about its
functionality without being able to verify them independently.
4. Availability of customer support

In closed source software, companies typically offer dedicated customer support services to assist users
with any issues they may encounter. This includes access to a helpdesk or hotline where users can reach
out for assistance.

Moreover, open source software often relies on community-based support. Users can seek help from
online forums, discussion boards, or mailing lists where fellow developers and enthusiasts provide guidance
and solutions.

While this approach may lack the immediate response time offered by dedicated customer support teams,
it benefits from a wider pool of expertise as multiple individuals contribute their knowledge and
experiences to troubleshoot problems.
5. Licensing systems

Open source software is typically released under licenses that allow users to view, modify, and distribute
the source code freely. The most common open source license is the GNU General Public License (GPL),
which ensures that any modifications or derivative works must also be made available as open source.

Further, closed source software is protected by proprietary licenses that restrict access to the underlying
code. These licenses often require users to pay for a license and prohibit them from modifying or
redistributing the software without explicit permission from the copyright holder.

Examples of popular closed source licenses include Microsoft’s End-User License Agreement (EULA), which
governs Azure and all other MS products, and Apple’s Software License Agreement.
6. Commercial usage and reusability restrictions

Open source software allows for unrestricted commercial use, meaning individuals or businesses can use
the software for profit without any limitations. Additionally, open source software typically has no
restrictions on code reuse, allowing developers to modify and distribute the code as they see fit.

Closed source software often comes with strict licensing agreements that limit its commercial usage. These
licenses may require users to purchase a specific license or pay royalties to use the software commercially.
Similarly, closed source software may have stringent restrictions on code reuse, prohibiting developers
from modifying or distributing the code without explicit permission from the owner.

See More: Top 10 Open Source Artificial Intelligence Software in 2021


Importance of Open Source

Open source software (OSS) has gained significant importance in today’s digital landscape, providing
numerous benefits to developers, businesses, and the broader technology community. Here are the top
reasons why open source—the software, the communities, and the philosophy—is so crucial:
Importance of Open Source Software

Open Source Software Importance


1. Helps in innovation and research

Providing access to the underlying source code allows developers to modify, customize, and build upon
existing software solutions. This level of flexibility enables researchers and innovators to experiment with
new ideas, add features, or solve specific problems without starting from scratch.

Moreover, the collaborative environment promotes knowledge sharing and collective problem-solving.
Researchers can leverage this vast pool of expertise to enhance their projects or find innovative solutions
for complex challenges.
2. Supports startups and solopreneurs

Open source software has been a game-changer for startups and solopreneurs, providing them with the
tools they need to thrive in an increasingly competitive market. The accessibility and affordability of open
source solutions make it easier for these small businesses to get off the ground without breaking the bank.

Startups can leverage open source software for a wide range of needs, from building their website or
mobile app to managing customer relationships and streamlining internal operations. With access to high-
quality, free, or low-cost software, startups can allocate their limited resources toward other crucial
aspects of their business, like marketing or product development.

Additionally, open source communities often provide support and forums where entrepreneurs can
connect with like-minded individuals facing similar challenges along their journey.
3. Assists in training software developers

Open source software plays a crucial role in training software developers and fostering their skills. With
open source projects, aspiring programmers can gain hands-on experience by contributing to real-world
applications. This practical approach allows them to understand the intricacies of coding, collaborate with
experienced developers, and improve their problem-solving abilities.

By participating in communities, software developers can learn from experts and receive valuable feedback
on their work. They can study well-established codebases, explore different programming languages like
Python, C, or C++, and understand best practices followed by industry professionals.

Whether they are working on bug fixes or adding new features to existing projects, these opportunities
enable them to gain confidence in their abilities while making tangible contributions to the world of
technology.
4. Improves software quality as a result of public scrutiny

One major advantage of open source software is that it undergoes constant review and feedback from a
large community of developers. With the source code available to anyone, bugs and vulnerabilities can be
identified and fixed faster than in closed source software. This collaborative effort ensures that the
software is thoroughly tested by experts, leading to higher-quality products.

The transparency provided by open source development allows for continuous improvement through
public scrutiny.

See More: Top 10 Software as a Service (SaaS) Companies in 2021


5. Drives better accountability of the software supply chain
With closed source software, the development process is often hidden, making it difficult to assess the
quality and security of the code. You need a complex software bill of materials (SBOM) to monitor supply
chain stakeholders, and SBOMs, too, can be incomplete. However, open source allows anyone to access
and review the source code, enabling a community-driven approach to identifying and fixing bugs or
vulnerabilities.
6. Speeds up problem-solving in the software development process

When developers encounter a bug or an issue in closed source software, they have limited options for
finding a solution. They often rely on customer support from the vendor, which can be time-consuming and
may not always provide satisfactory results.

In contrast, open source software allows developers to access the source code and collaborate with other
community members facing similar challenges.

This enables a faster resolution of problems as multiple minds work together to identify and fix issues
swiftly. The collective knowledge and diverse perspectives within the community contribute to an
accelerated problem-solving process, benefiting both individual developers and the wider software
development ecosystem. This is also a great way to find solutions to new and unprecedented problems.
7. Supports cybersecurity testing

In the world of software development, cybersecurity is a critical concern. Open source software plays a
crucial role in supporting application security testing. With open source software, developers can access
the underlying code and actively identify and fix security vulnerabilities. This allows for thoroughly
examining the software’s security measures, making detecting any potential weaknesses or flaws easier.

Moreover, open source projects often benefit from a large community of users and developers who
collaborate on identifying and resolving security issues efficiently. This collective effort helps ensure that
any vulnerabilities are quickly addressed through regular updates and patches. The availability of public
repositories enables continuous monitoring by security experts worldwide.
Pros and Cons of Open Source Software

Despite the importance of open source, OSS is not without its share of challenges. Let us take an objective
look at the pros and cons of open source software to decide if it is right for you:
Pros of open source software

The benefits of open source software are:


1. Lower cost

Open source projects are typically developed and maintained by a community of volunteers who share
their skills and knowledge for free. This means anyone can access and use the software without paying
hefty licensing fees or upfront costs.

Moreover, since the source code is available to everyone, businesses can modify and customize the
software according to their specific needs, eliminating the need for expensive proprietary software as a
service (SaaS) solutions.
2. Ease of integration
Unlike closed source software, which often requires proprietary application programming interfaces (APIs)
and protocols, open source software promotes interoperability and compatibility with other systems. This
means developers can seamlessly integrate different components or modules from various sources without
facing major hurdles.
3. No vendor lock-in

With OSS, there is no vendor lock-in. This means users are not tied to a single provider or limited by
proprietary formats or protocols. Developers are free to modify and customize the software according to
their specific needs without any restrictions imposed by a single vendor.

Additionally, it ensures that users can easily switch between different vendors if they find one better suited
to their requirements or if they encounter any issues with the current provider. This flexibility ultimately
leads to cost savings and improved efficiency in the long run.
4. Greater flexibility

Developers have access to the underlying source code, giving them the freedom to make any necessary
changes or enhancements. This flexibility empowers organizations and individuals to tailor the software to
meet their unique requirements, whether adding new features or integrating with other systems. The
ability to customize open source software makes it a versatile solution for various applications across
various industries.

This inherent flexibility in open source software ensures that businesses can build agile IT infrastructures
that evolve alongside their changing needs—a valuable advantage that closed source alternatives may not
offer.
5. The power of community

Unlike closed source software, where development and improvement are limited to a specific team or
company, open source projects benefit from a global community of developers, users, and enthusiasts. The
power of community lies in its ability to harness the collective intelligence of passionate individuals who
share a common goal: creating high-quality software accessible to all.

See More: What Is Agile Software Development? Life Cycle, Methodology, and Examples
Cons of open source software

Open source software, despite its many advantages, also has some drawbacks that users should be aware
of:
1. No prompt support

Open source software often relies on community forums and user-driven discussions for troubleshooting
and problem-solving. While these forums can be helpful in many cases, they may not always provide
immediate or timely responses to users’ queries or issues. This can be frustrating for individuals or
businesses requiring urgent technical assistance.

It’s important to consider this aspect before choosing open source software, especially if your organization
requires a high level of technical support and quick resolution for any potential problems that may arise
during usage.
2. Complexity and difficult learning curve
Unlike closed source software, which often comes with user-friendly interfaces and comprehensive
documentation, open source software might require some technical expertise to navigate effectively.

The sheer flexibility and customization options offered by open source software can lead to higher
complexity. Users may need to invest time in understanding the intricacies of the software’s framework
and architecture, configuration settings, and dependencies. This can be daunting for those unfamiliar with
coding or with limited technical knowledge.
3. Limited features

Open source software (OSS) offers numerous benefits, but it’s important to acknowledge that there can
also be limitations. One of these is the potential for limited features in certain OSS projects. This is because
OSS development relies on community contributions and volunteer efforts, which may result in prioritizing
core functionalities over additional features.
4. High maintenance needs

Since these projects rely on community contributions and updates, they require regular upkeep to ensure
compatibility and security. This includes regularly monitoring for updates, bug fixes, and security patches.
Open source applications can become vulnerable to security breaches or compatibility issues with other
software components without proper maintenance.

Additionally, because multiple contributors are involved in the development of open source projects,
coordinating updates can be more complex compared to closed source alternatives, where a single vendor
oversees all aspects of maintenance.
5. Less stable builds

The open nature of OSS means that anyone can modify and update the code, which can lead to unintended
consequences. As a result, users may experience occasional crashes or glitches while using open source
applications. However, passionate developers within the community work diligently to address these issues
and release patches and updates to improve stability over time.

See More: What Is Integrated Development Environment (IDE)? Meaning, Software, Types, and Importance
Open Source Software Examples

There are numerous examples of open source software that have made a significant impact in the tech
industry. These include:

VLC Media Player: VLC Media Player, developed by VideoLAN, is a highly popular open source media
player that supports a wide range of audio and video formats. With its humble beginnings in 1996 as an
academic project at École Centrale Paris, VLC has become one of today’s most widely used media players.
GIMP: GIMP, short for GNU Image Manipulation Program, is a powerful open source image editing
software. The history of GIMP dates back to 1995 when Spencer Kimball and Peter Mattis developed the
software as a class project at the University of California, Berkeley. Over the years, it has evolved into a
highly versatile tool used by graphic designers, photographers, and artists worldwide.
Mozilla Firefox: Mozilla Firefox is a popular web browser that has gained immense popularity among
users worldwide. It was created by the Mozilla Foundation and was initially released in 2004 as an open
source project.
Linux: Linux is a powerful open source operating system that has revolutionized the computing world.
Developed by Linus Torvalds in 1991, Linux was initially created as an alternative to proprietary operating
systems like Windows and macOS. It is based on the Unix operating system and is designed to run on a
wide range of devices, from servers to Raspberry Pi.
Apache HTTP Server: The Apache HTTP Server, commonly known as Apache, was created by a group of
developers in 1995 to provide a robust and reliable platform for hosting websites. Since its inception, it has become
one of the most popular web servers globally, commanding over half of the market share.

Introduction to Linux Operating System


Linux: From supercomputers to smartphones. Explore the open source OS powering innovation. Discover popular
distros like Ubuntu and Fedora. Learn why Linux matters.

Jan 11th, 2025 8:00am by TNS Staff

What Is Linux?

Linux is a free, open source operating system that is not only used on millions of desktops across the globe
but also serves as the backbone for the internet, the cloud, servers, supercomputers, smartphones, smart
devices and so much more.

At its foundation, the Linux operating system revolves around the Linux kernel initially created by Linus
Torvalds back in 1991. In contrast to closed systems such as Microsoft’s Windows, Linux allows anyone to
download and view the code of everything from the kernel all the way to user applications. This model has
helped to foster a thriving development community around access but also makes it possible for enterprise
businesses to use the code and contribute back to the efforts of open source teams everywhere.
The Evolution of Linux Operating System

Linux has transformed over time from a hobby project started by a Finnish student to a powerful system
that drives much of the internet’s backbone. Both individuals and companies such as the Free Software
Foundation, Red Hat, and Canonical have played roles in its development. This growth has resulted in the
emergence of distributions. Versions of the operating system customized for specific purposes, as well as
more general-purpose desktop distributions such as Ubuntu, Fedora and Debian.

Linux in the Computing World

Linux holds a role in the world of computing that cannot be emphasized enough. Its reputation for stability,
security and versatility has made it a top choice for systems and development environments. With support
for a wide range of hardware and network setups, Linux proves adaptable for a range of applications,
whether it’s running web servers, managing cloud environments, development or handling intricate
multicluster deployments.

The open source nature of Linux creates an environment for innovation. Developers have unrestricted
access to the kernel source code, enabling them to tune, optimize and fortify systems based on their
operational requirements and preferences. This level of accessibility has also cultivated an assortment of
software and tools that contribute to Linux’s standing as a cornerstone of computing.

The Linux Kernel: Heart of the Operating System

The Linux kernel serves as part of the Linux operating system, overseeing resource management and
hardware operations such as memory allocation and device management. It acts as a connection point
between applications and the underlying hardware processes. In contrast to Windows NTs hybrid kernel
approach, Linux uses a kernel that consolidates all functions into a unified entity. This architecture
enhances performance. It provides access to hardware essential for efficient computing activities. With the
Linux kernel’s modular approach, users and administrators can add or remove modules as needed, to
expand capabilities and even strengthen security.

Open Source Operating System: A Collaborative Framework

The Linux kernel and distributions are distributed via open source licenses, which means the source code is
available for developers to review, tweak and share. This openness encourages enhancements and
teamwork with contributions coming in from developers globally. The transparency of open source
principles boosts system security by inviting scrutiny and drives innovation by tapping into shared
knowledge and skills.

TRENDING STORIES

1. Ken Thompson Recalls Unix's Rowdy, Lock-Picking Origins


2. Linux Distros: Year in Review
3. What Is Omarchy Linux, and Why Is 37signals Moving to It?
4. Ubuntu Budgie 25.04: One of the Best Desktops on the Market
5. The Best Office Suites for Linux
Linux Operating System vs. Other Operating Systems

Linux is often compared to operating systems, such as UNIX and Windows. While Linux has roots in
UNIX, it stands out as a free option inspired by the GNU project led by Richard Stallman. Unlike
proprietary systems like Windows, Linux empowers developers and users with extensive customization
options and control essential for optimizing systems based on unique performance or security requirements.
Moreover, Linux’s efficient command line interface (CLI) serves as a resource for managing systems,
creating flexible scripts and granting users direct access to advanced functionalities.

Popular Linux Distributions


Overview of Major Linux Distributions

Linux distributions, often simply called “distros,” are customized versions of the Linux operating system
tailored to meet diverse user requirements. From desktops to servers, each distro offers a unique
combination of the core Linux kernel with a set of applications, a package management system, and a user
interface. Some of the most widely used distributions include:

 Ubuntu: Ubuntu is widely recognized for its ease of use and robust backing, from the community making it
a top choice among both novices and seasoned users in the realm of Linux distributions. Built upon Debian,
Ubuntu is versatile and ideal for settings such as desktops, servers and cloud platforms.
 Debian: Debian is highly regarded for its stability and security, making it a popular choice as the base for
many distributions, like Ubuntu and Linux Mint. Developers and system administrators favor Debian for its
strong foundation..
 Fedora: Fedora, well known for its speed and bleeding-edge approach, is a project led by a community that
acts as a platform to test out technologies, many of which eventually find their place in Red Hat Enterprise
Linux.
 Red Hat Enterprise Linux (RHEL): RHEL provides top-notch support, thorough documentation and a
reliable, safe setting for business applications as part of its distribution.
 Linux Mint: Mint is a choice for many users switching from Windows because of its user-friendly design and
seamless compatibility with various hardware.
Zoom

Data from 58,600 participants in Stack Overflow’s 2024 Developer Survey shows how many developers
use various operating systems (including Linux distros like Ubuntu and Debian) in both their professional
and private lives.

Unique Features and Uses of Each Distribution

Each Linux distribution caters to specific needs:

 Ubuntu is well known for its user installation process and wide range of software options available. It is an
option for software development, with recent updates that offer strong support for container and cloud
technologies.
 Debian provides a wide range of packages in its main repository but can be expanded with other third-party
“repos.” Debian emphasizes the importance of free software and high stability, which makes it well-suited
for servers and embedded systems.
 Fedora explores possibilities by incorporating cutting-edge open source technologies catering to developers
keen on leveraging the innovations within the Linux environment.
 In settings where reliability and robust support are essential, RHEL offers extended support periods and a
stable platform.
 Linux Mint is frequently praised for its multimedia capabilities and user-friendly nature, making it a solid
choice for computing tasks.

How Distributions Cater to Different User Needs

There are types of Linux distributions each tailored to meet the needs of users whether they are casual
desktop users, hardcore developers, or large enterprises. Selecting a distribution can have an influence on
system administration, security measures, compatibility with software, and the range of available
applications all of which can directly influence productivity levels and the overall user experience.

Linux for Development and Deployment


Linux in Software Development

Linux is highly valued in the world of software development for its strength, clarity and adaptability.
Developers appreciate Linux for its command line interface, which provides control over development
tools and system resources. The open source nature of Linux allows developers to tailor their operating
environment to meet project requirements, whether it involves tweaking the kernel or customizing software
stacks.
In Linux, you can find a variety of programming environments, integrated development environments
(IDEs), and compilers that are widely accessible and frequently updated, which makes Linux a dynamic
platform for creating applications in languages like Python, Java, Go, Rust, C++, and many
others. Furthermore, Linux’s compatibility with an array of software and hardware makes it an excellent
choice for platform development.

Linux and DevOps

In the world of DevOps, Linux truly shines with containers and orchestration tools like Docker and
Kubernetes. These technologies play a role in enabling continuous integration and continuous deployment
(CI/CD) practices and empowering developers and operations teams to efficiently create, deploy, and
manage applications across various environments.

Moreover, Linux offers an array of automation tools, such as Ansible, Puppet and Chef that aid in
simplifying configuration management and operational tasks. These tools contribute to streamlining the
DevOps workflow. With its reliability and scalability, Linux remains a player in driving DevOps
advancements by supporting agile development methodologies and swift deployment processes.

Linux in Cloud Computing

Linux holds a robust presence in the realm of cloud computing. It is the choice for public cloud providers
such as Amazon Web Services (AWS), Google Cloud Platform (GCP), and Microsoft Azure, all of which
offer services and virtual machines based on Linux. The popularity of Linux in this field can be attributed
to its cost-effectiveness, performance, security, flexibility and scalability.

By using Linux-based cloud solutions, businesses can take advantage of virtualization and containerization
technologies to optimize resource utilization and minimize expenses. The robust security features of the
operating system, along with its capability to manage workloads efficiently, make it a suitable option for
running data applications, web services and large-scale enterprise systems.

Advanced Linux Features


Security Features and User Access Control

Linux is well known for its security measures, which are essential for handling multiple users and
safeguarding sensitive information. One standout feature is Security Enhanced Linux (SELinux), originally
created by the National Security Administration (NSA), which offers support for access-control security
policies, including Mandatory Access Controls (MAC) that surpass traditional Discretionary Access
Controls (DAC) systems.

Moreover, Linux’s permission and user-role system add a layer of security by enabling system
administrators to specify resource access permissions. These capabilities allow developers to customize
Linux for an operating environment capable of protecting applications from unauthorized entry and
potential vulnerabilities.
Customizing the Linux Kernel

Linux offers an advantage, with its kernel allowing developers to tailor it for better performance, improved
hardware compatibility or the addition of new features. This flexibility is crucial for crafting computing
setups or for embedded systems with minimal resources. Moreover, Linux’s open source design provides
documentation and community assistance, which enable modifications at the kernel level. These factors
position Linux as a choice for fostering innovation and exploration, in all types of computing scenarios.

Automation and Scripting via the Command Line Interface

Linux’s command line interface (CLI) is a tool that empowers users to handle software packages and
manage hardware resources effectively. Popular scripting languages such as Bash and Python are well
supported on Linux and make it possible to simplify automation and system management tasks. Developers
benefit from the CLI’s automation capabilities boosting efficiency and accuracy in software development
processes. Additionally, the CLI accommodates programming methods and procedures, serving as a tool
for contemporary DevOps practices.

Linux Package Management


Understanding Package Managers

In Linux, package managers play a role by automating tasks, like installing, updating and uninstalling
software. They manage dependencies to prevent conflicts during installation and keep track of all installed
software for system maintenance. Some popular package managers are:

 APT (Advanced Package Tool): Used primarily by Debian and its derivatives like Ubuntu, APT simplifies the
process of managing software by automating the retrieval, configuration, dependency resolution, and
installation of software packages from repositories.
 YUM (Yellowdog Updater, Modified) and DNF: These package managers are used by distributions such as
Fedora, AlmaLinux, and Red Hat Enterprise Linux (RHEL). One thing to keep in mind is that yum has been
deprecated in favor of dnf. Although yum is still usable, it is advised to make the switch to dnf.
 Pacman: The package manager for Arch Linux, known for its speed and simplicity, which manages packages
more dynamically by tracking every installed file.

Installing and Managing Software Packages

Linux package-management systems make it easy to install software directly from maintained repositories,
which contain thousands of pre-built packages. For example, using APT, a user can install software with
commands like sudo apt-get install [package-name], and similarly, with DNF, a user might use udo
dnf install [package-name].

These tools also allow for easy updates and maintenance. Regular commands such as sudo apt-get
update && sudo apt-get upgrade or sudo dnf update ensure that all software on the system is up to
date, reducing security risks and improving stability.
Differences in Package Management Across Distributions

The functions of package managers are similar in how they handle software management. However, they
differ notably in their command formats and the repositories they can access. For example, Debian-based
systems typically offer repositories with a selection of software options, whereas Arch Linux prioritizes
simplicity and user empowerment by providing cutting-edge software that requires more hands-on
involvement.

The selection of a package manager can impact aspects from system security with updates to accessing the
latest software functionalities. For developers, it is essential to grasp these distinctions to opt for a
distribution that aligns best with their development requirements, particularly when specific libraries or
software versions are necessary for their projects.

Linux User Interface Options


Graphical User Interfaces (GUIs)

Linux provides a variety of graphical user interfaces that are particularly attractive, to users who are
familiar with visually driven operating systems such as Windows or macOS. Some of the more popular
desktop environments for Linux are:

 GNOME: Known for its minimal approach, simplicity, and functionality, GNOME is the default desktop
environment for many major Linux distributions, such as Fedora and Ubuntu. It offers a streamlined and
modern user experience with a focus on usability and accessibility.
 KDE Plasma: Celebrated for its configurability and robust feature set, KDE Plasma is for users who prefer a
highly customizable and beautiful desktop experience. It provides extensive visual customization options,
making it attractive for users who want to tailor every aspect of their interface.
 XFCE and LXDE: These environments are favored for their light resource usage and high customization,
making them ideal for older hardware or systems where performance is a priority over visual flair.
 Cinnamon: This desktop environment is ideal for anyone who prefers the traditional Windows-like desktop,
consisting of a desktop menu, panel, system tray and clickable desktop icons.

Command Line Interface (CLI)

The command line interface is still a tool for Linux users, particularly developers and system
administrators. Unlike user interfaces (GUIs), the CLI allows access to system functions and scripts,
providing a more efficient method for executing intricate tasks.

 Bash: The most common Linux shell, Bash is a powerful tool for managing files, running software, and
programming scripts. It is highly valued for its efficiency and the extensive control it offers over the system.
 Zsh: Known for its improvements over Bash, such as better auto-completion and customizable
appearances, Zsh is favored by users who spend a lot of time in the terminal and seek an enhanced
interactive experience.
Customizing the User Environment

Linux is known for its customization options. Users have the flexibility to personalize their system
according to their preferences or productivity needs with tools/apps such as:

 Conky: A tool that shows information on the screen, like CPU usage, disk status, email alerts and weather
updates.
 Docky: A dock software that simplifies launching apps and handling Windows efficiently.
 Compiz: A Windows manager that elevates the effects of the Linux interface, with animations and smooth
Windows transitions.

Networking and Linux


Configuring Linux for Networking

Linux’s versatility shines in networking, where it serves as a robust platform for configuring and managing
network operations. Linux systems can be tailored to function as network routers, firewalls, gateways and
servers. Key networking functions in Linux are managed through utilities like netstat, ss, ip, ufw and
firewall-cmd, which allow for detailed control over network interfaces, traffic routing, and firewall
settings.

Linux supports a wide range of networking protocols, from IP to SMB and NFS, making it capable of
interacting in diverse networked environments. Additionally, advanced tools like nftables provide newer,
more flexible ways to manage network packets and routes.

Tools and Commands for Network Management

Linux comes equipped with powerful tools that help in monitoring and managing network traffic:

 Wireshark: This GUI-based network protocol analyzer lets users capture and interactively browse the traffic
running on a computer network.
 tcpdump: A command-line packet analyzer used for network diagnostics and troubleshooting.
 iperf3: A tool for active measurements of the maximum achievable bandwidth on IP networks.

These tools enable developers and system administrators to diagnose network issues, monitor traffic flows
and ensure security protocols are being followed effectively.

Integration with Other Operating Systems and Networked Environments

Linux is highly effective, in settings where there is a need for multiple operating systems to work together.
Tools such as Samba make it easy for Linux servers to share files and printers with Windows computers
seamlessly. Similarly, NFS (Network File System) allows files to be shared among Linux machines,
promoting collaboration in environments with a mix of operating systems.

Moreover, Linux can seamlessly integrate into virtualized setups, often serving as a guest operating system
on hypervisors like VMware ESXi, Microsoft Hyper V and Oracle VirtualBox. This adaptability is key for
businesses that operate with a variety of operating systems and require a platform that can smoothly
interact with technologies.

Linux Community and Resources


Support Forums and Online Communities

The Linux community is vast and active, offering an array of support forums, discussion groups, and online
resources that foster collaboration and knowledge sharing. Key platforms include:

 LinuxQuestions.org: A comprehensive forum where users of all skill levels can find answers to technical
issues, share experiences, and discuss Linux-related topics.
 Stack Exchange: Sites like Ask Ubuntu, Unix & Linux Stack Exchange, and Server Fault provide platforms for
problem-solving, with community-driven Q&A tailored to specific needs and challenges.
 Reddit: Subreddits like r/Linux, r/Ubuntu and r/Fedora are bustling with discussions, advice, and the latest
news, making them valuable for staying updated and connected with the community.

These forums are not just about troubleshooting; they are vibrant hubs where enthusiasts and professionals
alike share projects, tutorials and personal experiences, contributing to the collective knowledge pool.

Contribution to Linux Development

Linux thrives on community contributions, which span from development to documentation. Individuals
and organizations can contribute to various aspects of Linux:

 Kernel development: Contributors can help improve the core functionalities of the Linux kernel by adding
features, fixing bugs or optimizing performance.
 Distribution development: Many distributions encourage users to contribute to packaging, testing and
artwork, among other areas.
 Documentation: High-quality documentation is crucial for user support and software development.
Contributions help maintain and expand these resources, making Linux more accessible to newcomers.

Noteworthy platforms for development collaboration include GitHub and GitLab, where many Linux
projects are hosted. Contributors can fork projects, push updates, and collaborate with developers from
around the world.

Learning Resources and Further Education Opportunities

Linux offers extensive educational resources for all levels of expertise:

 Official documentation and tutorials: Most Linux distributions provide detailed manuals and tutorials that
are invaluable for both beginners and advanced users.
 Online courses: Platforms like Coursera, edX, and Udemy offer courses on Linux fundamentals, system
administration, networking, and security.
 Certifications: Certifications like the CompTIA Linux+ and the Red Hat Certified System Administrator
provide structured learning paths and are recognized credentials that can boost professional careers.
These resources not only help individuals improve their technical skills but also support career
advancement in IT fields where Linux proficiency is valued.

Latest Developments and Future Trends


The Latest Linux Releases and Their New Features

Linux continues to evolve, with regular updates and new features across various distributions:

 Ubuntu: Recent releases have focused on enhancing support for cloud computing and containers, with
improved Kubernetes integration and updated toolchains for developers.
 Fedora: Known for staying at the forefront of innovation, Fedora has recently introduced new security
features and enhanced system performance capabilities to cater to both developers and enterprise users.
 Arch Linux: Continuously rolling out updates, Arch has improved its package management system and user
utilities, providing an even more streamlined and flexible user experience.

These updates are driven by feedback from the community and the ongoing need to support newer
hardware and software standards.

Emerging Trends in the Linux Ecosystem

Several trends are shaping the future of Linux:

 Linux on mobile: Projects like the Android Open Source Project (AOSP) and efforts by Purism, with its
Librem 5 smartphone, emphasize the potential for Linux in the mobile domain. These initiatives aim to
bring the robustness and flexibility of Linux to mobile devices, offering an open-source alternative to the
dominant iOS and Android platforms.
 Increased focus on security: With cyber threats becoming more sophisticated, Linux is increasingly focusing
on enhancing security. Features like Kernel Lockdown and improvements to SELinux are making Linux more
secure for all users.
 Containerization and microservices: The rise of Docker and Kubernetes has highlighted the importance of
Linux in the containerization ecosystem. Linux’s lightweight nature and strong isolation features make it
ideal for running containerized applications, a trend that continues to grow in software development and
deployment.

Future Directions for Linux Distributions

Looking ahead, Linux distributions are likely to focus on several key areas:

 Sustainability and system stability: Efforts will be made to ensure that Linux distributions remain
sustainable and stable, supporting older hardware while also accommodating the needs of modern
systems.
 Enhanced user experience: With the increasing adoption of Linux on desktops, distributions will likely
continue to polish user interfaces and improve usability to appeal to a broader audience.
 Integration with emerging technologies: As technologies like artificial intelligence (AI) and the Internet of
Things (IoT) continue to evolve, Linux distributions will likely integrate more tools and features to support
developers and businesses in these areas.
Conclusion: The Enduring Importance of Linux in Modern Computing

Linux continues to be an element of contemporary computing, fueling progress in areas ranging from
software creation to cloud architecture. Its open source design, strong security capabilities and adaptable
settings position it as the pick for IT experts, developers and tech aficionados globally.

Recap of Linux’s Importance

 Versatility and power. Linux’s ability to run on a wide range of hardware, from supercomputers to mobile
devices, and its pivotal role in server management and cloud computing underscore its versatility and
power.
 Community and collaboration. The vibrant Linux community continues to be a source of innovation and
support, offering resources, guidance, and a collaborative environment for users of all skill levels.
 Continual evolution. Regular updates and the introduction of new features ensure that Linux remains
relevant and on the cutting edge of technological advancements.

Introduction to the Linux Operating System¶


In this chapter, you will learn about GNU/Linux distributions.

Objectives: In this chapter, you will learn how to:

Describe the features and possible architectures of an operating system.

Recount the history of UNIX and GNU/Linux.

Choose the right Linux distribution for your needs.

Explain the philosophy of Free and Open-source Software.

Discover the usefulness of the shell.

generalities, linux, distributions

Knowledge:

Complexity:

Reading time: 10 minutes


What is an operating system?¶

Linux, UNIX, BSD, Windows, and MacOS are all operating systems.

Abstract

An operating system is a set of programs that manages the available resources of a computer.

As part of this management of resources, the operating system has to:

 Manage the physical or virtual memory.


o The physical memory is made up of the RAM bars and the processor cache memory, which
are used for program execution.
o The virtual memory is a location on the hard disk (the swap partition) that allows the
unloading of the physical memory and the saving of the current state of the system during
the electrical shutdown of the computer.
 Intercept access to peripherals. Software can rarely access hardware directly (except for graphics
cards for specific needs).
 Provide applications with proper task management. The operating system is responsible for
scheduling processes to occupy the processor
 Protect files from unauthorized access.
 Collect information about programs in use or in progress.
Generalities UNIX - GNU/Linux¶
History¶

UNIX¶

 1964 — 1968: MULTICS (MULTiplexed Information and Computing Service) is developed for
MIT, Bell Labs (AT&T) and General Electric.
 1969 — 1971: After the withdrawal of Bell (1969) and then General Electric from the project, two
developers, Ken Thompson and Dennis Ritchie (joined later by Brian Kernighan), judging
MULTICS to be too complex, begin development of UNIX (UNiplexed Information and
Computing Service). While it was created in Assembly language, the creators of UNIX eventually
developed the B language and then the C language (1971) and completely rewrote UNIX. As it was
developed in 1970, the reference (epoch) date for the start of time of UNIX/Linux systems is set at
January 01, 1970.

C remains one of the most popular programming languages today. A low-level language close to the
hardware, it allows the operating system to be adapted to any machine architecture having a C compiler.

UNIX is an open and evolving operating system that has played a major role in the history of computing. It
forms the basis for many other systems, such as Linux, BSD, MacOS, etc.

UNIX remains relevant today (HP-UX, AIX, Solaris, etc.).

GNU Project¶

 1984: Richard Matthew Stallman launched the GNU (GNU's Not Unix) Project, which aims to
establish a free and open Unix system, in which the more important tools are: gcc compiler, bash
shell, Emacs editor and so on. GNU is a Unix-like operating system. The development of GNU,
started in January 1984, is known as the GNU Project. Many of the programs in GNU are released
under the auspices of the GNU Project; those we call GNU packages.
 1990: GNU's own kernel, the GNU Hurd, was started in 1990 (before Linux was started).

MINIX¶

 1987: Andrew S. Tanenbaum develops MINIX, a simplified UNIX, to teach operating systems in a simple
way. Mr. Tanenbaum makes the source code of his operating system available.

Linux¶

 1991: A Finnish student, Linus Torvalds, creates an operating system that runs on his personal
computer and names it Linux. He publishes his first version, called 0.02, on the Usenet discussion
forum, and other developers help him improve his system. The term Linux is a play on words
between the founder's first name, Linus, and UNIX.
 1993: The Debian distribution is created. Debian is a non-commercial, community-based
distribution. Originally developed for use on servers, it is well-suited for this role; however it is a
universal system, usable on a personal computer as well. Debian forms the basis for many other
distributions, such as Mint or Ubuntu.
 1994: The commercial distribution Red Hat is created by the company Red Hat, which is today the
leading distributor of the GNU/Linux operating system. Red Hat supports the community version
Fedora and until recently the free distribution CentOS.
 1997: The KDE desktop environment is created. It is based on the Qt component library and the C+
+ development language.
 1999: The GNOME desktop environment is created. It is based on the GTK+ component library.
 2002: The Arch distribution is created. Its distinctive is that it offers rolling release (continuous
update).
 2004: Ubuntu is created by the Canonical company (Mark Shuttleworth). It is based on Debian but
includes free and proprietary software.
 2021: Rocky Linux is created, based on Red Hat distribution.

Info

Dispute over the name: although people are accustomed to calling the Linux operating system verbally,
Linux is strictly a kernel. We must not forget the development and contribution of the GNU project to the
open source cause, so! I prefer to call it the GNU/Linux operating system.

Market share¶

Despite its prevalence, Linux remains relatively unknown to the general public. Linux is hidden within
smartphones, televisions, internet boxes, etc. Almost 70% of the websites in the world are hosted on a
Linux or UNIX server!

Linux equips about 3% of personal computers but more than 82% of smartphones. The Android
operating system, for example, uses a Linux kernel.

Linux equips 100% of the top 500 supercomputers since 2018. A supercomputer is a computer designed to
achieve the highest possible performance with the techniques known during its design, especially
concerning computing speed.

Architectural design¶

 The kernel is the first software component.


o It is the heart of the Linux system.
o It manages the hardware resources of the system.
o The other software components must go through it to access the hardware.

 The shell is a utility that interprets user commands and ensures their execution.
o Main shells: Bourne shell, C shell, Korn shell, and Bourne-Again shell (bash).

 Applications are user programs including but not limited to:


o Internet browsers
o Word processors
o Spreadsheets

Multi-task¶

Linux belongs to the family of time-sharing operating systems. It divides processing time between several
programs, transparently switching from one to another for the user. This implies:

 Simultaneous execution of several programs.


 Distribution of CPU time by the scheduler.
 Reduction of problems caused by a failed application.
 Reduced performance in the event of too many programs running.

Multi-user¶

MULTICS's purpose was to allow users to work from several terminals (screen and keyboard) on a single
computer (which was very expensive at the time). Inspired by this operating system, Linux kept this ability
to work with several users simultaneously and independently, each with its user account with memory
space and access rights to files and software.

Multi-processor¶

Linux can work with multi-processor computers or with multi-core processors.

Multi-platform¶

Linux is written in a high-level language that can be adapted to different platforms during compilation.
This allows it to run on:

 Home computers (PC and laptop)


 Servers (data and applications)
 Portable computers (smartphones and tablets)
 Embedded systems (car computers)
 Active network elements (routers and switches)
 Household appliances (TVs and refrigerators)

Open¶

Linux is based on recognized standards such as POSIX, TCP/IP, NFS, and Samba, which allow it to share
data and services with other application systems.

The UNIX/Linux Philosophy¶

 Treat everything as a file.


 Value portability.
 Do one thing and do it well.
 KISS: Keep It Simple Stupid.
 "UNIX is a simple operating system, but you have to be a genius to understand the simplicity." (Dennis
Ritchie)
 "Unix is user-friendly. It just isn't promiscuous about which users it's friendly with." (Steven King)

The GNU/Linux distributions¶

A Linux distribution is a consistent set of software assembled around the Linux kernel, ready to be
installed along with the necessary components to manage itself (installation, removal, configuration). There
are associative or community distributions (Debian, Rocky) and commercial distributions (Red Hat,
Ubuntu).

Each distribution offers one or more desktop environments, and provides a set of pre-installed software
and a library of additional software. Configuration options (kernel or services options for example) are
specific to each distribution.

This principle allows distributions to be geared to beginners (Ubuntu, Linux Mint...) or fully customizable
for advanced users (Gentoo, Arch); distributions can also be more adept with servers (Debian, Red Hat)
or workstations (Fedora).

Desktop environments¶

There are many graphic environments such as GNOME, KDE, LXDE, XFCE, etc. There is something for
everyone, and their ergonomics hold their own against Microsoft or Apple systems.

So why is there so little enthusiasm for Linux, when this system is practically virus free? Could it be
because so many editors (Adobe) and manufacturers (Nvidia) do not play the free game and do not provide
a version of their software or drivers for GNU/Linux? Perhaps it's fear of change, or the difficulty of
finding where to buy a Linux computer, or too few games distributed under Linux. That last excuse, at
least, shouldn't be true for long, with the advent of the game engine Steam for Linux.
The GNOME 3 desktop environment no longer uses the concept of desktop but that of GNOME Shell (not
to be confused with the command line shell). It serves as a desktop, a dashboard, a notification area and a
window selector. The GNOME desktop environment is based on the GTK+ component library.
The KDE desktop environment is based on the Qt component library. It is traditionally recommended for
users familiar with a Windows environment.
Free / Open Source¶

A Microsoft or Mac operating system user must purchase a license to use the system. This license has a
cost, although it is usually transparent (the price of the license is included in the price of the computer).

The Free Software movement provides mostly free distributions in the GNU/Linux world.

Free does not mean free!

Open Source: the source code is available, so consulting and modifying it under certain conditions is
possible.

A free software is necessarily open-source, but the opposite is not true since open-source software is
distinct from the freedom offered by the GPL license.

GNU GPL (GNU General Public License)¶

The GPL guarantees the author of a software its intellectual property, but allows modification,
redistribution or resale of software by third parties, provided that the source code is included with the
software. The GPL is the license that came out of the GNU (GNU is Not UNIX) project, which was
instrumental in creating Linux.

It implies:

 The freedom to run the program, for any purpose.


 The freedom to study how the program works and adapt it to your needs.
 The freedom to redistribute copies.
 The freedom to improve the program, and publish those improvements for the benefit of the whole
community.

On the other hand, even products licensed under the GPL can have a cost. This is not for the product itself,
but the guarantee that a team of developers will continue to work on it to make it evolve and
troubleshoot errors, or even provide support to users.

Areas of use¶

A Linux distribution excels for:

 Servers: HTTP, email, groupware, file sharing, etc.


 Security: Gateway, firewall, router, proxy, etc.
 Central computers: Banks, insurance, industry, etc.
 Embedded systems: Routers, Internet boxes, SmartTVs, etc.

Linux is a suitable choice for hosting databases or websites, or as a mail server, DNS or firewall. In short,
Linux can do just about anything, which explains the quantity of specific distributions.
Shell¶
Generalities¶

The shell, known as command interface, allows users to send commands to the operating system. It is less
visible today since the implementation of graphical interfaces, but remains a privileged means on Linux
systems which do not all have graphical interfaces and whose services do not always have a setting
interface.

It offers a real programming language including classical structures (loops, alternatives) and common
constituents (variables, passing of parameters, and sub-programs). It allows the creation of scripts to
automate certain actions (backups, creation of users, system monitoring, etc.).

There are several types of shells available and configurable on a platform or according to the user's
preference. A few examples include:

 sh, the POSIX standard shell


 csh, command-oriented shell in C
 bash, Bourne-Again Shell, Linux shell

Functionalities¶

 Command execution (checks the command given and executes it).


 Input/Output redirection (returns data to a file instead of writing it on the screen).
 Connection process (manages the user's connection).
 Interpreted programming language (allowing the creation of scripts).
 Environment variables (access to information specific to the system during operation).
Principle¶

Check your Knowledge¶

Introduction

Linux is a popular UNIX-based operating system. It is an open-source whose freely available code can be
used freely. Numerous versions of Linux are already available on the internet for use. Since Linux is an
open-source operating system, with enough knowledge one can customize it as per their needs rather
easily.

In this article, we will be reading the features and the architecture of a linux operating system in complete
detail.

What are the Features of Linux Operating Systems?

Here is the list of top features of the Linux Operating system:


1. Free and Open Source

2. Multiuser Capacity

3. Multitasking

4. Security

5. Graphical User Interface (GUI)

6. File System

7. Application Support

8. Frequent New Updates

9. Portability

10. Performance

11. Lightweight Infrastructure

12. Live CD/USB

13. Support's customized keyboard

14. Compatible with cloud computing

15. Interoperability

16. Shell

1. Free and Open Source

This Linux code is freely available to all, and it's a community-based development project which helps the
user to modify the code or analyze the codes and redistribution of codes.

2. Multiuser Capacity

In Multiuser Capacity, Linux allows its users to share the system resources such as RAM, hard drive, and
application program at same time. But they have to use it in different terminals.

3. Multitasking

Multitasking allows multiple applications to run simultaneously by effectively dividing the CPU time.
Examples of multitasking are UNIX, IBM’s OS/390, Windows Vista, Windows XP, and Windows 7, 8, 9,
and 10.
4. Security

It secures data in three ways:


Authentication: By using a password and login ID
Authorization: By using read, write and execute permissions
Encryption: It converts the files into an unreadable format.

5. Graphical User Interface (GUI)

It is a command line that can be converted into a Graphical User Interface by installing some packages.
The most popular method for getting a GUI in a Linux system is logging into a Ubuntu server and
installing its desktop environment.

6. File System

It provides a hierarchical system to arrange files and directories. The folders are classified into binary
directories, configuration directories, data directories, and memory directories based on the type of files
they contain.

7. Application Support

It consists of a software repository for users to download and install several applications, which gives the
user a vast field of applications to download the application of their choice.

8. Frequent New Updates

Linux operating systems receive frequent updates, including security patches, bug fixes, and new features,
ensuring ongoing improvements and staying up-to-date with evolving technology.

9. Portability

Here the term portability doesn't mean the smaller size. Here, it means that Linux supports different kinds
of hardware, which means that the software can perform similarly on different types of hardware.

10. Performance

Linux operating systems are known for their performance, offering high stability, efficiency, and
scalability, making them widely used in various applications.

11. Lightweight Infrastructure

Linux can be configured into a lightweight infrastructure by using minimal resources, streamlined services,
and optimized kernel settings, ideal for resource-constrained environments or embedded systems.
12. Live CD/USB

Live CD/USB of a Linux operating system allows booting and running the OS from external media without
installation, useful for testing, recovery, or portable computing.

13. Support's customized keyboard

Linux offers support for customized keyboard layouts, allowing users to define and use specific key
mappings for various languages and preferences.

14. Compatible with cloud computing

Linux is highly compatible with cloud computing platforms, offering a wide range of distributions and
tools for cloud deployment, scaling, and management. It's a popular choice for cloud servers and
containers.

15. Interoperability

Linux demonstrates strong interoperability, allowing it to work seamlessly with various software, file
formats, and systems, promoting open standards and collaboration across diverse environments.

16. Shell

The Shell command-line interpreter on Linux acts as a line between the user and the kernel, which runs the
program known as commands. It is efficient and takes less time and space while executing the tasks.

Also read - File management in operating system

Components of the Linux System

Linux operating system has three primary components.

1. Kernel

The Kernel is the backbone of Linux. It is in control of the operating system's primary functions. It is made
up of various modules that interact directly with the hardware. The Kernel provides the needed abstraction
for system or application programs to mask low-level hardware specifics.

2. System Library

System libraries are unique functions or programs that allow application software or system utilities to use
the functionality of the Kernel. These libraries implement most of the operating system's features without
requiring kernel module code access.
3. System Utility

System Utility is a special type of program that is specialized to perform individual-level tasks.

4. Bootloader

Booting is the process through which computers startup. Your operating system controls this boot
procedure, which depends on what program opens on the boot. When you switch on your computer, the
bootloader for your operating system runs first.

5. Application Software

There are too many application requirements for the desktop environment which helps your Linux OS or
that you choose to install to satisfy them all. Individual applications are so installed. Most Linux
distributions, such as Ubuntu, provide dedicated app stores where users may search for and install
applications.

Also read - features of operating system

Why Use Linux?

Linux is much different from other operating systems in several ways.

 It is an Open Source Operating System that allows programmers to create their own bespoke operating
systems.

 It provides various applications with various characteristics from which to pick based on your requirements.

 A worldwide development community is looking at numerous methods to improve its security, which is
very safe and resilient. You don't need to scan it routinely with an anti-virus program. Linux is used by
companies such as Google, Amazon, and Facebook to defend their servers since it is very trustworthy and
stable.

 Above all, Linux is completely free, and you may install it on as many computers as you wish.

 An entirely trouble-free operating system does not cause viruses, spyware, or computer slowdown.

You can also read about layered structure of operating system.

Frequently Asked Questions


What are the main features of Linux Operating System?

The main features of the Linux operating system are:


1. Multiuser Capacity: Multiple users can share system resources such as RAM and hard drives. However, they
must run on distinct terminals.
2. Multitasking: Many functions may be done simultaneously by effectively dividing CPU time.

What are the main components of Linux?

The Kernel, Hardware layer, System library, Shell, and System utility are the main components of the
Linux Operating System's architecture. The Kernel is the most crucial operating system component since it
is responsible for all of LINUX's essential functions.

Which distribution of Linux is frequently used?

Fedora, SuSE, and Mandrake are the most popular and most accessible. Linspire has grown in popularity as
a pre-installed operating system for consumers who wish to buy a low-cost computer but don't have any
technical knowledge. It's a matter of personal choice as to which distribution is best.

What is the function of the Linux operating system?

Linux operating system performs several functions such as multitasking, security, networking, file
management, open-source development and many more. It serves as a powerful open-source operating
system that
is secure for performing various computing tasks.

What are the advantages of the Linux operating system?

There are various advantages of using the Linux operating system. Some advantages include open source,
security, free of cost, development, flexibility, security, and many more.

What is Linux? An in-depth introduction


 By Elvis Plesky
 February 5, 2024
 Various

14
Minutes

Linux is one of the most commonly used operating systems, serving as the backbone for a diverse array of
devices, from personal computers to servers and mobile phones. Linux has been around since the 1990s,
and it has since established a global presence, seamlessly integrating into virtually every imaginable
application and industry.

While the versatility of the Linux operating system is well known, many remain unaware of how
ubiquitous it is. In addition to supporting much of the internet, Linux OS is powering anything from TV
sticks to large appliances like refrigerators and elevators.
In this comprehensive introductory guide, we collected everything you need to know to learn if Linux is the
right fit for you, including its most common uses, basic terminology, a quick installation guide, and
answers to some of the most commonly asked questions about Linux OS. Whether you’re a complete
newbie or seeking to deepen your understanding, read on to learn more about the versatility and potential
of the Linux operating system.

Key Takeaways

 Linux is an open-source operating system known for its security, reliability, and flexibility. Its core kernel
manages hardware resources, process multitasking, and invites collaborative development under the
General Public License (GPL).
 There is a vast array of customizable Linux distributions and desktop environments, serving different needs
and preferences, from desktop computing and servers to gaming and embedded devices.
 Linux offers a secure and customizable alternative to other operating systems; it features an active
community for support and development; and it´s widely employed in various devices and enterprise
solutions.

Linux Operating System: a brief introduction

Serving as a liaison between software and hardware, an OS manages the intricacies of a computer’s
components. In the realm of operating systems like Linux or Windows, key components work in unison to
facilitate seamless functionality:

 Bootloader. Your computer needs to go through a startup sequence called booting. This boot process
needs guidance, and your OS is the software in control throughout the boot process. When you start your
computer the bootloader for your operating system kickstarts the process.
 OS Kernel. You can call the kernel the part of the operating system which is the “closest” to your computing
hardware as it is the part which controls the CPU, access to memory and any peripheral devices. It is the
“lowest” level at which your operating system works.
 Background services. Called “daemons” in Linux, these small applications act as servants in the
background, ensuring that key functions such as scheduling, printing and multimedia function correctly.
They load after you have booted up, or when you have logged into your computer.
 OS Shell. You need to be able to tell our operating system what to do, and this is the goal of the shell. Also
known as the command line, it is a facility which lets you instruct your OS using text. However few people
nowadays are familiar with command line code, and it once used to put people off using Linux. This
changed because a modern distribution of Linux will use a desktop shell just like Windows.
 Graphics server. This provides a graphical sub-system that renders images and shapes on your computer
monitor. Linux uses a graphical server called “X” or “X-server”.
 Desktop environment. You can’t interact with the graphical server directly. Instead you need software that
can drive the server. This is called a desktop environment in Linux and there are plenty of options including
KDE, Unity and Cinnamon. A desktop environment is usually bundled with a number of applications
including file and web browsers plus a couple of games.
 Applications. Obviously, the desktop environment which is bundled with your Linux OS or which you
choose to install cannot cater for every application need, there are too many. Individual applications,
however, can and there are thousands for Linux just like Windows and Apple’s OS X has thousands of
applications. Most Linux distros have app stores which help you find and install apps, for example Ubuntu
Software which comes with Ubuntu.
It’s worth noting that Ubuntu’s application repository, the Ubuntu software centre, is a great place to look
around for Linux applications, both free to use and paid to use.

Why use Linux software?

The desktop operating systems most of us use are typically bundled with our computers and we rarely
question why we need to change operating systems. Few people are interested in learning a new operating
system and rarely ask what Linux is simply because they feel their existing operating system does the job
just fine.

However, it is not always obvious how much time is lost in the process of battling common OS problems,
including malicious software such as viruses, frequent OS crashes, and the resulting costly repairs. Don’t
forget that most operating systems charge a license fee too.

Perhaps your existing choice of OS is not doing the job just fine. If you are tired of paying for an operating
system and hate the frequent, costly maintenance you have to do on your existing OS you might just want
to think about Linux and whether it offers a better, free alternative. There is no charge for trying Linux, and
many people will consider Linux to be the most reliable operating system for a desktop computer.

Costs: you can save by using Linux software

Because of the open-source, collaborative nature of Linux, there is no charge whatsoever to try Linux. You
can install the OS free of charge on an unlimited number of computers without paying anything towards
licensing. This is the case for both the server editions and the desktop editions of many Linux distributions.

In contrast with commercial solutions, many Linux distributions are completely free and include open-
source server software, so you can get started serving web pages without paying any fees for licensing.
Getting a fully functional Linux web server up and running is, in fact, just a few clicks away. To
learn more on Linux server distributions, read this post.

Reliability: Linux OS is great when stability matters

It’s also easy to argue that Linux software makes life easy for system administrators because Linux is more
reliable. It means you don’t need to closely watch your server every day; you can rely on it running without
a problem. Also, because of the way Linux is built, you can often restart individual services without
impacting the entire Linux OS.

By definition, an operating system is a tool that you need to be able to rely on. If cost is not the biggest
factor for you, the reliability that Linux brings can be game-changing. Wondering what the Linux operating
system’s biggest advantage is? Well, its inherent reliability and its general immunity to viruses, malicious
software, and other random operating system issues are perhaps the biggest reasons to adopt Linux.

Server reboots are a particular problem for sysadmins, and Linux, due to its stability, allows sysadmins to
largely avoid reboots unless the kernel is updated. Many Linux servers can run for years without seeing a
reboot, and sysadmins would often consider this a sign of the reliability of Linux.
Open source: Linux equals freedom

We mentioned open source earlier in this article. But what is open source? Simply put, any software that is
open source follows a set of principles, which include:

 Full freedom to run the software, no matter your reason for running it or your goals
 Permission to examine and disassemble the software, to study it, and to make any changes you want to
make to it
 There are no restrictions on distributing the software
 There are no restrictions on distributing any copies of the software modified by you

It is also important to understand that open-source software is a community. It´s a community that built
Linux and a community that maintains Linux. Arguably, it´s this open-source philosophy that has made
Linux so popular.

The Linux OS list: understanding distributions

The different editions, or distributions, of Linux can be vary varied. They can be aimed at desktop use, or
designed to be used as server software. Some distributions of Linux focus on expert users, other Linux
distributions are easy enough to use for beginners. Also known as distros, most Linux editions can be
downloaded free of charge and burned to an optical disk or USB drive for installation.

There are an almost endless number of Linux distributions. For desktop Linux users the default choice is
often Ubuntu, but Fedora, Arch, Linux Mint, Debian and openSUSE are also popular choices. Ubuntu is
one of the most modern thanks to Ubuntu Unity while KDE, included with openSUSE, has a more
traditional Linux look.

Looking for the server Linux OS list? It’s a long list, but some of the most well know distros include Red
Hat, Ubuntu Server, SUSE Enterprise and CentOS. However some Linux server distros are not free, Red
Hat requires licensing but bear in mind that you do get support in return for your license fee, which can be
important for businesses.

Popular Linux Distributions

A number of Linux distributions have gained a following for their unique features and specialized
offerings. For example, Ubuntu is highly regarded for its user-friendly interface and various versions
tailored to desktop, server, and IoT needs. It also boasts the support of Canonical as well as a customized
GNOME desktop environment.

On the other hand, Fedora remains closely aligned with traditional GNOME experiences while providing
software management through dnf, rpm, and Flatpak.

Some other notable Linux distributions include:

Red Hat Enterprise Linux which focuses on long-term commercial stability backed by default use of
GNOME.
MX Linx which merges MEPIS Linux and antiX to create an intermediate distribution offering both
reliability from its stable foundation along with current applications made possible thanks in partto MX-
tools;

openSUSE caters towards diverse users via Leap (a more consistent edition) or Tumbleweed’s rolling
release system. Each differs according to preferences/needs.

Linux Desktop Environments

Linux stands out from Windows and macOS in its flexible graphical user interfaces, offering a wide range
of customization options. Popular choices include GNOME with personalized touches on Fedora and
Ubuntu, Cinnamon, MATE, and Xfce for Linux Mint users who prioritize lightweight alternatives like
LXQt or Xfce as seen in Lubuntu and Linux Lite.

Major versions of various distributions also present diverse desktop environments such as KDE, Pantheon,
Mate among others to cater to different preferences for visual appeal or functionality. Lightweight
solutions are preferred by some users, resulting in the popularity of Openbox, SliTaz, IceWM along with
Trinity Desktop which can be found on Q4OS,Tiny Core Linux, Absolute Linux etc.

Comparing Linux to Other Operating Systems

When compared to other operating systems, Linux stands out for its strong security measures and
flexibility. The architecture of Linux has various built-in features that make it more secure than many
competing operating systems. There have been instances of specific malware targeting Linux, such as
Symbiote. Despite this potential vulnerability, the proactive community consistently tests and addresses
any security flaws in the system.

While the growing popularity of Linux has made it a target for malicious attacks like malware, overall it
remains reliable and cost-effective due to its lower number of targeted vulnerabilities compared to
Windows – largely because Windows still dominates with approximately 75% market share on desktops
while only about 3% use Linux instead.

Nevertheless, a significant portion continues to choose Linux over others due to their prioritization of
safeguarding computer data and reducing risk exposure by using less attractive operating systems which
are likely already hacked or at least regularly tested for safety glitches. Even though its user base is
relatively small compared to those who prefer Windows, Linux retains an appeal among security-conscious
users which amounts up not more than three percent of those who opt for a safer computing experience
foregoing the popular yet potentially risky Microsoft operating system (Linux uses a steadyitie between
upgrades).

Security Features

Linux is known for its robust security features, which include file permissions and the use of Security-
Enhanced Linux (SELinux) to enforce additional application and network-level protections. These
measures contribute to its reputation as a more secure operating system than others.
When it comes to file permissions in Linux, they are based on Unix’s model that allows owners, groups,
and other users different levels of access such as read, write, and execute. This highly configurable nature
adds another layer of security. Additionally, UX-based systems rely on optional packages like ClamAV for
antivirus protection instead of having an integrated one like Windows 10 or built-in technologies similar to
macOS’ Gatekeeper.

Although all three major operating systems – Linux,Windows & macOS – utilize codesigning, to ensure
trustworthiness, it’s worth noting that there have been some instances where unsigned code has slipped
through with Tux at a slightly higher frequency compared with the other two OSs’.

Customization and Flexibility

The open-source nature of Linux allows for extensive customization, from the kernel to the desktop
environment. This enables users to create a personalized computing experience tailored to their specific
needs.

Linux’s file system and directory structure can be extensively configured, giving users even more control
over their systems. Scripting and automation are deeply integrated in Linux, providing power users with
command-line tools that allow them to automate tasks and adjust system behavior according to their
preferences. The flexibility and level of personalization of these features make Linux a powerful tool for
those who know how to use it effectively.

What is Linux used for?

Linux is widely utilized in a diverse range of devices, including smartphones, cars, supercomputers, home
appliances, desktops, servers, and embedded systems. Its strengths lie in providing dependable and secure
desktop environments as well as graphical server solutions that require minimal maintenance.

The versatility of Linux allows it to cater to the needs of various users, such as business owners looking for
robust web server platforms or developers creating applications for mobile devices. Even hobbyists
experimenting with their own home automation systems can benefit from its tailored solutions. This
demonstrates the expansive capabilities and reach of this operating system, making it an excellent choice
for any Linux system.

One key feature that makes Linux stand out is its reliability on different types of machines, ranging from
small-scale personal computers to large enterprise-grade servers. It also offers flexible options like
graphical interfaces, which are user-friendly yet low-maintenance compared to other traditional operating
systems, allowing businesses more convenience with their data handling methods without compromising
security measures due to constant monitoring requirements.

It’s no wonder why so many individuals turn towards utilizing a Linux-based environment, whether they’re
trying to optimize resource management throughput levels or ensuring foolproof access restrictions
throughout all organization layers used. Regardless of whether you use your computer on a work, home, or
mobile platform, there will always be something new to explore while learning after switching over
completely painlessly.
Web Servers and Enterprise Solutions

In the realm of web servers and corporate environments, a Linux server provides customizable solutions for
hosting and balancing loads to meet diverse data usage requirements. With over 41.8% of known operating
systems using Linux, this technology is widely adopted by various websites worldwide.

Some of the popularly used distributions include Ubuntu, Debian, CentOS, Red Hat Gentoo, and
AlmaLinux.

Leading cloud service providers such as AWS, Google Cloud, and Microsoft Azure have successfully
integrated Linux into their services, catering to a wide array of computing and hosting demands. Different
enterprise needs are met with specific versions and distributions offered within Linux; Fedora requires
updates every nine months, followed by reboots, whereas Ubuntu Server has gained recognition for its
ability to support cloud-native applications.”

Mobile Devices and Embedded Systems

Linux serves as the base for a variety of popular consumer electronics, including smartphones, smart TVs,
in-vehicle infotainment systems, and routers. Android is one prime example where Linux dominates the
mobile operating system market.

Embedded Linux can be found at work in various devices, such as Sharp Zaurus PDAs or TomTom GPS
units, along with Linksys routers and Motorola smartphones, which run on the Sailfish OS. This
widespread use of Linux reflects its versatility and reliability.

Whether you’re using your smartphone to surf the internet or relying on your GPS device to navigate
through unfamiliar streets, chances are high that you’re utilizing a product powered by Linux technology.

Which Linux OS is right for you?

Your Linux distro of choice is going to depend on your personal needs. Foremost, you should consider
your computer skills. If you have never used the command line or Linux, you will be more restricted in
your choices. Another obvious point to consider is: are you going to use your Linux OS on a desktop or to
serve applications? And, if desktop, do you prefer one of the modern-looking distros or a more classic
Linux look?

With basic computer skills, you should look at a distribution that caters to inexperienced Linux users.
Linux Mint and Deepin are good choices. Are you a pro Linux user? You might prefer to use Fedora or
Debian, while the most experienced users could choose Gentoo.

As for servers, consider the need for a GUI. Some servers are best managed via the command line, which
means your server won’t be slowed down by the graphics server. Some server distros won’t come with a
GUI, some will, and some, like Ubuntu, will allow you to add a GUI any time after you’ve installed the
server.
Some server distros are good for specific applications, including a lot of pre-bundled services. CentOS is a
good example, as it offers a lot of what you need to run a comprehensive server out of the box. You can
even start with a desktop distribution and add Linux operating system components as and when you need
them. Consider Debian or Ubuntu if that’s the case.

Getting Started with Linux

Transitioning to Linux involves creating a bootable installation media, partitioning the hard drive, and
using package managers for software management. It is possible to have multiple operating systems on one
computer by dividing the hard drive and utilizing a boot manager like GRUB during system startup.

Don’t be intimidated! Live distributions in Linux make it easier to install without permanently saving it on
your device. The key element of managing and installing software in Linux is leveraging its specific
distribution package manager(s).

Installation Process

The process of installing Linux is fairly straightforward. To install a Linux distribution, you will need to
create bootable installation media with at least 4GB of space on a USB thumb drive or external hard drive
using Rufus. The recommended minimum amount of dedicated space for the operating system is 20GB
when partitioning your PC’s hard drive.

During the installation process, you need to:

1. Run the Live distribution

2. Go through an installation wizard where you must choose language, time zone, and keyboard layout.

3. Create login credentials for your user account.

You´ll then be prompted by GNU GRUB to select which operating system they would like to use. There
may be options available during this process, such as downloading updates or third-party software, if
desired by Linux users.

As you embark on your journey with Linux installation, we understand that it’s essential to start with the
basics. For those new to Linux, we’ve prepared a beginner-friendly guide on setting up a Linux mail server,
empowering you to expand your server’s functionalities while gaining valuable hands-on experience.
Additionally, discover our tutorial on finding files in Linux from the command line, providing you with
fundamental skills to navigate your system efficiently. Let’s dive in and make your Linux journey a smooth
and enjoyable one!

Installing Software on Linux

Linux uses a package manager to effectively manage software installation by adding, updating, or
removing components from trusted repositories. On Debian-based systems, users can utilize the command
line with ‘sudo apt install packagename’ while on DNF-based systems like Fedora, it would be ‘sudo dnf
install packagename’. Before initiating any installations, keeping an updated list of available software is
important, and this can be done through commands such as ‘sudo apt update’ for Debian-based systems
and sudo dnf makecache for DNF-based systems.

To find specific packages that meet their needs, users have options depending on the type of system they
are using. For instance, on Debian-based systems, keyword searching is possible via “apt-cache search”
followed by desired keywords, whereas, for those on DNF-based ones, the equivalent command would
involve typing in’sudo dnf search softwarename‘.

Some people may opt for graphical user interfaces instead, particularly if they prefer visual representations
when working; GNOME Software, KDE Discover, and Synaptic are examples of tools offering easy-to-use
graphical interfaces for managing software. In addition to these traditional packaging methods, some
universal solutions, including Flatpak and Snap, also exist that provide cross-distribution compatibility thus
easing sharing between different Linux distributions.

In addition to general software installation, users may also install web hosting control panels like Plesk on
Linux servers. If that is your case, here´s how to install Plesk on Linux.

The Linux Community and Resources

The community of Linux users offers various resources, such as online forums, documentation, and local
gatherings known as Linux User Groups (LUGs), to promote collaboration, provide support, and facilitate
learning. LUGs that are successful typically maintain a user-friendly website with easily accessible URLs,
share event details, including maps and directions, welcome all members of the public at their meetings
without charging any fees, and regularly update their online content with relevant information along with
functional hyperlinks.

Individuals who acquire proficiency in commonly used open-source tools like the Linux kernel can take
advantage of increased employment opportunities by actively contributing to them. Embedded systems also
have thriving communities involved in developing Linux-based devices through initiatives such as
Embeddable Linux Kernel Subset, Yocto, OpenEmbedded, and OpenWrt. All these groups play a vital role
in enhancing the development process for embedded systems using Linux technology.

Linux User Groups (LUGs)

Linux User Groups (LUGs) are instrumental in promoting preferred Linux distributions and providing
various forms of support, such as demonstrations, technical assistance, training sessions, and guidance for
newcomers on how to install the operating system. These groups gather physically and virtually through
online platforms to organize social events, deliver technical talks, and facilitate informal discussions
among members with a shared interest in using Linux.

For LUGs to maintain an active community that operates effectively over time, it is recommended they
establish consistent meeting times and locations while being mindful of avoiding scheduling conflicts.
Furthermore, having a dedicated core group comprising enthusiastic users can greatly contribute to their
success. LUG websites serve as valuable tools for showcasing past activities, enabling effective
communication among members, and offering practical learning resources related to internet technologies
specific to the use of Linux.

Online Forums and Documentation

The availability of online platforms such as Ubuntu Forums plays a crucial role in facilitating knowledge
sharing, troubleshooting discussions, and highlighting the strong support system present for Linux users.
The forum is structured to include both a resolution center and a council agenda dedicated to governing the
community and resolving conflicts within it.

These internet resources are vital to fostering collaboration among members of the Linux community by
providing an inclusive platform where they can exchange ideas, seek assistance with problems, and find
solutions. They effectively showcase the power behind open-source principles by promoting a culture that
values sharing information and continuous learning. Thus driving forward progress and innovation within
Linux.

Summary and conclusion

Linux offers a vast range of possibilities for individuals and businesses alike due to its open-source nature,
backed by a thriving community.

In this article, we covered the fundamentals of the Linux Operating System and listed the most common
use cases where Linux is employed. We also covered the unique security features of Linux and the
advantages of its versatility, as well as how it can adapt to users with different proficiency levels.

Frequently Asked Questions (FAQs)


What is Linux, in simple words?

Linux is an open-source operating system kernel. It differs from proprietary operating systems like
Windows and macOS in that it is freely distributable, customizable, and supported by a vast community of
developers worldwide.

Is Linux secure compared to other operating systems?

Linux is renowned for its security features, including user permissions, robust access controls, and regular
security updates. However, no system is entirely immune to vulnerabilities, so it’s essential to practice
good security hygiene, such as installing updates promptly and using reputable software sources.

Why use Linux as the main OS?

Linux offers numerous advantages, including stability, security, flexibility, and cost-effectiveness. It can
breathe new life into older hardware, provide robust server capabilities, and offer a wide range of software
options tailored to various needs.
Is Linux suitable for enterprise environments?

Linux is widely used in enterprise environments for servers, cloud computing, networking, and embedded
systems. Its stability, scalability, and cost-effectiveness make it a compelling choice for businesses seeking
reliable solutions without vendor lock-in.

Is Linux difficult to learn for beginners?

While Linux may have a learning curve for beginners accustomed to other operating systems, many
distributions (distros) offer user-friendly interfaces and extensive documentation. With some patience and
practice, users can quickly adapt to Linux and its ecosystem.

Can I run Linux alongside my current operating system?

Yes, you can dual-boot Linux alongside Windows or macOS, allowing you to choose which operating
system to use at startup. Alternatively, you can run Linux within a virtual machine for experimentation or
as a secondary environment.

How do I install software on Linux?

Linux offers various package management systems, such as apt (Advanced Package Tool), yum
(Yellowdog Updater, Modified), and Pacman, depending on the distribution. Users can install software
using these package managers, which simplify the process of downloading, installing, and updating
applications.

Who is the creator of Linux?

Linus Torvalds, a Finnish software engineer, created Linux in 1991. He developed the Linux kernel as an
open-source project, originally intending it to be a Unix-like operating system kernel for personal
computers. Torvalds released the first version of the Linux kernel to the public on September 17, 1991.
Since then, Linux operating system has evolved with contributions from thousands of developers
worldwide.

What is the Linux kernel?

The Linux kernel serves as the core element of the operating system and is responsible for managing
hardware resources. It plays a crucial role in controlling how different components interact with each other.

What is a Linux distribution?

A Linux distribution, commonly referred to as a distro, is a specific version of Linux tailored to fulfill
particular purposes. It´s a complete operating system based on the Linux kernel, along with various
software applications and utilities. While the Linux kernel itself is the core component responsible for
managing hardware resources and providing basic system functionalities, a Linux distribution packages the
kernel with additional software, libraries, and configuration files to create a usable operating system with
specific objectives or intended
Linux File System and Directory Structure
By Neil Mitra

9 mins read

Last updated: 12 Apr 2024

819 views

Topics Covered

Overview

A file system is a method for storing and organizing data on a computer. In Linux, the file system is a
crucial component of the operating system, responsible for managing data stored on disk and other storage
devices. The Linux file system is designed to provide a hierarchical and organized structure for files and
directories, making it easy to navigate and manage data on the system.

Introduction to Linux File System

The Linux file system is the structure that the Linux operating system uses to organize and store files and
data on a computer. It is a hierarchical, tree-like structure that starts with the root directory, which contains
all other directories and files. The Linux file system is based on the Unix file system, which was designed
to be scalable, flexible, and easy to use.

One of the key features of the Linux Operating System is that everything in Linux is a file, including
devices, programs, and system information. Even the most basic commands such as ls and cat are also files,
which lies inside the /bin directory, which itself is also a file. You can try to catch the cat command by
getting inside the /bin directory and see what happens.

The Linux Operating System is designed to support multiple file systems, each with its own characteristics
and features. This allows users to choose the best file system for their needs, depending on the specific
requirements of their system. We will discuss more about different file systems further in this article.

Linux File System Structure

The Linux file system structure is a complex hierarchy that includes multiple layers, each with its own role
in managing and organizing data on storage devices. At the top of the hierarchy is the root directory (/),
which contains all other directories and files. Below the root directory are several subdirectories, each with
its own purpose and set of files.

The file system is designed to manage non-volatile storage data by organizing it into files and directories,
which can be accessed and modified by users and applications. Linux uses different file systems such as
ext4, XFS, Btrfs, JFS, and ZFS to manage and store data on storage devices. It also provides a namespace,
which is a way of organizing files and directories into a logical hierarchy. The namespace allows multiple
users and applications to access the same storage device without conflicts.

The Linux file system structure also provides an API (Application Programming Interface) that allows
applications to interact with the file system. The API provides a set of functions and commands that allow
applications to create, modify, and delete files and directories, as well as to read and write data to and from
storage devices.

Characteristics of A File System

There are several characteristics of a file system that make it an essential component of any operating
system. Some of the most important characteristics are discussed below:

 File Organization:
The file system is responsible for organizing the files and directories on a disk. It provides a logical structure
to the data stored on the disk, making it easy for users and applications to locate and access files.
 File Naming Conventions:
The file system provides a set of rules for naming files and directories, ensuring that they can be easily
identified and managed. It also allows for the creation of long filenames, which can be more descriptive
and meaningful than traditional filenames.
 File Metadata:
The file system stores metadata about each file and directory, such as its name, size, creation and
modification dates, permissions, and ownership. This information is used by the operating system to
manage the file system and by applications to locate and manipulate files.
 File Access Control:
The file system provides a way to control access to files and directories, allowing users and applications to
specify who can read, write, or execute files. This is important for maintaining the security and integrity of
the data stored on the disk.
 File Compression:
The file system can compress files to reduce their size and save disk space. This can be useful for archiving
files or for transferring them over the internet.
 File Fragmentation:
As files are added, deleted, and modified on the disk, the file system may become fragmented, meaning
that the data for a file is stored in multiple locations on the disk. Fragmentation can slow down file access
and reduce overall system performance.
 File Recovery:
The file system provides a way to recover data from damaged or corrupted files or disks. This can be done
using file system utilities or specialized data recovery software.
 File System Type:
There are different types of file systems available, each with its own set of features and limitations. Some
of the most common file systems include ZFS, JFS, and ext4.
 File System Performance:
The performance of the file system can have a significant impact on overall system performance. Factors
such as disk speed, file system type, and disk fragmentation can all affect file system performance.
 File System Scalability:
The file system must be able to scale to accommodate the growing storage needs of users and applications.
This can be achieved through the use of larger disks or by implementing file system features such as disk
quotas or file compression.

Quiz Pop

Quiz Type

SCQ

100

Success Rate:35%

What does file fragmentation refer to in a Linux file system?

The process of compressing files to save disk space.

The loss of file metadata over time due to system use.

The storage of data from one file in multiple locations on the disk.

The method of encrypting files to enhance security.

Submit

Types of Linux File System

There is a wide range of file systems available in Linux, each of which is designed to meet specific needs.
We will learn about some of the most common file systems in Linux below :

 ext2:
The ext2 (extended file system 2) is one of the oldest and most widely used Linux file systems. It has been
the default file system for most Linux distributions for many years. The ext2 file system does not have a
journal, which means that file recovery can be more difficult after a system crash. However, it is a stable
and reliable file system that is ideal for small to medium-sized partitions.
 ext3:
The ext3 (extended file system 3) is an extension of the ext2 file system that adds journaling support.
Journaling keeps track of changes to the file system, which helps to reduce the risk of data loss after a
system crash. The ext3 file system is widely used and is a good choice for most Linux installations. It is
stable, reliable, and has good performance.
 ext4:
The ext4 (extended file system 4) is the successor to the ext3 file system and was designed to address some
of the limitations of ext3. It supports larger file sizes, faster file system checks, and better performance on
large disks. It also includes journal checksumming, which improves data integrity. The ext4 file system is the
default file system used by many modern Linux distributions.
 XFS:
The XFS(X File System) is a high-performance file system designed for large-scale storage systems. It
supports file systems up to 16 exabytes in size, making it suitable for use in large data centers. The XFS file
system is known for its scalability, performance, and reliability. It supports advanced features such as
journaling, file-level encryption, and online defragmentation.
 Btrfs:
The Btrfs (B-tree file system) is a modern file system designed for use on Linux systems. It supports features
such as copy-on-write, snapshots, and subvolumes, which allow users to create separate file systems within
a single partition. It also includes built-in support for RAID and compression. Btrfs is still under active
development and is not yet as widely used as some of the other file systems.
 ZFS:
The ZFS (Zettabyte File System) is a powerful and feature-rich file system that was originally developed for
Solaris. It supports advanced features such as snapshots, data compression, deduplication, and built-in
RAID. ZFS is known for its reliability and data integrity features, including checksumming and self-healing
capabilities. It is not included in most Linux distributions by default due to licensing issues but can be
installed separately.
 JFS:
The JFS(Journaled File System) is a high-performance file system that was originally developed by IBM. It
includes advanced features such as journaling, file-level compression, and online resizing. The JFS file
system is known for its speed and reliability and is a good choice for high-performance computing systems.
 ReiserFS:
The ReiserFS is a file system that was designed for high-performance computing systems. It includes
advanced features such as journaling, file-level encryption, and support for large files and directories. The
ReiserFS file system is known for its speed and reliability but is not as widely used as some of the other file
systems on this list.

Deep-dive into the Linux Directory Structure

Directories, also known as folders, are an integral part of the Linux file system. They serve as containers
for files and other directories and are used to organize and structure the file system. A directory can be
thought of as a virtual container that holds files and other directories within it.

One of the primary functions of directories in Linux is to provide a hierarchical structure for organizing
files. This structure starts at the root directory (/), and branches out into subdirectories as needed. With the
help of this hierarchical structure, complicated systems can be structured logically and organized. This
makes it simpler to locate and handle files on the system.
Each directory in Linux file system has a specific function, Some of a few key directories are listed below :

 / (root directory):
The root directory is the top-level directory in the Linux file system. All other directories and files are
contained within the root directory.
 /bin:
The /bin stands for binaries. This directory contains essential command-line tools and programs that are
required for basic system administration tasks.
 /boot:
The /boot directory contains the boot loader files and kernel images needed to start the system.
 /dev:
The /dev directory contains device files that represent hardware devices and virtual devices such as
terminals, printers, and disks.
 /etc:
The /etc directory contains system configuration files that are used by various applications and services on
the system.
 /home:
The /home directory contains the home directories of users on the system. Each user has their own
subdirectory within /home where they can store their personal files and settings.
 /lib:
The /lib directory contains shared library files that are needed by various programs on the system.
 /media:
The /media directory is used to mount removable media such as CDs, DVDs, and USB drives.
 /mnt:
The /mnt directory is used to mount file systems temporarily, such as network file systems or disk images.
 /opt:
The /opt directory is used to store additional software packages that are not part of the core system.
 /proc:
The /proc directory is a virtual file system that provides information about running processes and system
resources.
 /run:
The /run directory contains temporary files that are created by system services and daemons.
 /sbin:
The /sbin directory contains system binaries and administrative tools that are required for system
maintenance.
 /srv:
The /srv directory is used to store data for services provided by the system.
 /sys:
The /sys directory is a virtual file system that provides information about the system's hardware and
devices.
 /tmp:
The /tmp directory contains temporary files that are created by applications and services running on the
system.
 /usr:
The /usr directory contains user-level programs, libraries, documentation, and shared data files.
 /var:
The /var directory contains variable data files that change frequently, such as log files and system
databases.

Quiz Pop

Quiz Type

SCQ

100

Success Rate:35%

Which directory in Linux is specifically used for mounting file systems temporarily?

/media

/mnt

/opt

/tmp

Submit

Conclusion

 The Linux file system and directory structure are fundamental components of the operating system,
enabling users to effectively manage and organize their data while maintaining system integrity and
security.
 Linux uses a hierarchical file system that is organized in a tree-like structure.
 The topmost directory in any Linux file system is the root directory.
 There are different types of file systems available in Linux, and each type has its own advantages and
disadvantages, depending on the use case.
 The Linux directory structure contains various directories for system binaries, boot files, device files,
configuration files, user files, libraries, and system-generated files.
Linux operating system




By

 Peter Loshin, Former Senior Technology Editor


 Stephen J. Bigelow, Senior Technology Editor

Published: Oct 06, 2021

What is Linux?

Linux is a Unix-like, open source and community-developed operating system (OS) for computers, servers,
mainframes, mobile devices and embedded devices. It is supported on almost every major computer
platform, including x86, ARM and SPARC, making it one of the most widely supported operating systems.

How is the Linux operating system used?

Every version of the Linux OS manages hardware resources, launches and handles applications, and
provides some form of user interface. The enormous community for developers and wide range of
distributions means that a Linux version is available for almost any task, and Linux has penetrated many
areas of computing.

For example, Linux has emerged as a popular OS for web servers such as Apache, as well as for network
operations, scientific computing tasks that require huge compute clusters, running databases, desktop and
endpoint computing, and running mobile devices with OS versions like Android.

The Linux OS can be found in many different settings, supporting many different use cases. Linux is used
in the following ways:

 Server OS for web servers, database servers, file servers, email servers and any other type of shared server.
Designed to support high-volume and multithreading applications, Linux is well-suited for all types of server
applications.
 Desktop OS for personal productivity computing. Linux is an open source and freely available desktop
environment for users who prefer it to commercial OSes.
 Headless server OS for systems that do not require a graphical user interface (GUI) or directly connected
terminal and keyboard. Headless systems are often used for remotely managed networking server and
other devices.
 Embedded device or appliance OS for systems that require limited computing function. Linux is used as an
embedded OS for a variety of applications, including household appliances, automotive entertainment
systems and network file system appliances.
 Network OS for routers, switches, domain name system servers, home networking devices and more. For
example, Cisco offers a version of the Cisco Internetwork Operating System (IOS) that uses the Linux kernel.
 Software development OS for enterprise software development. Although many development tools have
been ported to Windows or other OSes, Linux is home to some of the most widely used open source
software development tools. For example, git for distributed source control; vim and emacs for source code
editing; and compilers and interpreters for almost every programming language.
 Cloud OS for cloud instances. Major cloud computing providers offer access to cloud computing instances
running Linux for cloud servers, desktops and other services.

Linux is highly configurable and depends on a modular design that enables users to customize their own
versions of Linux. Depending on the application, Linux can be optimized for different purposes such as:

 networking performance;
 computation performance;
 deployment on specific hardware platforms; and
 deployment on systems with limited memory, storage or computing resources.

Users can choose different Linux distributions for specific applications or adapt a specific distribution to
incorporate custom kernel configurations.

Linux distributions

Since its initial development, Linux has adopted the copyleft stipulations of the Free Software Foundation
which originated the GNU GPL. The GPL says that anything taken for free and modified must be
distributed for free. In practice, if Linux or other GNU-licensed components are developed or modified to
create a new version of Linux, that new version must be distributed for free. This prevents a developer or
other groups from profiting unfairly from the freely available work of others.
Linux

Tux, the Linux mascot.

Hundreds of different Linux versions, also known as distributions or distros, are available. Distributions
usually distinguish themselves from the pack by addressing a specific goal, philosophy, function or target
market.

There are distributions tailored for specific target functions, such as servers, desktops, gaming, security, or
embedded devices including Raspberry Pi systems. Most modern distributions are precompiled and ready
to use, while others like Gentoo Linux consist of source code that a user can compile locally during initial
installation to optimize their system configuration. Knoppix Linux is one of many distros used to recover
damaged hard drives and perform other technical support tasks. Information security professionals use Kali
Linux for penetration testing and other security-related tasks.

Linux has become an important component of automaker entertainment systems. Many automakers have
joined Automotive Grade Linux (AGL), an open source project hosted by the Linux Foundation. For
example, Toyota and Lexus vehicles use AGL for their infotainment systems.

Linux distributions may be community-developed, like Debian, Slackware and Gentoo. Other distributions
are commercial and intended for enterprise use, including Red Hat Enterprise Linux and SUSE Linux
Enterprise Server. Many distributions use a combination of community- and corporate-supported
development, such as Red Hat's Fedora, openSUSE from SUSE and Ubuntu from Canonical.
This chart highlights
nine popular Linux distributions.

The GNU GPL does not prohibit intellectual ownership, and it is commonplace for creators of Linux
components to hold copyrights on the various components. The GNU GPL ensures that those components
remain free and freely distributed. While the software remains free, it is common for some commercial
distributions to charge for value-added services, such as support or custom development services.

Linux components and terminology

The Linux OS system incorporates several different components, including:

 Bootloader. A bootloader is responsible for managing the boot process of the computer and for starting
the Linux kernel. It can also be used to manage systems that boot more than one OS.
 Kernel. The core of the Linux system, the kernel handles network access, schedules processes or
applications, manages basic peripheral devices and oversees all file system services. The Linux kernel is the
software that interfaces directly with the computer hardware.
 Init system. The first process to run once the kernel is loaded. A process is an instance of a program
running on a computer, and the init system initializes the system to enable it to run other processes. Init is
a daemon program that acts as the parent process to all other processes running on the system. Init can be
configured to start specific processes at system initialization. For example, when the system will be running
a web server the init system can be configured to load all necessary web server software.
 Daemons. This is a program that runs in the background, handling requests for a service. A web server
running on a Linux server depends on a daemon, usually named httpd, to listen for web server requests.
 Graphical server. This is the software that controls how graphics are displayed on a computer. Without a
graphical server, users can only interact with the Linux system through a command-line interface. The X
Window System, also known as X11 or X, is the most common graphical server for Linux, though not the
only one. X runs as a server daemon on the system and is called upon by applications when graphical
output is required.
 Desktop environment. This is the collection of applications and user interface controls with which users
interact when using Linux as a desktop platform. Access to the desktop environment is usually controlled
through the X Window System or another graphical system. Each desktop environment defines its own
look, including the way graphical elements like windows, pull-down menus and files are displayed and
manipulated. The desktop environment will also include a set of default applications for managing files and
folders, text editing, running a command-line session and other common tasks.
 Applications. This is the software that is installed during and after the initial Linux installation. Most Linux
distributions include thousands of different applications, including both for a networked server and for
desktop use.

The Linux kernel mediates interaction between applications and


system hardware such as CPU, memory and devices like storage or printers.

While these components are included in most Linux distributions, they are not necessarily part of every
deployed Linux system. For example, a Linux-based server may not require a graphical server, desktop
environment or applications.

But it is really the many outside developers and GNU projects that offer high-level functions to the Linux
kernel to provide a fully realized OS. For example, there are modules to provide a command-line interface,
implement a GUI, manage security, and offer video input or audio services -- each of which can be
modified and optimized to form unique distributions for specific tasks.

Desktop environments can also vary widely with different approaches to GUI design and default
applications. The two most popular desktop environments are:

 The GNOME desktop environment, which is included in most popular Linux distributions, is the default
desktop for many. Designed to be easy to use and reliable, GNOME spawned other desktop environment
projects, including MATE, Cinnamon and Unity.
 The KDE desktop environment is the primary alternative to GNOME. KDE is also designed to be easy to use
and reliable. It has spawned other projects, including the Trinity Desktop Environment.
Package manager software typically adds, updates or removes software components under the Linux OS.
Package managers enable users to install additional software not included with their distributions.
Examples of software package managers include RPM Package Manager, dpkg, OpenPKG and Zero
Install.

How the Linux operating system works

The Linux OS follows a modular design that is the key to its many variations and distributions. All Linux
distributions are based on the Linux kernel, but they can differ depending on factors such as:

 Kernel version. Distributions can be configured with more recent versions to incorporate newer features or
with older versions to be more stable.
 Kernel modules. This is software that can be loaded and unloaded into the kernel to extend functionality
without rebooting. Kernel modules are often used to support:
o device drivers, which use code that controls how attached devices operate;
o file system drivers, which use code that controls how the kernel works with different file systems;
and
o system calls, which use code that controls how programs request services from the kernel.

 Configuration options. Linux kernels compiled with configuration options set to include only device or file
system drivers are used for some specialized distributions; for example, compiling a kernel for a wireless
device without any wired network device drivers.

The Linux kernel is the one thing that all systems running Linux have in common. Linux works by:

 Loading and booting a Linux kernel.


 Once booted, the kernel manages all system input and output. The system is initialized, and processes can
be started.
 As system processes are started, the system can be used for processes that include network server
functions, commands entered interactively via command line, desktop applications or any application or
program.

While the kernel may be almost identical -- with some divergence for configuration and compilation
differences -- the user experience can vary widely, depending on how the Linux system is being used. For
example, some Linux use cases with widely different user experiences include:

 Desktop productivity systems, such as those used by software developers or other professionals. Software
development workstations may be optimized for performance, while desktops for administrative
professionals may be optimized for use of desktop productivity tools.
 Network servers may not even include a terminal for direct access. These headless servers are managed
remotely through network terminal or Windows sessions. Servers may be used by many but should be
directly accessed only by authorized system admins.
 Thin clients enable users to access a rich desktop environment from a lightweight device. This includes
Raspberry Pi single-card computers and Google Chromebooks.
When using Linux with a desktop environment as a GUI, Linux works much the same as any GUI-based
OS. Applications and other resources can be opened by clicking on icons, and files can be moved, copied
or deleted using a mouse or trackpad.

Likewise, using the Linux command line is similar to any modern OS command line:

userID@DESKTOP-2KD3FT2:/mnt/c/WINDOWS/system32$

This example shows the default command prompt in the Windows Subsystem for Linux. The prompt
displays, from left to right, userID@hostname, and the full path of the current directory followed by the "$"
symbol.

Experience Linux on
Windows 10 (or later) desktop by running the Windows Subsystem for Linux.

The pros and cons of using Linux

Some advantages of using Linux include:

 Open source software. The Linux kernel is released under the GNU GPL open source software license. Most
distros include hundreds of applications, with many options in almost every category. Many distributions
also include proprietary software, such as device drivers provided by manufacturers, to support their
hardware.
 Licensing costs. Unlike Microsoft Windows or Apple macOS, Linux has no explicit licensing fees. While
system support is available for a fee from many Linux vendors, the OS itself is free to copy and use. Some IT
organizations have increased their savings by switching their server software from a commercial OS to
Linux.
 Reliability. Linux is considered a reliable OS and is well-supported with security patches. Linux is also
considered to be stable, meaning it can run in most circumstances. Linux also copes with errors when
running software and unexpected input.
 Backward compatibility. Linux and other open source software tend to be updated frequently for security
and functional patches, while retaining core functionality. Configurations and shell scripts are likely to work
unchanged even when software updates are applied. Unlike commercial software vendors that roll out new
versions of their OSes along with new ways to work, Linux and open source applications generally don't
change their modes of operation with new releases.
 Many choices. Between the hundreds of available distributions, thousands of applications and almost
infinite options for configuring, compiling and running Linux on almost any hardware platform, it is possible
to optimize Linux for almost any application.

Some disadvantages of using Linux include:

 Lack of established standard. There is no standard version of Linux, which may be good for optimizing
Linux for particular applications, but less so for deploying standardized server or desktop images. The wide
range of options can complicate support as a result.
 Support costs. While an organization can acquire Linux freely without licensing fees, support is not free.
Most enterprise Linux distributors like SUSE and Red Hat offer support contracts. Depending on the
circumstances, these license fees can reduce savings significantly.
 Proprietary software. Desktop productivity software like Microsoft Office cannot be used on Linux
desktops, and other proprietary software may be unavailable for Linux platforms.
 Unsupported hardware. While many hardware manufacturers make Linux device drivers available for their
products, many do not.
 Steep learning curve. Many users struggle to learn to use the Linux desktop or Linux-based applications.

In some cases, the same Linux attribute can be either an advantage or disadvantage. For example, having
many options for customizing the Linux OS is advantageous for manufacturers looking for an embedded
OS, but it is a disadvantage for enterprises that want a desktop OS that can be used by a wide range of end
users.

History of Linux

Linus Torvalds started working on Linux as a replacement to the Minix OS while at the University of
Helsinki in Finland. Torvalds recognized the work done on the GNU Project in 1983, which intended to
create a complete, Unix-compatible OS comprised entirely of free software, and noted the GNU as a model
for distribution. However, the work on GNU had not been finished by the time Torvalds sought a Minix
replacement, prompting him to develop an alternate OS kernel dubbed Linux -- a contraction of Linus'
Unix -- and adopt the GNU GPL.

Torvalds released the Linux kernel in September 1991. A community of developers worked to integrate
GNU components with Torvalds' kernel to create a complete, free OS known collectively as Linux.
Torvalds continues to develop the Linux kernel and a vast developer community continues to create and
integrate a wide range of components.

While Linux still lags Windows and macOS on the desktop, it continues to challenge the proprietary OS
vendors on servers and embedded systems.

nderstanding the Linux Kernel, Shell, Terminal, and Console


Linux can feel confusing when terms like kernel, shell, terminal, and console are used interchangeably.
While they are closely related, each plays a unique role in how users interact with the operating system.
The kernel is the core that manages hardware, the shell interprets commands, the terminal provides the
interface to type those commands, and the console refers to the broader input/output environment.
Understanding these distinctions helps clarify how Linux bridges the gap between the user and the
machine.

Let’s dive into it:

Kernel
• The kernel (orange box in the diagram) is the core part of the operating system.
• It manages:

CPU (processing power)


Memory (RAM)
Disk (storage)
Network & Display adapters (hardware interfaces)

• The kernel acts like a bridge between hardware and software. Programs don’t talk directly to the
hardware; they request services from the kernel.

User Space
This is where user-level programs run (blue boxes in the diagram). It sits on top of the kernel, meaning it
interacts with the kernel to get things done.

Inside user space, we see:

Terminal
• A terminal is basically a program (emulator) that provides a text-based interface for user
interaction.
• In the old days, the terminal was a physical device (a monitor + keyboard connected to a
mainframe).
• Today, it’s a software window (like GNOME Terminal, Konsole, or xterm) where you type
commands.

Shell
• The shell is the command-line interpreter.
• When you type a command in the terminal, the shell takes it, interprets it, and passes it to the
operating system/kernel.
• Examples: Bash, Zsh, Fish.
• In the diagram, the shell sits between the terminal and the command you want to run.

Command (‘tree’)
• 'tree' is just an example of a user program/command.
• The shell launches it, and the kernel ensures it runs on the hardware properly.

Console
• A console is a physical or virtual text input/output environment.
• In early computers: it meant the physical keyboard + screen directly connected to the machine.

• In modern Linux:
A console can be a virtual console (like pressing Ctrl+Alt+F1 to Ctrl+Alt+F6 to switch to different TTYs).

It’s a low-level environment where you interact with the system without a graphical interface.

Are They the Same?


• Terminal: A program (emulator) that provides a window for typing commands.
• Shell: The software that interprets the commands inside the terminal.
• Console: A broader term, traditionally physical, but now usually refers to virtual TTYs or system
text-mode access.

Think of it like this:


• Console = the room.
• Terminal = the desk in the room where you type.
• Shell = the secretary who understands your instructions and passes them to the right department (kernel).

o 60 essential Linux commands

Let’s look at the 60 most commonly used Linux commands and their examples for system administration.

Pro Tip

If you want to check a command’s usage, syntax, and options, use the –help flag. For example, enter ls –
help to display the ls utility guide.

1. ls command

The ls command lists the content of a folder, including files and directories. Here’s the syntax:

ls [options] [directory_or_path]

If you omit the path, the ls command will check the content of your current directory. To list items inside
subfolders, add the -R option. Meanwhile, use -a to show hidden content.

2. pwd command

To check the full path of your current working directory, use the pwd command. Its syntax is as follows:

pwd [options]
The pwd command has only two options. The -L option prints environment variable content, like shortcuts,
instead of the actual path of your current location. Meanwhile, -P outputs the exact location.

For example, /shortcut/folder is a shortcut for /actual/path, and you are currently in /actual/path/dir. If
you use the -L option, the output will be:

/shortcut/folder/dir

Meanwhile, the -P option will print the exact canonical path:

/actual/path/dir

3. cd command

Use cd to navigate between directories in your Linux VPS. It doesn’t have any option, and the syntax is
simple:

cd [path_or_directory]

Depending on your location, you might only need to specify the parent directory. For example, omit path
from path/to/directory if you are already inside one. The cd command has several shortcuts:

 cd – returns to the current user’s home directory.


 cd .. – moves a directory up.
 cd – – goes back to the previous directory.

4. mkdir command

The mkdir command lets you create one or multiple directories. The syntax looks like this:

mkdir [options] directory_name1 directory_name2

To create a folder in another location, specify the full path. Otherwise, this command will make the new
item in your current working directory.

For example, enter the following to create new_folder in /path/to/target_folder:

mkdir path/to/target_folder/new_folder

By default, mkdir allows the current user to read, write, and execute files in the new folder. You can set
custom privileges during the creation by adding the -m option. To learn more about permission
management, read the chmod section below.

5. rmdir command

Run rmdir to delete empty directories in your Linux system. The command syntax looks like this:
rmdir [options] directory_name

The rmdir command won’t work if the directory contains subfolders. To force the deletion, add the –p
option. Note that you must own the item you want to remove or use sudo instead.

6. rm command

The rm command deletes files from a directory. You must have the write permission for the folder or use
sudo. Here’s the syntax:

rm [options] file1 file2

You can add the -r option to remove a folder and its contents, including subdirectories. Use the -i flag to
display a confirmation message before the removal or -f to deactivate it completely.

Warning! Avoid using -r and -f unless necessary. Instead, add -i option to prevent accidental deletion.

7. cp command

Use the cp command to copy files from your current directory to another folder. The syntax looks like this:

cp file1 file2 [target_path]

You can also use cp to duplicate the content of one file to another using this syntax. If the target is in
another location, specify the full path like so:

cp source_file /path/to/target_file

Additionally, cp lets you duplicate a directory and its content to another folder using the -R option:

cp -R /path/to/folder /target/path/to/folder_copy

8. mv command

The main usage of the mv command is to move a file or folder to another location. Here’s the syntax:

mv file_or_directory [target_directory]

For example, we will move file1.txt from another location to the /new/file/directory path using this
command:

mv /original/path/file1.txt the/target/path

You can also use the mv command to rename files in your Linux system. Here’s an example:

mv old_name.txt new_name.txt
If you specify the full path, you can simultaneously rename files and move them to a new location like this
example:

mv old/location/of/old_name.txt new/path/for/new_name.txt

9. touch command

Run the touch command to create a new empty file in a specific directory. The syntax is as follows:

touch [options] [path_and_file_name]

If you omit the path, the touch command will create a new file in your current working directory. Here’s
an example:

touch file.txt

10. file command

The file command checks a file type, such as TXT, PDF, or other. The syntax is as follows:

file [file_name]

If you use this command on a symbolic link, it will output the actual file connected to the shortcut. You can
add the -k option to print more detailed information about the item.

11. zip and unzip commands

The zip command compresses one or multiple files into a ZIP archive, reducing their size. Here’s the
syntax:

zip [options] zip_file_name file1 file2

To extract a compressed file into your current working directory, use the unzip command like so:

unzip [options] zip_file_name

12. tar command

The tar command bundles multiple files or directories into an archive without compression. The syntax
looks as follows:

tar [options] tar_file_name file1 file2

To create a new TAR file, you must add the -c option. Then, use the -f flag to specify the archive’s name.
If you want to enable compression, add a specific option based on your preferred method. For example, the
following will bundle file1.txt and file2.txt with the gzip compression:

tar -cfz archive.tar.gz fle1.txt file2.txt

Remember that the archive’s file format will differ depending on the compression method. Regardless of
the extension, you can unpack a TAR file using this syntax:

tar [options] tar_file_name

13. nano, vi, and jed command

nano, vi, and jed commands let you edit files. They have the same syntax, except at the beginning, where
you specify the name of the tool:

nano/vi/jed file_name

If the target file doesn’t exist, these commands will create a new one. Since your system might not have
these text processing utilities pre-installed, configure them using your package manager.

We will explain the command in the apt and dnf command section.

14. cat command

The concatenate or cat command has various usages. The most basic one is printing the content of a file.
Here’s the syntax:

cat file_name

To print the content in reverse order, use tac instead. If you add the standard output operator symbol (>),
the cat command will create a new file. For example, the following will make file.txt:

cat > file.txt

You can also use cat with the operator to combine the content of multiple files into a new item. In this
command, file1.txt and file2.txt will merge into target.txt:

cat file1.txt file2.txt > target.txt

15. grep command

Global regular expression print or grep lets you search specific lines from a file using keywords. It is
useful for filtering large data like logs. The syntax looks as follows:

grep [options] keyword [file]

You can also filter data from another utility by piping it to the grep command. For example, the following
searches file.txt from the ls command’s output:
ls | grep "file.txt"

16. sed command

Use the sed command to search and replace patterns in files quickly. The basic syntax looks like this:

sed [options] 'subcommand/new_pattern/target_pattern' input_file

You can replace a string in multiple files simultaneously by listing them. Here’s an example of a sed
command that changes red in colors.txt and hue.txt with blue:

sed 's/red/blue' colors.txt hue.txt

17. head command

Use the head command to print the first few entries of a file. The basic syntax is as follows:

head [options] file_name

You can also print the first few lines of another command’s output by piping it like so:

command | head [options]

By default, head will show the first ten lines. However, you can change this setting using the -n option
followed by your desired number.

Meanwhile, use -c to print the first few entries based on the byte size instead of the line.

18. tail command

The tail command is the opposite of head, allowing you to print the last few lines from files or another
utility’s output. Here are the syntaxes:

tail [options] file_name


command | tail [options]

The tail utility also has the same option as head. For example, we will extract the last five lines from the
ping command’s output:

ping -c 10 8.8.8.8 | tail -n 5


19. awk command

The awk command searches and manipulates regular expression patterns in a file. Here’s the basic syntax:

awk '/regex pattern/{action}' input_file.txt

Although similar to sed, awk offers more operations beyond substitution, including printing, mathematical
calculation, and deletion. It also lets you run a complex task with an if statement.

You can run multiple actions by listing them according to their execution order, separated by a semicolon
(;). For example, this awk command calculates the average student score and print names that are above
that threshold:

awk -F':' '{ total += $2; students[$1] = $2 } END { average = total /


length(students); print "Average:", average; print "Above average:"; for (student in
students) if (students[student] > average) print student }' score.txt

Need help with a command?

Ask Kodee, Hostinger’s AI assistant, to break down and explain complex commands.

20. sort command

Use the sort command to rearrange a file’s content in a specific order. Its syntax looks as follows:

sort [options] [file_name]


Note that this utility doesn’t modify the actual file and only prints the rearranged content as an output.

By default, the sort command uses the alphabetical order from A to Z, but you can add the -r option to
reverse the order. You can also sort files numerically using the -n flag.

21. cut command

The cut command selects specific sections from a file and prints them as a Terminal output. The syntax
looks like this:

cut options file

Unlike other Linux utilities, the cut command’s options are mandatory for file sectioning. Here are some of
the flags:

 -f – selects a specific row field.


 -b – cuts the line by a specified byte size.
 -c – sections the line using a specified character.
 -d – separates lines based on delimiters.

You can combine multiple options for a more specific output. For example, this command extracts the
third to fifth field from a comma-separated list:

cut -d',' -f3-5 list.txt

22. diff command

The diff command compares two files and prints their differences. Here’s the syntax:

diff file_name1 file_name2

By default, the diff command only shows the differences between the two files. To print all the content and
highlight the discrepancies, enable the context format using the -c option. You can also ignore case
sensitivity by adding -i.

For example, run the following to show only the differences between 1.txt and 2.txt:

diff -c 1.txt 2.txt


23. tee command

The tee command outputs another command’s results to both the Terminal and a file. It’s helpful if you
want to use the data for further processing or backups. Here’s the syntax:

command | tee [options] file_name

If the specified file doesn’t exist, tee will create it. Be careful when using this command since it will
overwrite the existing content. To preserve and append existing data, add the -a option.

For example, we will save the ping command’s output as new entries in the test_network.txt file:

ping 8.8.8.8 | tee -a test_network.txt


24. locate command

The locate command searches for a file and prints its location path. Here’s the syntax:

locate [options] [keyword]

If you use the -r option to search files using regular expressions, omit the [keyword] argument. The locate
command is case-sensitive by default, but you can turn off this behavior using the -i flag.

Note that locate will look for files from its database. While this behavior speeds up the search process, you
must wait for the list to refresh before finding newly created items.

Alternatively, enter the following to reload the data manually:

updatedb

25. find command

The find command searches for a file within a specific directory. Here’s the syntax:

find [path] [options] expression

If you don’t specify the path, the find command will search your current working directory. To find files
using their name, add the -name option followed by the keyword.

You can specify the type of item you are looking for using the -type flag. The –type f option will search
files only, while -type d will find directories. For example, we will check file.txt in path/to/folder:

find path/to/folder -type f -name "file"


Unlike locate, the find command searches through folders in real time. While it slows down the process,
you can look for new items immediately without waiting for the system database to refresh.

26. sudo command

superuser do or sudo enables non-root users who are part of the sudo group to execute administrative
commands. Simply add it at the beginning of another utility like so:

sudo [options] your_command

For example, enter the following to open a file using nano as an administrator:

sudo nano file.txt

The Terminal will prompt you to enter the user’s password before executing the command. By default, you
must reenter it after five minutes of inactivity.

Typically, you don’t add any option to sudo, but you can check them by entering:

sudo --help

Warning! Since users with sudo privileges can change various settings of your system, use this command
with caution.

27. su and whoami commands

The su command lets you switch to another user in the Terminal session. The syntax looks as follows:

su [options] [username]

If you don’t specify any option or username, this command will switch you to the root user. In this case,
you must enter the password before changing the account.

You can check the currently logged-in user from the Linux command-line shell. Alternatively, use the
whoami command:

whoami

28. chmod command

Chmod lets you change the permissions of files or directories. The basic syntax looks as follows:

chmod [options] [permission] [file_or_directory]


In Linux, there are three folder and file permissions – read (r), write (w), and execute (x). You can assign
them to three parties – the owner, a group, or other accounts belonging to neither category. Consider this
example:

chmod -rwx---r-– file1.txt

The spot after the first hyphen (–) specifies the permission for the owner of file1.txt. In the previous
example, we grant them the rwx privilege.

The next spot is for groups. Since we won’t grant them any privilege, we put three hyphens to indicate
emptiness. The last slot is for other users who only have read or r permission.

29. chown command

The chown command lets you change the ownership of files, directories, or symbolic links. Here’s the
syntax:

chown [options] newowner:newgroup file1 file2

If you want to assign a user as the new owner of an item, leave the group name empty. For example, we
will make admin-vps the owner of file1.txt:

chown admin-vps file1.txt

Conversely, omit the username to make all group members the owner. Remember to write the colons (:)
like so:

chown :newgroup file1.txt

30. useradd, passwd, and userdel command

Use the useradd command to create a new account in your Linux system. The syntax is as follows:

useradd [options] new_username

By default, the useradd command doesn’t prompt you to give the new user a password. You can add or
change it manually later with the passwd command:

passwd new_username

To remove a user, use the userdel command followed by the account name like the syntax in the example:

userdel new_username

Since managing other users requires a superuser privilege, run these commands as root or with the sudo
prefix.
Pro Tip

To set up a password and other details during the account creation process, use the adduser command
instead.

31. df command

The df command checks your Linux system’s disk usage, displaying the used space in percentage and
kilobyte (KB). The syntax looks like this:

df [options] [file system]

Note that the df command operates at the file system level. If you don’t specify one, the utility will display
all the active file systems.

32. du command

To check the size of a directory and its content, use the du command. Here’s the syntax:

du [directory]

The command will check your working directory if you don’t specify a path or folder. By default, it breaks
down each subfolder’s disk usage, but you can add the -s option to summarize the total usage in one output.

You can also use the -M option to change the information from KB to MB.

33. top command

The top command displays all running processes in your system and their hardware consumption. The
syntax looks like this:

top [options]
The top command has various options. For example, -p lets you check a specific process by specifying its
ID. Meanwhile, add the -d flag to change the delay between screen updates.

34. htop command

Like top, the htop command lets you display and manage processes in your Linux server. It also shares the
same syntax:

htop [options]

htop has options similar to top, but you can add additional ones. For example, -C enables the monochrome
mode, while –-tree shows processes in a hierarchical view.
35. ps command

The ps command summarizes the status of all running processes in your Linux system at a specific time.
Unlike top and htop, it doesn’t update the information automatically. Here’s the syntax:

ps [options]

You can print a more detailed report by adding other options. For example, use -A to list all processes in
your system, -r to check only the running ones, or -u username to query those associated with a particular
account.

36. uname command

The unix name or uname command displays detailed information about your Linux machine, including
hardware, name, and operating system kernel. Its basic syntax looks as follows:

uname [options]

Without any option, the command will print your system’s kernel name. To check all information about
your machine, add the -a option.

37. hostname command

Use the hostname command to check your VPS hostname and other related information. Here is the
syntax:

hostname [options]

If you leave the option empty, the command will print your hostname. Add -i to check your server’s IP
address, -a to print the hostname alias, and -A to output the system’s fully qualified domain name (FQDN).

38. time command

The time command measures the execution time of commands or scripts to gain insights into your system
performance. The basic syntax looks as follows:

time command_or_script

You can measure a series of commands by separating them using double ampersands (&&) or semicolons
(;) like so:

time command; command; command

39. systemctl command

The systemctl command is used to manage services in your Linux system. Here’s the basic syntax:
systemctl subcommand [service_name][options]

The subcommands represent your task, like listing, restarting, terminating, or enabling the services. For
example, we will list Linux services using this:

sudo systemctl list-unit-files --type service --all

Note that this command might not work with older distributions since they use another service manager.

40. watch command

The watch command lets you continuously run a utility at a specific interval to monitor changes in the
output. Here’s the basic syntax:

watch [options] command_name

By default, watch will run your command every two seconds, but you can change the interval using the -n
option followed by the delay. If you want to highlight changes in the output, add the -d flag.
41. jobs command

Jobs are tasks or commands that are running in your current shell. To check them, use the jobs command
with the following syntax:

jobs [options] [Job_ID]

Running this command without any argument will show all jobs running in the Terminal’s foreground and
background. If you don’t have any ongoing tasks, it will return an empty output.

You can display more detailed information about each job by adding the -l option. Meanwhile, use -n to
show only tasks whose status has changed since the last notification.

42. kill command

Use the kill command to terminate a process using its ID. Here’s the basic syntax:

kill [signal_option] Process_ID

To obtain the process ID, run the following command:

ps ux

The kill command has 64 termination signals. By default, it uses the SIGTERM method that lets the
program save its progress before closing.

43. shutdown command

The shutdown command lets you turn off or restart your Linux system at a specific time. Here’s the
syntax:

shutdown [option] [time] [message]

If you run the command without any arguments, your system will shut down immediately. You can specify
the schedule using a 24-hour format or a relative one. For example, enter +5 to shut down the system after
five minutes. To restart the machine, add the -r option.

The message argument specifies the notification other users in your system will receive before the server
shuts down.

44. ping command

The ping command sends packets to a target server and fetches the responses. It is helpful for network
diagnostics. The basic syntax looks like the following:

ping [option] [hostname_or_IP_address]


By default, ping sends infinite packets until the user manually stops it by pressing Ctrl + C.

However, you can specify a custom number using the -c option. You can also change the interval between
transfers by adding -i.

For instance, let’s send 15 packets every two seconds to Google’s server:

ping -c 15 -i 2 google.com

45. wget command

The wget command lets you download files from the internet via HTTP, HTTPS, or FTP protocols. Here’s
the syntax:

wget [options] [URL]

By default, the wget command will download an item to your current working directory. For example, run
this command to retrieve the latest WordPress installer:

wget https://wordpress.org/latest.zip

46. cURL command

Use the cURL command to transfer data from or to a server by specifying its URL. The basic syntax looks
as follows:

curl [options] URL

Running cURL without an option will print the website’s HTML content in your Terminal. If you add the -
O or -o option, the command will download files from the specified link.

The cURL command is also helpful for testing API or server endpoints. You can do so by adding the –X
option followed by an HTTP method, depending on whether you want to fetch or upload data.
For example, the following command will retrieve data from a specific API endpoint:

curl -X GET https://api.example.com/endpoint

47. scp command

The scp command lets you securely copy files and directories between systems over a network. The syntax
looks as follows:

scp [option] [source username@IP]:/[directory and file name] [destination


username@IP]:/[destination directory]

If you are copying items to or from your local machine, omit the IP and path. When transferring a file or
folder from a local machine, specify its name after options.

For example, we will run the following to copy file1.txt to our VPS’ path/to/folder directory as root:

scp file1.txt root@185.185.185.185:path/to/folder

You can change the default SCP port by specifying its number after the -P option. Meanwhile, use the -l
flag to limit the transfer bandwidth and add –C to enable compression.

48. rsync command

The rsync command syncs files or folders between two destinations to ensure they have the same content.
The syntax looks as follows:

rsync [options] source destination

The source and destination can be a folder within the same system, a local machine, or a remote server. If
you are syncing content with a VPS, specify the username and IP address like so:

rsync /path/to/local/folder/ vps-user@185.185.185.185:/path/to/remote/folder/

You can add the -a option to sync the file or folder’s attributes as well, including their symbolic links.
Meanwhile, use the -z flag to enable compression during the transfer.

49. ip command

The ip utility lets you list and manage your system’s network parameters, similar to the ifconfig command
in older Linux distros. Here’s the syntax:

ip [options] object command

Running this command without any argument will print the manual, including an explanation about
acceptable options and objects.
To manage a network parameter, specify the action in the command argument. For example, run this to
show your system’s IP address:

ip address show

Pro tip

You can also use Kodee to display network details on your VPS. Simply type a prompt like “Can you show
my server’s network details?”, and it will respond accordingly.

50. netstat command

The netstat command displays information about your system’s network configuration. The syntax is
simple:

netstat [options]

Add an option to query specific network information. Here are several flags to use:

 -a – displays listening and closed sockets.


 -t – shows TCP connections.
 -u – lists UDP connections.
 -r – displays routing tables.
 -i – shows information about network interfaces.
 -c – continuously outputs network information for real-time monitoring.

51. traceroute command

The traceroute command tracks a packet’s path when traveling between hosts, providing information like
the transfer time and involved routers. Here’s the syntax:

traceroute [options] destination

You can use a hostname, domain name, or IP address as the destination. If you don’t specify an option,
traceroute will run the test using the default settings.

Change the maximum packet hops using the -m option. To prevent traceroute from resolving IP addresses,
add -n.

You can also enable a timeout in seconds using the -w flag followed by the duration.

52. nslookup command

The nslookup command requests a domain name system (DNS) server to check a domain linked to an IP
address or vice versa. Here’s the syntax:

nslookup [options] domain-or-ip [dns-server]

If you don’t specify a DNS server, nslookup will use your internet service provider’s default resolver. You
can add other options to change how this command queries an IP address or a domain.

For example, use the -type= option to specify the information you want to check, such as the DNS records.

You can also set up automatic retry with the -retry= flag and add -port= to use a specific port.

Since some Linux distros don’t have this utility pre-installed, you might encounter the “command not
found” error. You can configure it by downloading bind-utils or dnsutils via your package manager.
53. dig command

The domain information groper or dig command displays information about a domain. It is similar to
nslookup but more comprehensive. The syntax looks as follows:

dig [options] [server] [type] name-or-ip

Running dig without an argument will check A records of the specified domain using the operating
system’s default resolver. You can query a particular record by specifying it in the [type] argument like the
following example:

dig MX domain.com

To run a reverse DNS lookup, add the –x option and use an IP address as the target.

54. history command

Run the history command to check previously run utilities. Here’s its syntax:

history [options]

Add the -r option if you want to clear the Terminal history. To rerun a specific utility from the list, enter an
exclamation mark followed by its ID.

For example, use the following to run the 145th command:

!145

55. man command

The man or manual command displays a comprehensive guide of another utility. The syntax looks like the
following:

man [options] [section_number] command_name

If you specify only the command name, man will display the entire manual. Alternatively, you can select
one of the nine sections using their IDs to print more specific information.

For example, run the following to check the library call section of the ls command’s manual:

man 3 ls
56. echo command

Use echo to print text in your command as a Terminal output. Here’s the syntax:

echo [options] [text]

You can also add the redirection symbol (>) to print the text in a file instead of Terminal. If you use two
symbols (>>), it will append the existing content. The command syntax looks like this:

echo [options] [text] > [file_name]

If your text contains an environment or shell variable like $var, echo will display the actual value. This
command is commonly used for testing and bash scripting.

57. ln command

The ln command links files or directories with a shortcut. The syntax looks as follows:

ln [options] source target

This command will automatically create the shortcut, meaning you don’t need to make one manually. For
example, the following will enable you to open file.txt using shortcut.txt:

ln target.txt shortcut.txt

By default, ln creates a hard link, meaning changes in the source will be reflected in the linked item and
vice versa. To set up a soft or symbolic link, add the -s option.

58. alias and unalias command

The alias command lets you set another name for a string that belongs to a file, text, program, or command
name. Here’s the syntax:

alias name='string'

For example, the following will assign k as the alias for the kill command, allowing you to use the letter
instead of the full name.

alias k='kill'

To check a command’s alias, run alias followed by an alternative name. For example, we will check the
previous snippet:

alias k
You can remove an alias by running this syntax:

unalias [name]

59. cal command

The cal command displays a calendar in your Linux command-line interface. Here’s the syntax:

cal [options] [month] [year]

If you don’t add any argument, the command will show the current date. Alternatively, you can enter a
specific month and year in a numerical format.

You can also add the -3 option to show the current, previous, and next month.

60. apt and dnf command

The apt command lets you manage advanced package tool (APT) libraries in Debian-based operating
systems such as Ubuntu and Kali Linux. The syntax looks like this:

apt [options] subcommand

The subcommands define the action, like updating the library, upgrading software, installing an
application, or removing a package. For example, we will install the Vim text editor:

apt install vim

In Linux, package management commands differ across distributions. For example, Red Hat Enterprise
Linux-based distros like CentOS and AlmaLinux use dnf. It has the same syntax and options as apt.

Running both apt and dnf requires superuser privileges, which you can only obtain with sudo or via root.

The Linux Shell and Commands


From the last lecture we learnt to write our first C program and looked at the compiler (gcc) code chain. In
this lecture, we will discuss the Linux shell and its commands. The shell is a command line interpreter and
invokes kernel level commands. It also can be used as a scripting language to design your own utilities. We
will discuss scripting as part a future lecture on shell programming.

Since we do not recommend you buy a Linux book here are some very good references and free access
online books - see resources.

If you need help on the meaning or syntax of any unix shell command you can use the manual (man) pages
or the web unix commands.
Goals

We plan to learn the following from today’s lecture:

 The shell
 The file system

OK. Let’s get started.

The shell

Commands, switches, arguments

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. The shell can also execute other programs such as applications, scripts, and user programs (e.g.,
written in c or the shell programming language).

You will get by in the course by becoming familiar with a subset of the Linux commands.

Linux has often been criticized for being very terse (it’s rumored that its designers were bad typists). Many
commands have short, cryptic names - vowels are a rarity:

awk, cat, cp, cd, chmod, grep, find, ls, mv, ps, rm

We will learn to use all of these commands and more.

Linux command output is also very terse - the default action on success is silence. Only errors are reported.
Linux strongly supports the philosophy of one and only one way to perform each task. Linux commands
are often termed tools or utilities - familiarity with the “top 20” will be a great help.

Instructions entered in response to the shell prompt have the following syntax:

command [arg1] [arg2] .. [argn]

The brackets [] indicate that the arguments are optional. Many commands can be executed with or without
arguments. Others require arguments (e.g., cp sort.c anothersort.c) to work correctly, if not, they will
provide some error status message in return. But to avoid an explosion in the number of commands most
commands support switches (i.e., options) to modify the actions of the commands.

For example, lets use the ls command and the -l option switch to list in long format the file c.tex. Switches
are often single characters preceded by a hyphen (e.g., -l). Most commands accept switches in any order
though they must appear before all “true” arguments (usually filenames). In the case of the ls example
below the command arguments represent [options] filenames[s], as shown below. Options therefore modify
the operation of the command and are operated on by the program called by the shell and not the shell
itself.
In fact, the command is argument 0 (ls), -l switch or option is argument 1 and the filename is argument 2.
Some commands also accept their switches grouped together. For example, the following switches to ls are
identical:

[campbell@galehead lectures]$ ls -rtl


...
[campbell@galehead lectures]$ ls -l -r - t

The shell parses the words or tokens (commandname , options, filesnames[s]) and gets the kernel to
execute the commands assuming the syntax is good.

Typically, the shell processes the complete line after a carriage return (cr) (carriage return) is entered and
finds the program that the command line wants executing. The shell looks for the command to execute
either in the specified directory if given (./mycommnd) or it searches through a list of directories depending
on your $PATH variable.

Path environment

You will need to look at your $PATH variable and update it from time to time to make sure the path to the
code you want to execute is there. Typically, your login files that execute when you log in (.bash˙profile)
or each time to execute a command (.bashrc) are the place to set up these environment variables such as
$PATH.

echo $PATH
/sw/bin:/sw/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/texbin:/sw/bin:/usr/X11R6/bin

So where does the ls command executed above reside in the Linux directory hierarchy. Let’s use another
command to find out.

[atc@Macintosh-7 atc]$ which ls


ls is /bin/ls
[atc@Macintosh-7 atc]$ whereis ls
/bin/ls
[atc@Macintosh-7 atc]$

The whereis or which commands are a useful sanity check if you want to know for sure which ls command
is executed. For example, I could have written a program called ls and placed it in my working directory -
probably not a good idea but could happen. In that case, if I entered ls - which command would the shell
execute?

So we can see from the $PATH variable that /bin is in the path. Hence the shell can track down the ls
binary to execute. The fact that the ls command is in /bin assumes that the filename /bin/ls has the correct
permission set to be an executable by all. We can check this.
[atc@Macintosh-7 atc]$ ls -l /bin/ls
-r-xr-xr-x 1 root wheel 60972 Oct 17 2006 /bin/ls

Indeed it is. The file is owned by “root” and is executable by all.

If I set my $PATH variable to “.” only the current working directory and execute ls (this would be akin to
not having my path name set up correctly) then the shell would not be able to find the correct program to
execute (assuming I don’t have an ls binary with the correct permissions in my current directory). Here is
what would happen.

[atc@Macintosh-7 teaching]$ which ls


ls is /bin/ls
[atc@Macintosh-7 teaching]$ PATH=.
[atc@Macintosh-7 teaching]$ ls
-bash: ls: command not found
[atc@Macintosh-7 teaching]$ which ls
-bash: type: ls: not found
[atc@Macintosh-7 teaching]$

You may come across this error (“-bash: ls: command not found” or variants thereof) when you install code
or try and execute new programs you want to use or have written.

There are shells, shells and more shells

There are a number of shells available to a Linux user - so which one do you select? These are:

 sh - This is known as the Borne Shell and is the original shell;


 csh, tcsh - These are well-known and widely used derivatives of the Borne shell;
 ksh - The popular Korn shell; and
 bash - The Borne Again SHell is the most popular shell used for linux and developed by GNU.

Changing the Shell to bash

We will be using the bash shell in this course since it is standard fare with Linux machines. Let’s check
what shell has been configured for your login account. If it’s not the bash shell then let’s change the shell
using the change shell chsh command. To find out what shell is running, log in and look at the $SHELL
environment variable. We will use the echo command which is akin to the print (e.g., printf in C) statement
in many languages.

[campbell@spruce ~]$ echo $SHELL


/bin/tcsh

[campbell@spruce ~]$ chsh


please login to galehead and run /usr/bin/chsh from there.
[campbell@spruce ~]$ ssh galehead
campbell@galehead’s password:
Last login: Sun Dec 23 22:58:58 2007 from spruce.cs.dartmouth.edu

[campbell@galehead ~]$ chsh -l


/bin/bash
/bin/sh
/bin/ash
/bin/bsh
/bin/tcsh
/bin/csh
/usr/local/bin/bash
/usr/local/bin/tcsh
/bin/bash2
/bin/zsh

The tcsh shell is set. So we need to change the shell to bash. Note, that galehead is the only machine that
you can change user configuration information on such as passwords and shells. So we ssh to galehead and
list all permissible shells supported by our local Linux machines using the “chsh -l” switch.

Now, let’s change the shell to bash. Note, that our first attempt fails because the shell wants the full path
name. We will discuss full and relative path names later in this lecture. Our second attempt using the full
path name from above is successful.

[campbell@galehead ~]$ chsh -s bash


Changing shell for campbell.
Password:
chsh: shell must be a full path name.

[campbell@galehead ~]$ chsh -s /bin/bash


Changing shell for campbell.
Password:
Shell changed.

[campbell@galehead ~]$ ps
PID TTY TIME CMD
22271 pts/1 00:00:00 bash
22345 pts/1 00:00:00 ps

Another way to see what shell is running is to use the process status (ps) command. We can see that the
bash shell is running. The process ID and other status information of the process is displayed.
Note, that most commands executed by the shell starts a new “process”. (There is an exception to for what
are called builtins). We will discuss processes in a future lecture.

The basic shell operation is as follows. The shell parses the command line and finds the program to
execute. It passes any options and arguments to the program as part of a new process for the command such
as ps above. While the process is running ps above the shell waits for the process to complete. The shell is
in a sleep state. When the program completes it passes its exit status back to the shell. At this point the
shell wakes up and prompts the user for another command. Note, that it is the program that is executed, for
example, ps in this case, that checks to see if the arguments passed to it by the shell are correct or not. It is
not the job of the shell to do that level of parsing or error checking. If there are problems with the syntax
(e.g., wrong switch) then it is the program itself that informs the user via an error message.

A note on shell builtins

The term command and utility are used synonymous in these notes. The shell has a number of utilities built
into the shell called builtins. When a builtin runs the shell does not fork a process; that is, it does not create
a process specifically to execute the command. Therefore, the builtins run more efficiently in the context of
the existing process rather than having the cost of creating new processes to run the command. Typically,
users are not aware if a command runs as a builtin or a standard forked command. The echo command
exists as a builtin to the shell and as a separate utility in /bin/echo. As a rule the shell will always execute a
builtin before trying to find a command of the same name to fork. Bash supports a number of builtins
including bg, fg, cd, kill, pwd, read among others.

Linux file system

The Linux file system is a hierarchical file system. The file system consists of a very small number of
different file types. These include text files, directories, character special files (e.g., terminals) and block
special files (e.g., disks and tapes).

A directory is just a special type of file. A directory (akin to a Macintosh folder) contains the names and
locations of all files and directories below it. A directory always contains two special files ’.’ (dot) and ’..’
(dot dot). Every file has a filename of up to 1024 characters typically from ’A-Z a-z 0-9 ˙ .’ and an inode
which uniquely identifies the file in the file system.

Directory names are separated by a slash ’/’, forming pathnames.

/usr/bin/emacs
/etc/passwd

Files are accessed by referring to their relative or absolute pathnames.

Home directory

Each account has a home directory. After you have logged in your shell will be executing in your home
directory. So let’s log in and use the pwd command to find out where we are - we will be in the home
directory of course.
[atc@Macintosh-7 l2]$ ssh -Y -l campbell spruce.cs.dartmouth.edu
campbell@spruce.cs.dartmouth.edu’s password:
Last login: Mon Dec 24 11:37:01 2007 from c-75-69-130-98.hsd1.nh.comcast.net

[campbell@spruce ~]$ pwd


/net/nusers/campbell

Let’s list the contents of the home directory.

[campbell@spruce ~]$ ls -l
total 434
drwx------ 2 campbell faculty 48 Dec 22 15:29 bin
drwxr--r-- 5 campbell faculty 128 Dec 24 14:33 cs23
drwx------ 2 campbell faculty 48 Dec 22 15:30 lib
drwx------ 3 campbell faculty 1368 Dec 24 11:25 mail
drwx------ 3 campbell faculty 104 Nov 6 12:01 papers
drwxr-xr-x 4 campbell ug 728 Oct 26 2006 public_html
-rw------- 1 campbell faculty 435438 Dec 14 2006 Sent
-rw------- 1 campbell faculty 1017 Mar 22 2007 Sent Messages
drwx------ 3 campbell faculty 72 Dec 11 15:14 teaching

Recall the “d” in “drwx——” indicates that this file is in fact a directory. So we can move to that directory
assuming we have the relevant permission - which we do in all cases. So lets move around.

File and directory permission

All files and directories have certain access permissions which constrain access to only those users having
the correct permission. Let’s consider a couple of typical examples from above:

drwxr--r-- 5 campbell faculty 128 Dec 24 14:33 cs50

-rw------- 1 campbell faculty 1017 Mar 22 2007 Sent Messages

The first character of the access permissions indicate what “type of file” is being displayed.

 - plain files (such as C programs or text files)


 d directories
 c character special files (such as terminals)
 b block special files (such as disk drives)

Following the first type of file character the next 3 triples (i.e., groups of three characters) from left to right
represent file permissions: the read, write, and execute permissions, for (respectively) the owner (campbell
in this case), the files’s group (faculty in this case), and the “rest-of-the-world”. To determine that group
particular files are in enter the “ls -lg” command.
What do these permissions mean?

 Read permission means that the file may be displayed on the screen, copied to another file or printed on
the printer - any operation that requires reading the contents of the file. Having read permission on a
directory means that its contents can be read; for example, ls could read the names and attributes of the
files in the directory. Could the contents of those files be read?
 Write permission means that the file of directory may be modified, changed or overwritten. Most
importantly, write permission means that a file may be deleted. Write permission on a directory gives
permission to delete a file from within a directory.
 Execute permission on a file indicates that the file may be executed (i.e., run). Since a directory cannot be
executed its meaning is redefined. Execute permission on a directory means that the user can change into
that directory (e.g., using cd) and examine files (e.g., using ls) that it has permission to read. If it does not
have permission to read then permission will be denied when using the ls command.

After the file permission comes the number of links to the file (e.g., 5), followed b the owner (campbell),
group (faculty), size (e.g., 128) which represents the size of the file in bytes, date and time of modification
(e.g., Dec 24 14:33), and the filename (e.g., cs50).

Note, that shellscripts (which we will discuss in a future lecture) must have both read and execute
permission - bash or any of the shells must both be able to read the shellscript and execute it. Program
binaries on the other hand do not need to be read and only need execution permission since they are not
read but executed (recall when we tried to more a.out we could not view it because it was an executable in
machine code).

Changing permission

The permissions on files and directories may be changed with the chmod (change mode) command. When
you own a file or directory you can use chmod to change the access permissions to the file or directory.

Only the three permission triplets may be changed - a directory cannot be changed into a plain file nor
vice-versa.

Permissions given to chmod are either absolute or relative (i.e., symbolic).

Each triplet is the sum of the octal digits 4, 2, 1, and read from left to right. For example rwx is represented
by 7, rw- by 6, and r– by 4 and so on. The absolute octal values used with chmod are as follows:

Octal Value Protection mechanism


400 Read by owner
200 Write (delete) by owner
100 Execute (search in directory) by owner
040 Read by group
020 Write (delete) by group
010 Execute (search) by group
004 Read by others (i.e., rest of the world)
002 Write (delete) by others (dangerous!)
001 Execute (search) by others

The complete permission on any file is the sum of the values. For example, home directories are typically
700 which provides the owner with read, write, and execute permission but denies all access to others.

drwxr-xr-x 6 campbell faculty 152 Dec 31 20:40 cs50


...
[campbell@galehead ~]$ chmod 700 cs50
...
drwx------ 6 campbell faculty 152 Dec 31 20:40 cs50

If you wish others to read your files set - in this case a file funny - then the command would be:

[campbell@galehead ~]$ chmod 664 funny


...
-rw-rw-r-- 1 campbell faculty 0 Jan 1 15:50 funny

Because the file is only to be read, not written too, and the fact that it’s a file with no execution (not a
binary or shellscript) 644 makes good sense.

Use the manual pages to read how chmod can be used in a relative or symbolic mode; for example, what
would

[atc@Macintosh-7 notes]$ chmod u=wrx,og-rwx cs50

These symbolic arguments need to be used carefully. Here “o” means others and “u” means owner or user.

“chmod o+wrx cs50” do?

Moving around the file system

The change directory command (cd) allows us to move around the Linux directory hierarchy. Let’s
combine pwd, ls, and cd to move around the my local directories that are rooted at /net/nusers/campbell

[campbell@spruce ~]$ cd cs50

[campbell@spruce cs50]$ ls
assignments code lectures

[campbell@spruce cs50]$ pwd


/net/nusers/campbell/cs50
[campbell@spruce cs50]$ cd lectures/

[campbell@spruce lectures]$ ls
bash-programming.tex design.tex se.tex start.tex
c.tex linux-advance.tex shell.tex

[campbell@spruce lectures]$ pwd


/net/nusers/campbell/cs50/lectures

There are also a number of special characters that can be used with cd for short hand.

Moving to the parent directory:

[campbell@spruce lectures]$ cd ..

[campbell@spruce cs50]$ pwd


/net/nusers/campbell/cs50

Moving back to where we came from:

[campbell@spruce cs50]$ cd -
/net/nusers/campbell/cs50/lectures

[campbell@spruce lectures]$ pwd


/net/nusers/campbell/cs50/lectures

Moving to our home directory:

[campbell@spruce lectures]$ cd ~

[campbell@spruce ~]$ pwd


/net/nusers/campbell

and back:

[campbell@spruce ~]$ cd -
/net/nusers/campbell/cs50/lectures

Listing and globbing files


campbell@spruce lectures]$ ls -l
total 0
-rw-r--r-- 1 campbell faculty 0 Dec 24 12:22 bash-programming.tex
-rw-r--r-- 1 campbell faculty 0 Dec 24 12:22 c.tex
-rw-r--r-- 1 campbell faculty 0 Dec 24 12:23 design.tex
-rw-r--r-- 1 campbell faculty 0 Dec 24 12:22 linux-advance.tex
-rw-r--r-- 1 campbell faculty 0 Dec 24 12:23 se.tex
-rw-r--r-- 1 campbell faculty 0 Dec 24 12:21 shell.tex
-rw-r--r-- 1 campbell faculty 0 Dec 24 12:21 start.tex
[campbell@spruce lectures]$

Here are a popular set of switches you can use with ls:

-l list in long format (as above)


-t sort by modification time (latest first)
-a list all entries (including ’dot’ files)
-r list in reverse order (alphabetical or time)
-R list the directory and its subdirectories recursively

We can use a number of special characters to look at the files in a smart and efficient manner:

[campbell@spruce lectures]$ ls -l s*
-rw-r--r-- 1 campbell faculty 0 Dec 24 12:23 se.tex
-rw-r--r-- 1 campbell faculty 0 Dec 24 12:21 shell.tex
-rw-r--r-- 1 campbell faculty 0 Dec 24 12:21 start.tex
[campbell@spruce lectures]$

[campbell@spruce lectures]$ ls -l *s*


-rw-r--r-- 1 campbell faculty 0 Dec 24 12:22 bash-programming.tex
-rw-r--r-- 1 campbell faculty 0 Dec 24 12:23 design.tex
-rw-r--r-- 1 campbell faculty 0 Dec 24 12:23 se.tex
-rw-r--r-- 1 campbell faculty 0 Dec 24 12:21 shell.tex
-rw-r--r-- 1 campbell faculty 0 Dec 24 12:21 start.tex
[campbell@spruce lectures]$

[campbell@spruce lectures]$ ls -l *.tex


-rw-r--r-- 1 campbell faculty 0 Dec 24 12:22 bash-programming.tex
-rw-r--r-- 1 campbell faculty 0 Dec 24 12:22 c.tex
-rw-r--r-- 1 campbell faculty 0 Dec 24 12:23 design.tex
-rw-r--r-- 1 campbell faculty 0 Dec 24 12:22 linux-advance.tex
-rw-r--r-- 1 campbell faculty 0 Dec 24 12:23 se.tex
-rw-r--r-- 1 campbell faculty 0 Dec 24 12:21 shell.tex
-rw-r--r-- 1 campbell faculty 0 Dec 24 12:21 start.tex
[campbell@spruce lectures]$
Some cool tricks - an example

If I wanted to list just the directories or just plain files (i.e., non directory files) in a directory how would I
do that? Use ls, right. Sorry, ls does not have an option to list only directories or just plain files. But we can
use a combination of commands to do this!

We can write our own commands to do this job - we can use a combination of ls and grep to list directory
names only or plain file names only.

First let’s just list all the files in the home directory - it includes one plain file and the rest are directories.

[campbell@bear ~]$ cd ~
[campbell@bear ~]$ ls -l
total 40
drwx------ 2 campbell faculty 4096 2007-12-22 15:29 bin
drwx------ 15 campbell faculty 4096 2010-01-03 21:16 cs50
drwx------ 5 campbell faculty 4096 2008-05-11 15:18 cs60
drwx------ 2 campbell faculty 4096 2007-12-22 15:30 lib
drwx------ 3 campbell faculty 4096 2009-12-29 08:12 mail
drwx------ 2 campbell faculty 4096 2009-06-23 02:43 Mail
drwx------ 3 campbell faculty 4096 2007-12-24 23:23 papers
-rw-r--r-- 1 campbell faculty 0 2010-01-04 21:43 plainfile
drwxr-xr-x 6 campbell ug 4096 2009-12-02 12:41 public_html
drwx------ 3 campbell faculty 4096 2007-12-11 15:14 teaching
drwxr-xr-x 2 campbell faculty 4096 2009-04-08 09:48 trash

Now we use a combination of ls and grep and the pipe command. More on this is in a later lecture but now
we begin to see the power of the shell.

Let’s just list plain files:

[campbell@bear ~]$ ls -l | grep -v ^d


total 40
-rw-r--r-- 1 campbell faculty 0 2010-01-04 21:43 plainfile

Now, let’s use a modification on the above to just list directories:

[campbell@bear ~]$ ls -l | grep ^d


drwx------ 2 campbell faculty 4096 2007-12-22 15:29 bin
drwx------ 15 campbell faculty 4096 2010-01-03 21:16 cs50
drwx------ 5 campbell faculty 4096 2008-05-11 15:18 cs60
drwx------ 2 campbell faculty 4096 2007-12-22 15:30 lib
drwx------ 3 campbell faculty 4096 2009-12-29 08:12 mail
drwx------ 2 campbell faculty 4096 2009-06-23 02:43 Mail
drwx------ 3 campbell faculty 4096 2007-12-24 23:23 papers
drwxr-xr-x 6 campbell ug 4096 2009-12-02 12:41 public_html
drwx------ 3 campbell faculty 4096 2007-12-11 15:14 teaching
drwxr-xr-x 2 campbell faculty 4096 2009-04-08 09:48 trash

If you don’t know any of the above swicthes then use the man command. We can also use the -F switch to
show which file is a directory or not. Check it out.

[campbell@bear ~]$ ls -lF


total 140
drwx------ 2 campbell faculty 4096 Dec 22 2007 bin/
drwx------ 31 campbell faculty 4096 Jan 16 2013 cs50/
drwx------ 5 campbell faculty 4096 Apr 19 2012 cs60/
-rw------- 1 campbell faculty 532 Jun 22 2011 Drafts
drwx------ 2 campbell faculty 4096 Dec 22 2007 lib/
drwx------ 3 campbell faculty 4096 May 19 2013 mail/
drwx------ 2 campbell faculty 4096 Jun 23 2009 Mail/
drwx------ 3 campbell faculty 4096 Jan 2 2012 misc/
-rwxrwxrwx 1 campbell faculty 0 Jan 8 10:32 myls*
drwx------ 3 campbell faculty 4096 Dec 24 2007 papers/
drwxr-xr-x 8 campbell ug 12288 Jan 8 16:55 public_html/
-rw------- 1 campbell faculty 81979 Jun 22 2011 Sent Messages
drwx------ 2 campbell faculty 4096 Jan 8 10:55 solutions/
drwx------ 3 campbell faculty 4096 Dec 11 2007 teaching/

It is handy to be able to list just the directories when moving around the file system. So we’ll add these
commands to our bash files in the next lecture - we’ll create aliases of these commands so we can use them
any time.

We’ll there is a ls option to list directories and indeed there are many ways to do this; for example:

[campbell@bear ~]$ ls -d */
bin/ cs50/ cs60/ lib/ mail/ Mail/ papers/ public_html/ teaching/ trash/

[campbell@bear ~]$ echo */


bin/ cs50/ cs60/ lib/ mail/ Mail/ papers/ public_html/ teaching/ trash/
Creating and deleting directories and files

In the following sequence we will create a new directory, create two new files (using touch), move one file
to another directory, delete the other file and remove the directory.

[campbell@spruce cs50]$ pwd


/net/nusers/campbell/cs50

[campbell@spruce cs50]$ mkdir project

[campbell@spruce cs50]$ cd project

[campbell@spruce project]$ touch socket.c transport.c

[campbell@spruce project]$ ls
socket.c transport.c

[campbell@spruce project]$ mv transport.c ~/.

[campbell@spruce cs50]$ alias rm


alias rm=’rm -i’

[campbell@spruce project]$ alias rm=rm

[campbell@spruce project]$ rm socket.c

[campbell@spruce project]$ ls

[campbell@spruce project]$ cd ..

[campbell@spruce cs50]$ ls
assignments code lectures project

[campbell@spruce cs50]$ rmdir project

In the sequence above we reset the alias for rm which is set up in .bashrc. When you use the “rm -i” option
the shell will ask you to confirm if you really want to delete files. This is worth doing by setting up the
alias in your .bashrc file. It is easy to type “rm” and accidently delete files. Therefore, the “-i” (interactive)
option is a life saver. For example,

[campbell@spruce project]$ rm -i socket.c


rm: remove regular empty file ‘socket.c’? y
Hidden files

In the home directory there are a number of interesting “hidden” files. Using the “-a” lists all files
including those that begin with a dot (aka the hidden files).

[campbell@spruce ~]$ ls -al


total 899
drwxr-xr-x 21 campbell faculty 1448 Dec 24 14:58 .
drwxr-xr-x 25 root root 624 May 31 2007 ..
-rw-r--r-- 1 campbell faculty 0 Dec 23 18:45 .addressbook
-rw------- 1 campbell faculty 2285 Dec 23 18:45 .addressbook.lu
drwxr-xr-x 3 campbell faculty 72 Nov 6 22:57 .adobe
-rw------- 1 campbell faculty 4978 Dec 24 13:39 .bash_history
-rw-r--r-- 1 campbell ug 882 Jun 24 1997 .bash_logout
-rw-r--r-- 1 campbell faculty 1707 Dec 22 18:52 .bash_profile
-rw-r--r-- 1 campbell faculty 1411 Dec 22 19:18 .bashrc
... (snip)
-rw------- 1 campbell faculty 864 Dec 23 22:42 .Xauthority
drwx------ 2 campbell faculty 136 Nov 5 21:04 .xemacs

But a simple ls will only show:

[campbell@spruce ~]$ ls
bin cs50 lib mail papers public_html Sent Sent Messages teaching

50+ Essential Linux Commands: A


Comprehensive Guide
Updated on April 8, 2025

UNIX/Linux

Linux Commands

Linux Basics

By Anish Singh Walia

Sr Technical Writer
Introduction

Unlock the full potential of your Linux system with this comprehensive guide to essential Linux
commands. Whether you’re a seasoned administrator or just starting out, mastering these commands is
crucial for efficient server management, script writing, and troubleshooting. In this tutorial, you will learn
the most frequently used and powerful commands for file management, process control, user access,
network configuration, and system debugging.

You will learn over 50+ must-know Linux commands that will transform you into a Linux power user.
From basic to advanced, these commands will become your go-to tools for tackling any task that comes
your way.

Prerequisites

We will be running these commands on a Ubuntu server, but you can follow along on any modern Linux
distribution. You can set up a Ubuntu server for this tutorial by following our guide to Initial Server Setup
on Ubuntu.

Deploy your frontend applications from GitHub using DigitalOcean App Platform. Let DigitalOcean focus
on scaling your app.

Let’s get right into it!


Top 50 Linux Commands You Must Know as a Regular User

1. ls - The most frequently used command in Linux to list directories


2. pwd - Print working directory command in Linux
3. cd - Linux command to navigate through directories
4. mkdir - Command used to create directories in Linux
5. mv - Move or rename files in Linux
6. cp - Similar usage as mv but for copying files in Linux
7. rm - Delete files or directories
8. touch - Create blank/empty files
9. ln - Create symbolic links (shortcuts) to other files
10. clear - Clear the terminal display
11. cat - Display file contents on the terminal
12. echo - Print any text that follows the command
13. less - Linux command to display paged outputs in the terminal
14. man - Access manual pages for all Linux commands
15. uname - Linux command to get basic information about the OS
16. whoami - Get the active username
17. tar - Command to extract and compress files in linux
18. grep - Search for a string within an output
19. head - Return the specified number of lines from the top
20. tail - Return the specified number of lines from the bottom
21. diff - Find the difference between two files
22. cmp - Allows you to check if two files are identical
23. comm - Combines the functionality of diff and cmp
24. sort - Linux command to sort the content of a file while outputting
25. export - Export environment variables in Linux
26. zip - Zip files in Linux
27. unzip - Unzip files in Linux
28. ssh - Secure Shell command in Linux
29. service - Linux command to start and stop services
30. ps - Display active processes
31. kill and killall - Kill active processes by process ID or name
32. df - Display disk filesystem information
33. mount - Mount file systems in Linux
34. chmod - Command to change file permissions
35. chown - Command for granting ownership of files or folders
36. ifconfig - Display network interfaces and IP addresses
37. traceroute - Trace all the network hops to reach the destination
38. wget - Direct download files from the internet
39. ufw - Firewall command
40. iptables - Base firewall for all other firewall utilities to interface with
41. apt, pacman, yum, rpm - Package managers depending on the distribution
42. sudo - Command to escalate privileges in Linux
43. cal - View a command-line calendar
44. alias - Create custom shortcuts for your regularly used commands
45. dd - Majorly used for creating bootable USB sticks
46. whereis - Locate the binary, source, and manual pages for a command
47. whatis - Find what a command is used for
48. top - View active processes live with their system usage
49. useradd and usermod - Add a new user or change existing user data
50. passwd - Create or update passwords for existing users

File and Directory Commands


Command Description Example

ls List directory contents. ls

cd Change directory. cd /path/to/directory

pwd Show current directory. pwd

mkdir Create a new directory. mkdir new_directory

rmdir Remove an empty directory. rmdir empty_directory

rm Delete files or directories. rm file.txt

touch Create an empty file. touch new_file.txt

cp Copy files or directories. cp file.txt /path/to/destination

mv Move or rename files. mv file.txt /path/to/new_location

cat Display file contents. cat file.txt

nano / vim Edit files in terminal. nano file.txt

find Search for files in a directory hierarchy. find . -name "file.txt"

grep Search text using patterns. grep "pattern" file.txt

tar Archive and compress files. tar -cvf archive.tar file1.txt file2.txt

df Show disk usage of file systems. df

du Show directory/file size. du -sh /path/to/directory

chmod Change file permissions. chmod 755 file.txt

chown Change file owner. chown user:group file.txt

mount Mount a filesystem. mount /dev/sdb1 /mnt


Command Description Example

umount Unmount a filesystem. umount /mnt

Networking Commands
Command Description Sample Usage

ping Test connectivity to a host. ping google.com

ifconfig / ip
Display network interfaces. ifconfig or ip a
a

netstat / ss Show network connections. netstat -tuln or ss -tuln

wget Download files via HTTP/FTP. wget http://example.com/file.zip

curl Transfer data using URL syntax. curl -O http://example.com/file.zip

nc (Netcat) Network debugging and data transfer. nc -zv 192.168.1.1 80

tcpdump Capture and analyze network packets. tcpdump -i eth0

iptables -A INPUT -p tcp --dport 22 -j


iptables Configure firewall rules. ACCEPT

traceroute Trace the path packets take to a network host. traceroute example.com

Query DNS to obtain domain name or IP


nslookup nslookup example.com
address mapping.

ssh Securely connect to a remote host. ssh user@example.com

Process and System Monitoring Commands


Command Description Example Command

ps Show running processes. ps aux

top Dynamic process viewer. top

htop Enhanced version of top. htop

kill Send a signal to a process. kill <PID>

killall Kill processes by name. killall <process_name>


Command Description Example Command

uptime System uptime and load. uptime

whoami Current logged-in user. whoami

env Display environment variables. env

strace Trace system calls of a process. strace -p <PID>

systemctl Manage systemd services. systemctl status <service_name>

journalctl View system logs. journalctl -xe

free Display memory usage. free -h

vmstat Report virtual memory statistics. vmstat 1

iostat Report CPU and I/O statistics. iostat

lsof List open files by processes. lsof

dmesg Print kernel ring buffer messages. dmesg

User and Permission Management Commands


Command Description Example Command

passwd Change user password. passwd <username>

adduser / useradd Add a new user. adduser <username> or useradd <username>

deluser / userdel Delete a user. deluser <username> or userdel <username>

usermod Modify user account. usermod -aG <group> <username>

groups Show group memberships. groups <username>

sudo Execute commands as root. sudo <command>

chage Change user password expiry information. chage -l <username>

id Display user identity information. id <username>

newgrp Log in to a new group. newgrp <group>


File Transfer and Synchronization Commands
Command Description Example Command

scp Securely copy files over SSH. scp user@remote:/path/to/file /local/destination

rsync -avz /local/directory/


rsync Efficiently sync files and directories. user@remote:/path/to/destination

Transfer files using the File Transfer


ftp ftp ftp.example.com
Protocol.

Securely transfer files using SSH File


sftp sftp user@remote:/path/to/file
Transfer Protocol.

wget Download files from the web. wget http://example.com/file.zip

curl Transfer data from or to a server. curl -O http://example.com/file.zip

Text Processing Commands


Command Description Example Command

awk Pattern scanning and processing. awk '{print $1}' file.txt

sed Stream editor for filtering/modifying text. sed 's/old/new/g' file.txt

cut Remove sections from lines of text. cut -d':' -f1 /etc/passwd

sort Sort lines of text. sort file.txt

grep Search for patterns in text. grep 'pattern' file.txt

wc Count words, lines, and characters. wc -l file.txt

paste Merge lines of files. paste file1.txt file2.txt

join Join lines of two files on a common field. join file1.txt file2.txt

head Output the first part of files. head -n 10 file.txt

tail Output the last part of files. tail -n 10 file.txt

Shell Utilities and Shortcuts Commands


Command Description Example Command

alias Create shortcuts for commands. alias ll='ls -la'


Command Description Example Command

unalias Remove an alias. unalias ll

history Show previously entered commands. history

clear Clear the terminal screen. clear

reboot Reboot the system. reboot

shutdown Power off the system. shutdown now

date Display or set the system date and time. date

echo Display a line of text. echo "Hello, World!"

sleep Delay for a specified amount of time. sleep 5

time Measure the duration of command execution. time ls

watch Execute a program periodically, showing output fullscreen. watch -n 5 df -h

Now let’s dive a little deeper into each of these commands and understand them in more detail. We already
have a lot of existing articles for each of those individual commands. For your convenience, we’ll add links
to all the existing articles, and continue to update the article as new topics are covered.

The ls command in Linux

The ls command is used to list files and directories in the current working directory. This is going to be
one of the most frequently used Linux commands you must know of.

As you can see in the above image, using the command by itself without any arguments will give us an
output with all the files and directories in the directory. The command offers a lot of flexibility in terms of
displaying the data in the output.

Learn more about using the ls command


Jump back to commands list ↑

The pwd command in Linux

The pwd command allows you to print the current working directory on your terminal. It’s a very basic
command and solves its purpose very well.

Now, your terminal prompt should usually have the complete directory anyway. But in case it doesn’t, this
can be a quick command to see the directory that you’re in. Another application of this command is when
creating scripts where this command can allow us to find the directory where the script has been saved.

Jump back to commands list ↑

The cd command in Linux

While working within the terminal, moving around within directories is pretty much a necessity. The cd
command is one of the important Linux commands you must know, and it will help you navigate through
directories. Just type cd followed by directory, as shown below.

root@ubuntu:~# cd <directory path>

As you can see in the above command, I simply typed cd /etc/ to get into the /etc directory. We used the
pwd command to print the current working directory.

Jump back to commands list ↑

The cd command in Linux

While working within the terminal, moving around within directories is pretty much a necessity. The cd
command is one of the important Linux commands you must know, and it will help you navigate through
directories. Just type cd followed by directory, as shown below.
root@ubuntu:~# cd <directory path>

As you can see in the above command, I simply typed cd /etc/ to get into the /etc directory. We used the
pwd command to print the current working directory.

Jump back to commands list ↑

The mkdir command in Linux

The mkdir command allows you to create directories from within the terminal.

root@ubuntu:~# mkdir <folder name>

As you can see in the above screenshot, we created the JournalDev directory with just this simple
command.

Jump back to commands list ↑

The mkdir command in Linux

The mkdir command allows you to create directories from within the terminal.

root@ubuntu:~# mkdir <folder name>


As you can see in the above screenshot, we created the JournalDev directory with just this simple
command.

Jump back to commands list ↑

The cp and mv commands

The cp and mv commands are equivalent to the copy-paste and cut-paste commands in Windows. But since
Linux doesn’t really have a command for renaming files, we also use the mv command to rename files and
folders.

root@ubuntu:~# cp <source> <destination>

In the above command, we created a copy of the file named Sample. Let’s see how what happens if we use
the mv command in the same manner.

root@ubuntu:~# mv <source> <destination


In the above case, since we were moving the file within the same directory, it acted as a rename. The file
name is now changed.

Jump back to commands list ↑

The cp and mv commands

The cp and mv commands are equivalent to the copy-paste and cut-paste commands in Windows. But since
Linux doesn’t really have a command for renaming files, we also use the mv command to rename files and
folders.

root@ubuntu:~# cp <source> <destination>

In the above command, we created a copy of the file named Sample. Let’s see how what happens if we use
the mv command in the same manner.

root@ubuntu:~# mv <source> <destination

In the above case, since we were moving the file within the same directory, it acted as a rename. The file
name is now changed.

Jump back to commands list ↑


The cp and mv commands

The cp and mv commands are equivalent to the copy-paste and cut-paste commands in Windows. But since
Linux doesn’t really have a command for renaming files, we also use the mv command to rename files and
folders.

root@ubuntu:~# cp <source> <destination>

In the above command, we created a copy of the file named Sample. Let’s see how what happens if we use
the mv command in the same manner.

root@ubuntu:~# mv <source> <destination

In the above case, since we were moving the file within the same directory, it acted as a rename. The file
name is now changed.

Jump back to commands list ↑

The rm command in Linux

In the previous section, we deleted the Sample-Copy file. The rm command is used to delete files and
folders and is one of the important Linux commands you must know.

root@ubuntu:~# rm <file name>


To delete a directory, you must add the -r argument to it. Without the -r argument, the rm command won’t
delete directories.

root@ubuntu:~# rm -r <folder/directory name>

The -r flag in the rm command in Linux stands for “recursive”. When used with the rm command, it will
remove not only the specified file but also all of its subdirectories and the files within those subdirectories
recursively.

Note: It’s important to be careful when using the rm command with the -r flag, as it can quickly and
permanently delete a large number of files and directories. It’s a good idea to use the -i flag in conjunction
with the -r flag, which will prompt you for confirmation before deleting each file and directory.

For example, to remove the mydir directory and its contents with confirmation, you can use this command:

root@ubuntu:~# rm -ri mydir

This will prompt you for confirmation before deleting each file and directory within the mydir directory.

Jump back to commands list ↑

The rm command in Linux

In the previous section, we deleted the Sample-Copy file. The rm command is used to delete files and
folders and is one of the important Linux commands you must know.

root@ubuntu:~# rm <file name>

To delete a directory, you must add the -r argument to it. Without the -r argument, the rm command won’t
delete directories.
root@ubuntu:~# rm -r <folder/directory name>

The -r flag in the rm command in Linux stands for “recursive”. When used with the rm command, it will
remove not only the specified file but also all of its subdirectories and the files within those subdirectories
recursively.

Note: It’s important to be careful when using the rm command with the -r flag, as it can quickly and
permanently delete a large number of files and directories. It’s a good idea to use the -i flag in conjunction
with the -r flag, which will prompt you for confirmation before deleting each file and directory.

For example, to remove the mydir directory and its contents with confirmation, you can use this command:

root@ubuntu:~# rm -ri mydir

This will prompt you for confirmation before deleting each file and directory within the mydir directory.

Jump back to commands list ↑

The rm command in Linux

In the previous section, we deleted the Sample-Copy file. The rm command is used to delete files and
folders and is one of the important Linux commands you must know.

root@ubuntu:~# rm <file name>

To delete a directory, you must add the -r argument to it. Without the -r argument, the rm command won’t
delete directories.

root@ubuntu:~# rm -r <folder/directory name>

The -r flag in the rm command in Linux stands for “recursive”. When used with the rm command, it will
remove not only the specified file but also all of its subdirectories and the files within those subdirectories
recursively.

Note: It’s important to be careful when using the rm command with the -r flag, as it can quickly and
permanently delete a large number of files and directories. It’s a good idea to use the -i flag in conjunction
with the -r flag, which will prompt you for confirmation before deleting each file and directory.
For example, to remove the mydir directory and its contents with confirmation, you can use this command:

root@ubuntu:~# rm -ri mydir

This will prompt you for confirmation before deleting each file and directory within the mydir directory.

Jump back to commands list ↑

The rm command in Linux

In the previous section, we deleted the Sample-Copy file. The rm command is used to delete files and
folders and is one of the important Linux commands you must know.

root@ubuntu:~# rm <file name>

To delete a directory, you must add the -r argument to it. Without the -r argument, the rm command won’t
delete directories.

root@ubuntu:~# rm -r <folder/directory name>

The -r flag in the rm command in Linux stands for “recursive”. When used with the rm command, it will
remove not only the specified file but also all of its subdirectories and the files within those subdirectories
recursively.

Note: It’s important to be careful when using the rm command with the -r flag, as it can quickly and
permanently delete a large number of files and directories. It’s a good idea to use the -i flag in conjunction
with the -r flag, which will prompt you for confirmation before deleting each file and directory.

For example, to remove the mydir directory and its contents with confirmation, you can use this command:

root@ubuntu:~# rm -ri mydir

This will prompt you for confirmation before deleting each file and directory within the mydir directory.

Jump back to commands list ↑


The touch command in Linux

The touch command in Linux creates an empty file or updates the timestamp of an existing file.

root@ubuntu:~# touch <file name>

Jump back to commands list ↑

The touch command in Linux

The touch command in Linux creates an empty file or updates the timestamp of an existing file.

root@ubuntu:~# touch <file name>

Jump back to commands list ↑

The ln command in Linux

To create a link to another file, we use the ln command. This is one of the most important Linux
commands that you should know if you’re planning to work as a Linux administrator.

root@ubuntu:~# ln -s <source path> <link name>


The -s flag creates a symbolic link (also known as a symlink or soft link) to a file or directory. A symbolic
link is a special type of file that acts as a shortcut or pointer to another file or directory.

By default, the ln command will make hard links instead of symbolic or soft links.

Note: Say you have a text file. If you make a symbolic link to that file, the link is only a pointer to the
original file. If you delete the original file, the link will be broken, as it no longer has anything to point to.

A hard link is a mirror copy of an original file with the exact same contents. Like symbolic links, if you
edit the contents of the original file, those changes will be reflected in the hard link. If you delete the
original file, though, the hard link will still work, and you can view and edit it as you would a normal copy
of the original file.

Learn more about Soft and Hard Links.

Jump back to commands list ↑

The ln command in Linux

To create a link to another file, we use the ln command. This is one of the most important Linux
commands that you should know if you’re planning to work as a Linux administrator.

root@ubuntu:~# ln -s <source path> <link name>


The -s flag creates a symbolic link (also known as a symlink or soft link) to a file or directory. A symbolic
link is a special type of file that acts as a shortcut or pointer to another file or directory.

By default, the ln command will make hard links instead of symbolic or soft links.

Note: Say you have a text file. If you make a symbolic link to that file, the link is only a pointer to the
original file. If you delete the original file, the link will be broken, as it no longer has anything to point to.

A hard link is a mirror copy of an original file with the exact same contents. Like symbolic links, if you
edit the contents of the original file, those changes will be reflected in the hard link. If you delete the
original file, though, the hard link will still work, and you can view and edit it as you would a normal copy
of the original file.

Learn more about Soft and Hard Links.

Jump back to commands list ↑

The clear command in Linux

The clear command in Linux clears the terminal screen. It removes all the text and output currently
displayed on the terminal and gives you a clean slate to work with.

Here is an example of how to use the clear command:

root@ubuntu:~# clear

This will clear the terminal screen and move the cursor to the top-left corner of the screen.

You can also use the clear command in combination with other commands, like this:

root@ubuntu:~# ls -l; clear

This will list the files and directories in the current directory, and then clear the terminal screen.
Note: The clear command does not delete any files or data from your system. It only affects the display of
the terminal.

The clear command in Linux

The clear command in Linux clears the terminal screen. It removes all the text and output currently
displayed on the terminal and gives you a clean slate to work with.

Here is an example of how to use the clear command:

root@ubuntu:~# clear

This will clear the terminal screen and move the cursor to the top-left corner of the screen.

You can also use the clear command in combination with other commands, like this:

root@ubuntu:~# ls -l; clear

This will list the files and directories in the current directory, and then clear the terminal screen.

Note: The clear command does not delete any files or data from your system. It only affects the display of
the terminal.

The clear command in Linux

The clear command in Linux clears the terminal screen. It removes all the text and output currently
displayed on the terminal and gives you a clean slate to work with.

Here is an example of how to use the clear command:

root@ubuntu:~# clear

This will clear the terminal screen and move the cursor to the top-left corner of the screen.

You can also use the clear command in combination with other commands, like this:

root@ubuntu:~# ls -l; clear

This will list the files and directories in the current directory, and then clear the terminal screen.

Note: The clear command does not delete any files or data from your system. It only affects the display of
the terminal.
The cat, echo, and less commands

When you want to output the contents of a file or print anything to the terminal output, we use the cat or
echo commands. Let’s see their basic usage.

root@ubuntu:~# cat <file name>


root@ubuntu:~# echo <Text to print on terminal>

As you can see in the above example, the cat command, when used on our New-File, prints the contents
of the file. At the same time, when we use echo command, it simply prints whatever follows after the
command.

The less command is used when the output printed by any command is larger than the screen space and
needs scrolling. The less command allows the user to break down the output and scroll through it with the
use of the enter or space keys.

The simple way to do this is with the use of the pipe operator (|).

root@ubuntu:~# cat /boot/grub/grub.cfg | less

Note: Use the -S flag with less to enable line wrapping. This will allow you to view long lines of text
without scrolling horizontally.

Use the -N flag with less to display line numbers. This can be useful when you need to know the line
number of a specific piece of text.

You can use these useful flags in the following way:

root@ubuntu:~# cat /boot/grub/grub.cfg | less -SN

Using less with the pipe operator can be useful in many different situations. Here are a few examples:

 Viewing the output of a long-running command, such as top or htop.


 Searching for specific text in the output of a command, such as grep or cat .

Jump back to commands list ↑


The cat, echo, and less commands

When you want to output the contents of a file or print anything to the terminal output, we use the cat or
echo commands. Let’s see their basic usage.

root@ubuntu:~# cat <file name>


root@ubuntu:~# echo <Text to print on terminal>

As you can see in the above example, the cat command, when used on our New-File, prints the contents
of the file. At the same time, when we use echo command, it simply prints whatever follows after the
command.

The less command is used when the output printed by any command is larger than the screen space and
needs scrolling. The less command allows the user to break down the output and scroll through it with the
use of the enter or space keys.

The simple way to do this is with the use of the pipe operator (|).

root@ubuntu:~# cat /boot/grub/grub.cfg | less

Note: Use the -S flag with less to enable line wrapping. This will allow you to view long lines of text
without scrolling horizontally.

Use the -N flag with less to display line numbers. This can be useful when you need to know the line
number of a specific piece of text.

You can use these useful flags in the following way:

root@ubuntu:~# cat /boot/grub/grub.cfg | less -SN

Using less with the pipe operator can be useful in many different situations. Here are a few examples:

 Viewing the output of a long-running command, such as top or htop.


 Searching for specific text in the output of a command, such as grep or cat .

Jump back to commands list ↑


The cat, echo, and less commands

When you want to output the contents of a file or print anything to the terminal output, we use the cat or
echo commands. Let’s see their basic usage.

root@ubuntu:~# cat <file name>


root@ubuntu:~# echo <Text to print on terminal>

As you can see in the above example, the cat command, when used on our New-File, prints the contents
of the file. At the same time, when we use echo command, it simply prints whatever follows after the
command.

The less command is used when the output printed by any command is larger than the screen space and
needs scrolling. The less command allows the user to break down the output and scroll through it with the
use of the enter or space keys.

The simple way to do this is with the use of the pipe operator (|).

root@ubuntu:~# cat /boot/grub/grub.cfg | less

Note: Use the -S flag with less to enable line wrapping. This will allow you to view long lines of text
without scrolling horizontally.

Use the -N flag with less to display line numbers. This can be useful when you need to know the line
number of a specific piece of text.

You can use these useful flags in the following way:

root@ubuntu:~# cat /boot/grub/grub.cfg | less -SN

Using less with the pipe operator can be useful in many different situations. Here are a few examples:

 Viewing the output of a long-running command, such as top or htop.


 Searching for specific text in the output of a command, such as grep or cat .

Jump back to commands list ↑


The cat, echo, and less commands

When you want to output the contents of a file or print anything to the terminal output, we use the cat or
echo commands. Let’s see their basic usage.

root@ubuntu:~# cat <file name>


root@ubuntu:~# echo <Text to print on terminal>

As you can see in the above example, the cat command, when used on our New-File, prints the contents
of the file. At the same time, when we use echo command, it simply prints whatever follows after the
command.

The less command is used when the output printed by any command is larger than the screen space and
needs scrolling. The less command allows the user to break down the output and scroll through it with the
use of the enter or space keys.

The simple way to do this is with the use of the pipe operator (|).

root@ubuntu:~# cat /boot/grub/grub.cfg | less

Note: Use the -S flag with less to enable line wrapping. This will allow you to view long lines of text
without scrolling horizontally.

Use the -N flag with less to display line numbers. This can be useful when you need to know the line
number of a specific piece of text.

You can use these useful flags in the following way:

root@ubuntu:~# cat /boot/grub/grub.cfg | less -SN

Using less with the pipe operator can be useful in many different situations. Here are a few examples:

 Viewing the output of a long-running command, such as top or htop.


 Searching for specific text in the output of a command, such as grep or cat .

Jump back to commands list ↑


The man command in Linux

The man command is a very useful Linux command one must know. When working with Linux, the
packages that we download can have a lot of functionality. Knowing it all is impossible.

The man command in Linux is used to display the manual page for a specific command. It provides detailed
information about the command, including its syntax, options, and examples.

Here’s an example of how to use the man command:

1. Open a terminal and type man ls to display the manual page for the ls command.

root@ubuntu:~# man ls

This will display a page that looks something like this:

Output
LS(1) User Commands LS(1)

NAME
ls - list directory contents

SYNOPSIS
ls [OPTION]... [FILE]...

DESCRIPTION
List information about the FILEs (the current directory by default).

Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Mandatory arguments to long options are mandatory for short options too.

-a, --all
do not ignore entries starting with .

-A, --almost-all
do not list implied . and ..

-c with -lt: sort by, and show, ctime (time of last modification
of file status information) with -l: show ctime and sort
by name;
...

Jump back to commands list ↑

The man command in Linux

The man command is a very useful Linux command one must know. When working with Linux, the
packages that we download can have a lot of functionality. Knowing it all is impossible.
The man command in Linux is used to display the manual page for a specific command. It provides detailed
information about the command, including its syntax, options, and examples.

Here’s an example of how to use the man command:

1. Open a terminal and type man ls to display the manual page for the ls command.

root@ubuntu:~# man ls

This will display a page that looks something like this:

Output
LS(1) User Commands LS(1)

NAME
ls - list directory contents

SYNOPSIS
ls [OPTION]... [FILE]...

DESCRIPTION
List information about the FILEs (the current directory by default).

Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Mandatory arguments to long options are mandatory for short options too.

-a, --all
do not ignore entries starting with .

-A, --almost-all
do not list implied . and ..

-c with -lt: sort by, and show, ctime (time of last modification
of file status information) with -l: show ctime and sort
by name;
...

Jump back to commands list ↑

The man command in Linux

The man command is a very useful Linux command one must know. When working with Linux, the
packages that we download can have a lot of functionality. Knowing it all is impossible.

The man command in Linux is used to display the manual page for a specific command. It provides detailed
information about the command, including its syntax, options, and examples.

Here’s an example of how to use the man command:

1. Open a terminal and type man ls to display the manual page for the ls command.
root@ubuntu:~# man ls

This will display a page that looks something like this:

Output
LS(1) User Commands LS(1)

NAME
ls - list directory contents

SYNOPSIS
ls [OPTION]... [FILE]...

DESCRIPTION
List information about the FILEs (the current directory by default).

Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Mandatory arguments to long options are mandatory for short options too.

-a, --all
do not ignore entries starting with .

-A, --almost-all
do not list implied . and ..

-c with -lt: sort by, and show, ctime (time of last modification
of file status information) with -l: show ctime and sort
by name;
...

Jump back to commands list ↑

The uname and whoami commands

The uname and whoami commands allow you to access some basic information that comes in handy when
you work on multiple systems.

The uname command in Linux displays information about the system’s kernel, including the kernel name,
hostname, kernel release, kernel version, and machine hardware name.

The whoami command in Linux returns the current user’s username. It stands for “who am I?” and it’s
often used to determine the current user’s identity in shell scripts or the terminal.

Let’s see the output of both the commands and the way we can use these.

root@ubuntu:~# uname -a
The parameter -a with uname command stands for “all”. This prints out the complete information. If the
parameter is not added, all you will get as the output is “Linux”.

Note: Some important flags you can use with the uname command.

1. Use uname -s to display the kernel name.


2. Use uname -n to display the hostname.
3. Use uname -r to display the kernel release.
4. Use uname -v to display the kernel version.
5. Use uname -m to display the machine hardware name.

Jump back to commands list ↑

The uname and whoami commands

The uname and whoami commands allow you to access some basic information that comes in handy when
you work on multiple systems.

The uname command in Linux displays information about the system’s kernel, including the kernel name,
hostname, kernel release, kernel version, and machine hardware name.

The whoami command in Linux returns the current user’s username. It stands for “who am I?” and it’s
often used to determine the current user’s identity in shell scripts or the terminal.

Let’s see the output of both the commands and the way we can use these.

root@ubuntu:~# uname -a

The parameter -a with uname command stands for “all”. This prints out the complete information. If the
parameter is not added, all you will get as the output is “Linux”.
Note: Some important flags you can use with the uname command.

1. Use uname -s to display the kernel name.


2. Use uname -n to display the hostname.
3. Use uname -r to display the kernel release.
4. Use uname -v to display the kernel version.
5. Use uname -m to display the machine hardware name.

Jump back to commands list ↑

The tar, zip, and unzip commands

The tar command in Linux is used to create and extract archived files. We can extract multiple different
archive files using the tar command.

To create an archive, we use the -c parameter, and to extract an archive, we use the -x parameter. Let’s see
how it works.

#Compress
root@ubuntu:~# tar -cvf <archive name> <files separated by space>
#Extract
root@ubuntu:~# tar -xvf <archive name>

In the first line, we created an archive named Compress.tar with the New-File and New-File-Link. In the
next command, we have extracted those files from the archive.

Let’s discuss the zip and unzip commands. Both are very straightforward. You can use them without any
parameters, and they’ll work as intended. Let’s see an example below.

root@ubuntu:~# zip <archive name> <file names separated by space>


root@ubuntu:~# unzip <archive name>
Since we already have those files in the same directory, the unzip command prompts us before overwriting
those files.

Jump back to commands list ↑

The tar, zip, and unzip commands

The tar command in Linux is used to create and extract archived files. We can extract multiple different
archive files using the tar command.

To create an archive, we use the -c parameter, and to extract an archive, we use the -x parameter. Let’s see
how it works.

#Compress
root@ubuntu:~# tar -cvf <archive name> <files separated by space>
#Extract
root@ubuntu:~# tar -xvf <archive name>

In the first line, we created an archive named Compress.tar with the New-File and New-File-Link. In the
next command, we have extracted those files from the archive.

Let’s discuss the zip and unzip commands. Both are very straightforward. You can use them without any
parameters, and they’ll work as intended. Let’s see an example below.
root@ubuntu:~# zip <archive name> <file names separated by space>
root@ubuntu:~# unzip <archive name>

Since we already have those files in the same directory, the unzip command prompts us before overwriting
those files.

Jump back to commands list ↑

The tar, zip, and unzip commands

The tar command in Linux is used to create and extract archived files. We can extract multiple different
archive files using the tar command.

To create an archive, we use the -c parameter, and to extract an archive, we use the -x parameter. Let’s see
how it works.

#Compress
root@ubuntu:~# tar -cvf <archive name> <files separated by space>
#Extract
root@ubuntu:~# tar -xvf <archive name>

In the first line, we created an archive named Compress.tar with the New-File and New-File-Link. In the
next command, we have extracted those files from the archive.
Let’s discuss the zip and unzip commands. Both are very straightforward. You can use them without any
parameters, and they’ll work as intended. Let’s see an example below.

root@ubuntu:~# zip <archive name> <file names separated by space>


root@ubuntu:~# unzip <archive name>

Since we already have those files in the same directory, the unzip command prompts us before overwriting
those files.

Jump back to commands list ↑

The grep command in Linux

The grep command is a powerful and versatile text search tool in Linux and Unix-based operating systems.
It can search for specific patterns or strings in one or more files and filter the output of other commands.

The grep command stands for “global regular expression print,” which reflects its ability to search for
regular expressions across multiple lines and files.

root@ubuntu:~# <Any command with output> | grep "<string to find>"

This was a simple demonstration of the command. Learn more about the grep command.

Jump back to commands list ↑


The grep command in Linux

The grep command is a powerful and versatile text search tool in Linux and Unix-based operating systems.
It can search for specific patterns or strings in one or more files and filter the output of other commands.

The grep command stands for “global regular expression print,” which reflects its ability to search for
regular expressions across multiple lines and files.

root@ubuntu:~# <Any command with output> | grep "<string to find>"

This was a simple demonstration of the command. Learn more about the grep command.

Jump back to commands list ↑

The head and tail commands

When outputting large files, the head and tail commands come in handy. These commands display the
beginning or end of a file, respectively. They are commonly used to quickly view the contents of a file
without having to open it in a text editor.

The head and tail commands display the first 10 lines of a file by default. To display a different number
of lines, you can use the -n option, followed by the number of lines you want to display.

Here’s an example of using the head and tail commands:

root@ubuntu:~# head <file name>


root@ubuntu:~# tail <file name>
As you can see, the head command showed 10 lines from the top of the file.

The tail command outputted the bottom 10 lines from the file.

These commands can be used to quickly view a file’s contents, monitor real-time updates for
troubleshooting issues, filter output from other commands, and perform log analysis.

Jump back to commands list ↑


The head and tail commands

When outputting large files, the head and tail commands come in handy. These commands display the
beginning or end of a file, respectively. They are commonly used to quickly view the contents of a file
without having to open it in a text editor.

The head and tail commands display the first 10 lines of a file by default. To display a different number
of lines, you can use the -n option, followed by the number of lines you want to display.

Here’s an example of using the head and tail commands:

root@ubuntu:~# head <file name>


root@ubuntu:~# tail <file name>

As you can see, the head command showed 10 lines from the top of the file.
The tail command outputted the bottom 10 lines from the file.

These commands can be used to quickly view a file’s contents, monitor real-time updates for
troubleshooting issues, filter output from other commands, and perform log analysis.

Jump back to commands list ↑

The diff, comm, and cmp commands

The diff, comm, and cmp commands are all used to compare files in Linux and Unix-based operating
systems. These commands can be used to identify differences between two files, merge changes, and
perform other file comparison tasks.

root@ubuntu:~# diff <file 1> <file 2>

As you can see above, we have added a small piece of text saying, “This line is edited” to the New-File-
Edited file.

The cmp command is used to compare two files and display the first byte that is different between them. It
can be used to identify differences between binary files or to check for corruption in files.
root@ubuntu:~# cmp <file 1> <file 2>

The cmp command only tells us the line number, which is different. Not the actual text.

The comm command is used to compare two sorted files and display the lines that are unique to each file, as
well as the lines that are common to both files.

root@ubuntu:~# comm <file 1> <file2>

The text that’s aligned to the left is only present in file 1. The centre-aligned text is present only in file
2. And the right-aligned text is present in both files.

By the looks of it, comm command makes the most sense when we’re trying to compare larger files and
would like to see everything arranged together.

All three of these commands are essential tools for working with files in Linux and Unix-based operating
systems. By understanding how to use the diff, comm, and cmp commands effectively, you can identify
differences between files, merge changes, and perform other file comparison tasks.

These commands can help you to identify and resolve issues with files, as well as to track changes and
maintain version control. Whether you’re a developer or a system administrator, these commands are an
essential part of your toolkit.

Jump back to commands list ↑


The diff, comm, and cmp commands

The diff, comm, and cmp commands are all used to compare files in Linux and Unix-based operating
systems. These commands can be used to identify differences between two files, merge changes, and
perform other file comparison tasks.

root@ubuntu:~# diff <file 1> <file 2>

As you can see above, we have added a small piece of text saying, “This line is edited” to the New-File-
Edited file.

The cmp command is used to compare two files and display the first byte that is different between them. It
can be used to identify differences between binary files or to check for corruption in files.

root@ubuntu:~# cmp <file 1> <file 2>

The cmp command only tells us the line number, which is different. Not the actual text.

The comm command is used to compare two sorted files and display the lines that are unique to each file, as
well as the lines that are common to both files.

root@ubuntu:~# comm <file 1> <file2>


The text that’s aligned to the left is only present in file 1. The centre-aligned text is present only in file
2. And the right-aligned text is present in both files.

By the looks of it, comm command makes the most sense when we’re trying to compare larger files and
would like to see everything arranged together.

All three of these commands are essential tools for working with files in Linux and Unix-based operating
systems. By understanding how to use the diff, comm, and cmp commands effectively, you can identify
differences between files, merge changes, and perform other file comparison tasks.

These commands can help you to identify and resolve issues with files, as well as to track changes and
maintain version control. Whether you’re a developer or a system administrator, these commands are an
essential part of your toolkit.

Jump back to commands list ↑

The diff, comm, and cmp commands

The diff, comm, and cmp commands are all used to compare files in Linux and Unix-based operating
systems. These commands can be used to identify differences between two files, merge changes, and
perform other file comparison tasks.

root@ubuntu:~# diff <file 1> <file 2>


As you can see above, we have added a small piece of text saying, “This line is edited” to the New-File-
Edited file.

The cmp command is used to compare two files and display the first byte that is different between them. It
can be used to identify differences between binary files or to check for corruption in files.

root@ubuntu:~# cmp <file 1> <file 2>

The cmp command only tells us the line number, which is different. Not the actual text.

The comm command is used to compare two sorted files and display the lines that are unique to each file, as
well as the lines that are common to both files.

root@ubuntu:~# comm <file 1> <file2>

The text that’s aligned to the left is only present in file 1. The centre-aligned text is present only in file
2. And the right-aligned text is present in both files.

By the looks of it, comm command makes the most sense when we’re trying to compare larger files and
would like to see everything arranged together.

All three of these commands are essential tools for working with files in Linux and Unix-based operating
systems. By understanding how to use the diff, comm, and cmp commands effectively, you can identify
differences between files, merge changes, and perform other file comparison tasks.

These commands can help you to identify and resolve issues with files, as well as to track changes and
maintain version control. Whether you’re a developer or a system administrator, these commands are an
essential part of your toolkit.
Jump back to commands list ↑

The diff, comm, and cmp commands

The diff, comm, and cmp commands are all used to compare files in Linux and Unix-based operating
systems. These commands can be used to identify differences between two files, merge changes, and
perform other file comparison tasks.

root@ubuntu:~# diff <file 1> <file 2>

As you can see above, we have added a small piece of text saying, “This line is edited” to the New-File-
Edited file.

The cmp command is used to compare two files and display the first byte that is different between them. It
can be used to identify differences between binary files or to check for corruption in files.

root@ubuntu:~# cmp <file 1> <file 2>

The cmp command only tells us the line number, which is different. Not the actual text.

The comm command is used to compare two sorted files and display the lines that are unique to each file, as
well as the lines that are common to both files.

root@ubuntu:~# comm <file 1> <file2>


The text that’s aligned to the left is only present in file 1. The centre-aligned text is present only in file
2. And the right-aligned text is present in both files.

By the looks of it, comm command makes the most sense when we’re trying to compare larger files and
would like to see everything arranged together.

All three of these commands are essential tools for working with files in Linux and Unix-based operating
systems. By understanding how to use the diff, comm, and cmp commands effectively, you can identify
differences between files, merge changes, and perform other file comparison tasks.

These commands can help you to identify and resolve issues with files, as well as to track changes and
maintain version control. Whether you’re a developer or a system administrator, these commands are an
essential part of your toolkit.

Jump back to commands list ↑

The sort command in Linux

The sort command is used to sort lines in a text file or standard input in Linux and Unix-based operating
systems. It can be used to sort lines in ascending or descending order and to perform other sorting
operations, such as sorting by fields or using a custom sorting order.

The basic syntax of the sort command is:

root@ubuntu:~# sort <filename>


By default, the sort command sorts lines in ASCII collating sequence, which can lead to unexpected
results when sorting numbers or special characters. To sort numbers in numerical order, you can use the -n
option.

Here’s an example of using the -n option:

root@ubuntu:~# sort -n file.txt

The above command will sort the lines in file.txt in numerical order.

The sort command can also be used to sort lines based on specific fields using the -k option.

Here’s an example of using the -k option:

root@ubuntu:~# sort -k 2 file.txt

This command will sort the lines in file.txt based on the second field.

The sort command is a powerful and flexible tool for working with text files in Linux and Unix-based
operating systems. By understanding how to use the sort command effectively, you can sort lines in text
files, sort lines based on specific fields, and perform other sorting operations.

These commands can help you organize and analyze data and perform other file manipulation tasks.
Whether you’re a developer or a system administrator, the sort command is an essential part of your
toolkit.

Jump back to commands list ↑

The sort command in Linux

The sort command is used to sort lines in a text file or standard input in Linux and Unix-based operating
systems. It can be used to sort lines in ascending or descending order and to perform other sorting
operations, such as sorting by fields or using a custom sorting order.
The basic syntax of the sort command is:

root@ubuntu:~# sort <filename>

By default, the sort command sorts lines in ASCII collating sequence, which can lead to unexpected
results when sorting numbers or special characters. To sort numbers in numerical order, you can use the -n
option.

Here’s an example of using the -n option:

root@ubuntu:~# sort -n file.txt

The above command will sort the lines in file.txt in numerical order.

The sort command can also be used to sort lines based on specific fields using the -k option.

Here’s an example of using the -k option:

root@ubuntu:~# sort -k 2 file.txt

This command will sort the lines in file.txt based on the second field.

The sort command is a powerful and flexible tool for working with text files in Linux and Unix-based
operating systems. By understanding how to use the sort command effectively, you can sort lines in text
files, sort lines based on specific fields, and perform other sorting operations.

These commands can help you organize and analyze data and perform other file manipulation tasks.
Whether you’re a developer or a system administrator, the sort command is an essential part of your
toolkit.

Jump back to commands list ↑


The sort command in Linux

The sort command is used to sort lines in a text file or standard input in Linux and Unix-based operating
systems. It can be used to sort lines in ascending or descending order and to perform other sorting
operations, such as sorting by fields or using a custom sorting order.

The basic syntax of the sort command is:

root@ubuntu:~# sort <filename>

By default, the sort command sorts lines in ASCII collating sequence, which can lead to unexpected
results when sorting numbers or special characters. To sort numbers in numerical order, you can use the -n
option.

Here’s an example of using the -n option:

root@ubuntu:~# sort -n file.txt

The above command will sort the lines in file.txt in numerical order.

The sort command can also be used to sort lines based on specific fields using the -k option.

Here’s an example of using the -k option:

root@ubuntu:~# sort -k 2 file.txt

This command will sort the lines in file.txt based on the second field.

The sort command is a powerful and flexible tool for working with text files in Linux and Unix-based
operating systems. By understanding how to use the sort command effectively, you can sort lines in text
files, sort lines based on specific fields, and perform other sorting operations.
These commands can help you organize and analyze data and perform other file manipulation tasks.
Whether you’re a developer or a system administrator, the sort command is an essential part of your
toolkit.

Jump back to commands list ↑

The sort command in Linux

The sort command is used to sort lines in a text file or standard input in Linux and Unix-based operating
systems. It can be used to sort lines in ascending or descending order and to perform other sorting
operations, such as sorting by fields or using a custom sorting order.

The basic syntax of the sort command is:

root@ubuntu:~# sort <filename>

By default, the sort command sorts lines in ASCII collating sequence, which can lead to unexpected
results when sorting numbers or special characters. To sort numbers in numerical order, you can use the -n
option.

Here’s an example of using the -n option:

root@ubuntu:~# sort -n file.txt

The above command will sort the lines in file.txt in numerical order.

The sort command can also be used to sort lines based on specific fields using the -k option.

Here’s an example of using the -k option:

root@ubuntu:~# sort -k 2 file.txt

This command will sort the lines in file.txt based on the second field.
The sort command is a powerful and flexible tool for working with text files in Linux and Unix-based
operating systems. By understanding how to use the sort command effectively, you can sort lines in text
files, sort lines based on specific fields, and perform other sorting operations.

These commands can help you organize and analyze data and perform other file manipulation tasks.
Whether you’re a developer or a system administrator, the sort command is an essential part of your
toolkit.

Jump back to commands list ↑

The export command in Linux

The export command in Linux and Unix-based operating systems is used to set environment variables.
Environment variables are used to store information that can be used by processes or commands.

Once an environment variable is set, it can be accessed by any process or command that is running in the
same shell.

Environment variables can be used to store a wide range of information, such as configuration settings,
user preferences, or system information.

Here’s an example of using the export command:

root@ubuntu:~# export <variable name>=<value>

Learn more about the export command

Jump back to commands list ↑

The export command in Linux

The export command in Linux and Unix-based operating systems is used to set environment variables.
Environment variables are used to store information that can be used by processes or commands.

Once an environment variable is set, it can be accessed by any process or command that is running in the
same shell.

Environment variables can be used to store a wide range of information, such as configuration settings,
user preferences, or system information.

Here’s an example of using the export command:


root@ubuntu:~# export <variable name>=<value>

Learn more about the export command

Jump back to commands list ↑

The ssh command in Linux

The ssh command in Linux and Unix-based operating systems establishes a secure shell connection to a
remote server. The command provides a secure encrypted connection between the local and remote servers,
allowing users to run commands and transfer files securely.

The basic syntax of the ssh command is:

root@ubuntu:~ ssh username@remote-server

This command establishes an ssh connection to the remote-server using the username account.

The ssh command supports a wide range of options and configurations, including:

 Configuring authentication methods (password, public key, etc.)


 Configuring encryption algorithms
 Configuring compression
 Configuring port forwarding
 Configuring X11 forwarding
 Configuring SSH keys

The ssh command in Linux

The ssh command in Linux and Unix-based operating systems establishes a secure shell connection to a
remote server. The command provides a secure encrypted connection between the local and remote servers,
allowing users to run commands and transfer files securely.

The basic syntax of the ssh command is:

root@ubuntu:~ ssh username@remote-server

This command establishes an ssh connection to the remote-server using the username account.

The ssh command supports a wide range of options and configurations, including:

 Configuring authentication methods (password, public key, etc.)


 Configuring encryption algorithms
 Configuring compression
 Configuring port forwarding
 Configuring X11 forwarding
 Configuring SSH keys

The service command in Linux

The service command in Linux is used to manage system services, which are long-running processes that
are started at boot time and run in the background. These services are responsible for providing various
system functionalities, such as networking, database management, and user authentication.

The service command is used to start, stop, restart, and check the status of these services. It is a front-end
to the systemctl command, which is used to manage the systemd service manager.

The basic syntax of the command is as below.

root@ubuntu:~ service ssh status


root@ubuntu:~ service ssh stop
root@ubuntu:~ service ssh start

As you can see in the image, the ssh server is running on our system.

Jump back to commands list ↑


The service command in Linux

The service command in Linux is used to manage system services, which are long-running processes that
are started at boot time and run in the background. These services are responsible for providing various
system functionalities, such as networking, database management, and user authentication.

The service command is used to start, stop, restart, and check the status of these services. It is a front-end
to the systemctl command, which is used to manage the systemd service manager.

The basic syntax of the command is as below.

root@ubuntu:~ service ssh status


root@ubuntu:~ service ssh stop
root@ubuntu:~ service ssh start

As you can see in the image, the ssh server is running on our system.

Jump back to commands list ↑

The ps, kill, and killall commands

The ps, kill, and killall commands are all used to manage processes in Linux.

The ps command is used to display information about the current running processes on the system. Here
are some examples of using the ps command:

Display a list of all running processes:


root@ubuntu:~ ps -ef

Display a list of all processes for a specific process ID (PID):

root@ubuntu:~ ps -p PID

Let’s see all of this in action:

root@ubuntu:~ ps
root@ubuntu:~ kill <process ID>
root@ubuntu:~ killall <process name>

For demonstration purposes, we will create a shell script with an infinite loop and will run it in the
background.

With the use of the & symbol, we can pass a process into the background. As you can see, a new bash
process with PID 14490 is created.

Now, to kill a process with the kill command, you can type kill followed by the PID(Process Id) of the
process.
But if you do not know the process ID and just want to kill the process with the name, you can make use of
the killall command.

You will notice that PID 14490 stayed active. That is because, both times, we killed the sleep process.

Learn more about the ps command and the kill command.

Jump back to commands list ↑

The ps, kill, and killall commands

The ps, kill, and killall commands are all used to manage processes in Linux.

The ps command is used to display information about the current running processes on the system. Here
are some examples of using the ps command:

Display a list of all running processes:

root@ubuntu:~ ps -ef
Display a list of all processes for a specific process ID (PID):

root@ubuntu:~ ps -p PID

Let’s see all of this in action:

root@ubuntu:~ ps
root@ubuntu:~ kill <process ID>
root@ubuntu:~ killall <process name>

For demonstration purposes, we will create a shell script with an infinite loop and will run it in the
background.

With the use of the & symbol, we can pass a process into the background. As you can see, a new bash
process with PID 14490 is created.

Now, to kill a process with the kill command, you can type kill followed by the PID(Process Id) of the
process.
But if you do not know the process ID and just want to kill the process with the name, you can make use of
the killall command.

You will notice that PID 14490 stayed active. That is because, both times, we killed the sleep process.

Learn more about the ps command and the kill command.

Jump back to commands list ↑

The ps, kill, and killall commands

The ps, kill, and killall commands are all used to manage processes in Linux.

The ps command is used to display information about the current running processes on the system. Here
are some examples of using the ps command:

Display a list of all running processes:

root@ubuntu:~ ps -ef
Display a list of all processes for a specific process ID (PID):

root@ubuntu:~ ps -p PID

Let’s see all of this in action:

root@ubuntu:~ ps
root@ubuntu:~ kill <process ID>
root@ubuntu:~ killall <process name>

For demonstration purposes, we will create a shell script with an infinite loop and will run it in the
background.

With the use of the & symbol, we can pass a process into the background. As you can see, a new bash
process with PID 14490 is created.

Now, to kill a process with the kill command, you can type kill followed by the PID(Process Id) of the
process.
But if you do not know the process ID and just want to kill the process with the name, you can make use of
the killall command.

You will notice that PID 14490 stayed active. That is because, both times, we killed the sleep process.

Learn more about the ps command and the kill command.

Jump back to commands list ↑

The ps, kill, and killall commands

The ps, kill, and killall commands are all used to manage processes in Linux.

The ps command is used to display information about the current running processes on the system. Here
are some examples of using the ps command:

Display a list of all running processes:

root@ubuntu:~ ps -ef
Display a list of all processes for a specific process ID (PID):

root@ubuntu:~ ps -p PID

Let’s see all of this in action:

root@ubuntu:~ ps
root@ubuntu:~ kill <process ID>
root@ubuntu:~ killall <process name>

For demonstration purposes, we will create a shell script with an infinite loop and will run it in the
background.

With the use of the & symbol, we can pass a process into the background. As you can see, a new bash
process with PID 14490 is created.

Now, to kill a process with the kill command, you can type kill followed by the PID(Process Id) of the
process.
But if you do not know the process ID and just want to kill the process with the name, you can make use of
the killall command.

You will notice that PID 14490 stayed active. That is because, both times, we killed the sleep process.

Learn more about the ps command and the kill command.

Jump back to commands list ↑

The df and mount commands

When working with Linux, the df and mount commands are very efficient utilities to mount filesystems
and get details of the file system.

The df command is used to display the amount of disk space used and available on the file systems, and
the mount command is used to mount a file system or device to a specific directory.

When we say mount, it means that we’ll connect the device to a folder so we can access the files from our
filesystem. The default syntax to mount a filesystem is below:
root@ubuntu:~ mount /dev/cdrom /mnt
root@ubuntu:~ df -h

In the above case, /dev/cdrom is the device that needs to be mounted. Usually, a mountable device is
found inside the /dev folder. mnt is the destination folder to which to mount the device. You can change it
to any folder you want, but we have used /mnt as it’s the system’s default folder for mounting devices.

To see the mounted devices and get more information about them, we use the df command. Just typing df
will give us the data in bytes, which is not readable. So, we’ll use the -h parameter to make the data
human-readable.

Jump back to commands list ↑

The df and mount commands

When working with Linux, the df and mount commands are very efficient utilities to mount filesystems
and get details of the file system.

The df command is used to display the amount of disk space used and available on the file systems, and
the mount command is used to mount a file system or device to a specific directory.

When we say mount, it means that we’ll connect the device to a folder so we can access the files from our
filesystem. The default syntax to mount a filesystem is below:

root@ubuntu:~ mount /dev/cdrom /mnt


root@ubuntu:~ df -h

In the above case, /dev/cdrom is the device that needs to be mounted. Usually, a mountable device is
found inside the /dev folder. mnt is the destination folder to which to mount the device. You can change it
to any folder you want, but we have used /mnt as it’s the system’s default folder for mounting devices.
To see the mounted devices and get more information about them, we use the df command. Just typing df
will give us the data in bytes, which is not readable. So, we’ll use the -h parameter to make the data
human-readable.

Jump back to commands list ↑

The chmod and chown commands

The chmod and chown commands are used to modify file permissions and ownership in Linux.

The chmod command is used to change the permissions of a file or directory, and the chown command is
used to change the ownership of a file or directory

The default syntax for both the commands is chmod <parameter> filename and chown <user:group>
filename

root@ubuntu:~ chmod +x loop.sh


root@ubuntu:~ chmod root:root loop.sh
In the above example, we’re adding executable permissions to the loop.sh file with the chmod command.
In addition, with the chown command, we’ve made it accessible only to the root user and users within the
root group.

As you will notice, the root root part is now changed to www-data which is the new user who has full file
ownership.

Learn more about the Linux file Permissions and using the chmod command.

Jump back to commands list ↑

The chmod and chown commands

The chmod and chown commands are used to modify file permissions and ownership in Linux.

The chmod command is used to change the permissions of a file or directory, and the chown command is
used to change the ownership of a file or directory

The default syntax for both the commands is chmod <parameter> filename and chown <user:group>
filename

root@ubuntu:~ chmod +x loop.sh


root@ubuntu:~ chmod root:root loop.sh

In the above example, we’re adding executable permissions to the loop.sh file with the chmod command.
In addition, with the chown command, we’ve made it accessible only to the root user and users within the
root group.
As you will notice, the root root part is now changed to www-data which is the new user who has full file
ownership.

Learn more about the Linux file Permissions and using the chmod command.

Jump back to commands list ↑

The ifconfig and traceroute commands

The ifconfig and traceroute commands manage network interfaces and trace the route of network
packets in Linux.

The ifconfig command will give you the list of all the network interfaces along with the IP addresses,
MAC addresses and other information about the interface.

root@ubuntu:~ ifconfig

There are multiple parameters that can be used, but we’ll work with the basic command here.

The traceroute command is used to trace the route of network packets and determine the path they take
to reach a specific destination.

When working with traceroute, you can simply specify the IP address, hostname, or domain name of the
endpoint.
root@ubuntu:~ traceroute <destination address>

Now, obviously, localhost is just one hop (the network interface itself). You can try this same command
with any other domain name or IP address to see all the routers your data packets pass through to reach the
destination.

Jump back to commands list ↑

The ifconfig and traceroute commands

The ifconfig and traceroute commands manage network interfaces and trace the route of network
packets in Linux.

The ifconfig command will give you the list of all the network interfaces along with the IP addresses,
MAC addresses and other information about the interface.

root@ubuntu:~ ifconfig

There are multiple parameters that can be used, but we’ll work with the basic command here.

The traceroute command is used to trace the route of network packets and determine the path they take
to reach a specific destination.

When working with traceroute, you can simply specify the IP address, hostname, or domain name of the
endpoint.

root@ubuntu:~ traceroute <destination address>


Now, obviously, localhost is just one hop (the network interface itself). You can try this same command
with any other domain name or IP address to see all the routers your data packets pass through to reach the
destination.

Jump back to commands list ↑

The ifconfig and traceroute commands

The ifconfig and traceroute commands manage network interfaces and trace the route of network
packets in Linux.

The ifconfig command will give you the list of all the network interfaces along with the IP addresses,
MAC addresses and other information about the interface.

root@ubuntu:~ ifconfig

There are multiple parameters that can be used, but we’ll work with the basic command here.

The traceroute command is used to trace the route of network packets and determine the path they take
to reach a specific destination.

When working with traceroute, you can simply specify the IP address, hostname, or domain name of the
endpoint.

root@ubuntu:~ traceroute <destination address>


Now, obviously, localhost is just one hop (the network interface itself). You can try this same command
with any other domain name or IP address to see all the routers your data packets pass through to reach the
destination.

Jump back to commands list ↑

The wget command in Linux

If you want to download a file from within the terminal, the wget command is one of the handiest
command-line utilities available. It is one of the important Linux commands you should know when
working with source files.

When you specify the link for download, it has to directly be a link to the file. If the file cannot be accessed
by the wget command, it will simply download the webpage in HTML format instead of the actual file that
you wanted.

Let’s try an example. The basic syntax of the wget command is :

root@ubuntu:~ wget <link to file>

Or,

root@ubuntu:~ wget -c <link to file>

The -c argument allows us to resume an interrupted download.

Jump back to commands list ↑

The wget command in Linux

If you want to download a file from within the terminal, the wget command is one of the handiest
command-line utilities available. It is one of the important Linux commands you should know when
working with source files.

When you specify the link for download, it has to directly be a link to the file. If the file cannot be accessed
by the wget command, it will simply download the webpage in HTML format instead of the actual file that
you wanted.
Let’s try an example. The basic syntax of the wget command is :

root@ubuntu:~ wget <link to file>

Or,

root@ubuntu:~ wget -c <link to file>

The -c argument allows us to resume an interrupted download.

Jump back to commands list ↑

The wget command in Linux

If you want to download a file from within the terminal, the wget command is one of the handiest
command-line utilities available. It is one of the important Linux commands you should know when
working with source files.

When you specify the link for download, it has to directly be a link to the file. If the file cannot be accessed
by the wget command, it will simply download the webpage in HTML format instead of the actual file that
you wanted.

Let’s try an example. The basic syntax of the wget command is :

root@ubuntu:~ wget <link to file>

Or,

root@ubuntu:~ wget -c <link to file>

The -c argument allows us to resume an interrupted download.

Jump back to commands list ↑

The ufw and iptables commands

The ufw and iptables commands are used to manage firewalls in Linux.

UFW and IPTables are firewall interfaces for the Linux Kernel’s netfilter firewall. IPTables directly passes
firewall rules to Netfilter while UFW configures the rules in IPTables, which then sends those rules to
Netfilter.

Why do we need UFW when we have IPTables? Because IPTables is pretty difficult for a newbie. UFW
makes things extremely easy. See the below example where we are trying to allow port 80 for our
webserver.
root@ubuntu:~# iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
root@ubuntu:~# ufw allow 80

I’m sure you now know why UFW was created! Look at how easy the syntax becomes. Both these
firewalls are very comprehensive and can allow you to create any kind of configuration required for your
network. Learn at least the basics of UFW or IPTables firewall, as these are the Linux commands you must
know.

Learn more about managing firewall with ufw and managing firewall with iptables.

Jump back to commands list ↑

The ufw and iptables commands

The ufw and iptables commands are used to manage firewalls in Linux.

UFW and IPTables are firewall interfaces for the Linux Kernel’s netfilter firewall. IPTables directly passes
firewall rules to Netfilter while UFW configures the rules in IPTables, which then sends those rules to
Netfilter.

Why do we need UFW when we have IPTables? Because IPTables is pretty difficult for a newbie. UFW
makes things extremely easy. See the below example where we are trying to allow port 80 for our
webserver.

root@ubuntu:~# iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT


root@ubuntu:~# ufw allow 80

I’m sure you now know why UFW was created! Look at how easy the syntax becomes. Both these
firewalls are very comprehensive and can allow you to create any kind of configuration required for your
network. Learn at least the basics of UFW or IPTables firewall, as these are the Linux commands you must
know.

Learn more about managing firewall with ufw and managing firewall with iptables.

Jump back to commands list ↑

Package Managers in Linux

Different Linux distributions use different package managers. Since we’re working on a Ubuntu server, we
have the apt package manager. But for someone working on a Fedora, Red Hat, Arch, or Centos machine,
the package manager will be different.

Below are the commands on how to use these package managers on different Linux distributions.

 Debian and Debian-based distros - apt install <package name>


 Arch and Arch-based distros - pacman -S <package name>
 Red Hat and Red Hat-based distros - yum install <package name>
 Fedora and CentOS - yum install <package>

Getting yourself well versed with the package manager of your distribution will make things much easier
for you in the long run. So even if you have a GUI based package management tool installed, try an make
use of the CLI based tool before you move on to the GUI utility. Add these to your list of Linux commands
you must know.

Jump back to commands list ↑

The sudo command in Linux

“With great power, comes great responsibility”_

This is the quote displayed when a sudo-enabled user(sudoer) first uses the sudo command to escalate
privileges. This command is equivalent to logging in as root (based on what permissions you have as a
sudoer).

non-root-user@ubuntu:~# sudo <command you want to run>


Password:

Just add the command sudo before any command that you need to run with escalated privileges, and that’s
it. It’s very simple to use, but can also be an added security risk if a malicious user gains access to a sudoer.

Learn more about how to create a new sudo user and how to edit sudoers file.

Jump back to commands list ↑

The sudo command in Linux

“With great power, comes great responsibility”_

This is the quote displayed when a sudo-enabled user(sudoer) first uses the sudo command to escalate
privileges. This command is equivalent to logging in as root (based on what permissions you have as a
sudoer).

non-root-user@ubuntu:~# sudo <command you want to run>


Password:

Just add the command sudo before any command that you need to run with escalated privileges, and that’s
it. It’s very simple to use, but can also be an added security risk if a malicious user gains access to a sudoer.

Learn more about how to create a new sudo user and how to edit sudoers file.

Jump back to commands list ↑


The cal command in Linux

Have you ever wanted to view the calendar in the terminal? There apparently are people who want it to
happen, and well, here it is.

The cal command displays a well-presented calendar on the terminal. Just enter the command cal on your
terminal prompt.

root@ubuntu:~# cal
root@ubuntu:~# cal March 2024

Although we don’t need it often, it’s a great addition! It’s an amazing option for terminal fans.

Jump back to commands list ↑

The cal command in Linux

Have you ever wanted to view the calendar in the terminal? There apparently are people who want it to
happen, and well, here it is.
The cal command displays a well-presented calendar on the terminal. Just enter the command cal on your
terminal prompt.

root@ubuntu:~# cal
root@ubuntu:~# cal March 2024

Although we don’t need it often, it’s a great addition! It’s an amazing option for terminal fans.

Jump back to commands list ↑

The alias command

Do you have some commands that you run very frequently while using the terminal? It could be rm -r or
ls -l, or it could be something longer like tar -xvzf.

This is one of the productivity-boosting Linux commands you must know.

If you know a command that you run very often, it’s time to create an alias.

What’s an alias? In simple terms, it’s another name for a command that you’ve defined.
root@ubuntu:~# alias lsl="ls -l"
OR
root@ubuntu:~# alias rmd="rm -r"

Now, every time you enter lsl or rmd in the terminal, you’ll receive the output that you’d have received if
you had used the full commands.

The examples here are for really small commands that you can still type by hand every time. But in some
situations where a command has too many arguments that you need to type, it’s best to create a shorthand
version of the same.

Jump back to commands list ↑

The alias command

Do you have some commands that you run very frequently while using the terminal? It could be rm -r or
ls -l, or it could be something longer like tar -xvzf.

This is one of the productivity-boosting Linux commands you must know.

If you know a command that you run very often, it’s time to create an alias.

What’s an alias? In simple terms, it’s another name for a command that you’ve defined.

root@ubuntu:~# alias lsl="ls -l"


OR
root@ubuntu:~# alias rmd="rm -r"

Now, every time you enter lsl or rmd in the terminal, you’ll receive the output that you’d have received if
you had used the full commands.

The examples here are for really small commands that you can still type by hand every time. But in some
situations where a command has too many arguments that you need to type, it’s best to create a shorthand
version of the same.

Jump back to commands list ↑

The dd command in Linux

This command was created to convert and copy files from multiple file system formats. In the current day,
the command is simply used to create bootable USB for Linux but there still are some things important you
can do with the command.

The dd command in Linux is a versatile command used for low-level copying and conversion of data. It
stands for “data-description” or “data definition,” and it can be used to copy and convert data between
different file formats and storage devices.
For example, if we wanted to back up the entire hard drive as is to another drive, we would use the dd
command.

root@ubuntu:~# dd if=/dev/sdb of=/dev/sda

The if and of arguments stand for input file and output file.

It’s a powerful and flexible tool, but it can also be dangerous if not used carefully. Always double-check
your syntax and make sure you know what the command will do before executing it.

Jump back to commands list ↑

The dd command in Linux

This command was created to convert and copy files from multiple file system formats. In the current day,
the command is simply used to create bootable USB for Linux but there still are some things important you
can do with the command.

The dd command in Linux is a versatile command used for low-level copying and conversion of data. It
stands for “data-description” or “data definition,” and it can be used to copy and convert data between
different file formats and storage devices.

For example, if we wanted to back up the entire hard drive as is to another drive, we would use the dd
command.

root@ubuntu:~# dd if=/dev/sdb of=/dev/sda

The if and of arguments stand for input file and output file.

It’s a powerful and flexible tool, but it can also be dangerous if not used carefully. Always double-check
your syntax and make sure you know what the command will do before executing it.

Jump back to commands list ↑

The whereis and whatis commands

The whereis and whatis commands are used in Linux to search for information about programs and files.

The whereis command locates the binary, source, and manual pages for a specific command or program,
and the whatis command displays a short description of a command or program.

root@ubuntu:~# whereis sudo


sudo: /usr/bin/sudo /usr/lib/sudo /usr/share/man/man8/sudo.8.gz

The whatis command gives us an explanation of what a command actually is.


root@ubuntu:~# whatis sudo
sudo (8) - execute a command as another user

Jump back to commands list ↑

The whereis and whatis commands

The whereis and whatis commands are used in Linux to search for information about programs and files.

The whereis command locates the binary, source, and manual pages for a specific command or program,
and the whatis command displays a short description of a command or program.

root@ubuntu:~# whereis sudo


sudo: /usr/bin/sudo /usr/lib/sudo /usr/share/man/man8/sudo.8.gz

The whatis command gives us an explanation of what a command actually is.

root@ubuntu:~# whatis sudo


sudo (8) - execute a command as another user

Jump back to commands list ↑

The whereis and whatis commands

The whereis and whatis commands are used in Linux to search for information about programs and files.

The whereis command locates the binary, source, and manual pages for a specific command or program,
and the whatis command displays a short description of a command or program.

root@ubuntu:~# whereis sudo


sudo: /usr/bin/sudo /usr/lib/sudo /usr/share/man/man8/sudo.8.gz

The whatis command gives us an explanation of what a command actually is.

root@ubuntu:~# whatis sudo


sudo (8) - execute a command as another user

Jump back to commands list ↑

The top command in Linux

A few sections earlier, we talked about the ps command. You observed that the ps command will output
the active processes and end itself.

The top command is like a CLI version of the task manager in Windows.
The top command in Linux is a system monitoring tool that displays real-time information about system
processes and resource usage. It provides a dynamic, real-time view of system activity, including CPU
usage, memory usage, and process information.

Note: Here are some examples of using the top command:

 Sort processes by memory usage:

root@ubuntu:~# top -o MEM

This will sort the process list by memory usage, with the most memory-intensive processes at the top.

 Display detailed information about a specific process:

root@ubuntu:~# top -p PID

Replace PID with the ID of the process you want to inspect.

 Display a summary of system resource usage:

root@ubuntu:~# top -n 1

This will display a single summary screen of system resource usage.

It’s a powerful and flexible tool for monitoring system activity and troubleshooting performance issues.
Jump back to commands list ↑

This will sort the process list by memory usage, with the most memory-intensive processes at the top.

 Display detailed information about a specific process:

root@ubuntu:~# top -p PID

Replace PID with the ID of the process you want to inspect.

 Display a summary of system resource usage:

root@ubuntu:~# top -n 1

The top command in Linux

A few sections earlier, we talked about the ps command. You observed that the ps command will output
the active processes and end itself.

The top command is like a CLI version of the task manager in Windows.

The top command in Linux is a system monitoring tool that displays real-time information about system
processes and resource usage. It provides a dynamic, real-time view of system activity, including CPU
usage, memory usage, and process information.

Note: Here are some examples of using the top command:


 Sort processes by memory usage:

root@ubuntu:~# top -o MEM

This will sort the process list by memory usage, with the most memory-intensive processes at the top.

 Display detailed information about a specific process:

root@ubuntu:~# top -p PID

Replace PID with the ID of the process you want to inspect.

 Display a summary of system resource usage:

root@ubuntu:~# top -n 1

This will display a single summary screen of system resource usage.

It’s a powerful and flexible tool for monitoring system activity and troubleshooting performance issues.

Jump back to commands list ↑

The useradd and usermod commands

The useradd and usermod commands are used in Linux to manage user accounts.

The useradd or adduser commands are the exact same commands where adduser is just a symbolic link
to the useradd command. This command allows us to create a new user in Linux.

root@ubuntu:~# useradd JournalDev -d /home/JD

The above command will create a new user named JournalDev with the home directory as /home/JD.

The usermod command, on the other hand, is used to modify existing users. You can modify any value of
the user including the groups, the permissions, etc.

For example, if you want to add more groups to the user, you can type in:

root@ubuntu:~# usermod JournalDev -a -G sudo, audio, mysql

Jump back to commands list ↑

The useradd and usermod commands

The useradd and usermod commands are used in Linux to manage user accounts.
The useradd or adduser commands are the exact same commands where adduser is just a symbolic link
to the useradd command. This command allows us to create a new user in Linux.

root@ubuntu:~# useradd JournalDev -d /home/JD

The above command will create a new user named JournalDev with the home directory as /home/JD.

The usermod command, on the other hand, is used to modify existing users. You can modify any value of
the user including the groups, the permissions, etc.

For example, if you want to add more groups to the user, you can type in:

root@ubuntu:~# usermod JournalDev -a -G sudo, audio, mysql

Jump back to commands list ↑

The useradd and usermod commands

The useradd and usermod commands are used in Linux to manage user accounts.

The useradd or adduser commands are the exact same commands where adduser is just a symbolic link
to the useradd command. This command allows us to create a new user in Linux.

root@ubuntu:~# useradd JournalDev -d /home/JD

The above command will create a new user named JournalDev with the home directory as /home/JD.

The usermod command, on the other hand, is used to modify existing users. You can modify any value of
the user including the groups, the permissions, etc.

For example, if you want to add more groups to the user, you can type in:

root@ubuntu:~# usermod JournalDev -a -G sudo, audio, mysql

Jump back to commands list ↑

The passwd command in Linux

Now that you know how to create new users, let’s also set the password for them. The passwd command
lets you set the password for your own account, or if you have the permissions, set the password for other
accounts.

Here are some examples of using the passwd command:

 Change the password for the current user:


 root@ubuntu:~# passwd
This will prompt you to enter a new password for the current user.

 Change the password for a specific user:


 root@ubuntu:~# passwd username

Replace username with the name of the user whose password you want to change.

 Force a user to change their password at the next login:


 root@ubuntu:~# passwd -f username

 Set an expiration date for a user’s password:


 root@ubuntu:~# passwd -e -n days -w warndays username

Replace days with the number of days before the password expires and warm days with the number of
days before the password expires that the user will be warned.

These are just a few examples of using the passwd command in Linux. By understanding how to use this
command effectively, you can manage user accounts and ensure that your system is secure.

Jump back to commands list ↑

The passwd command in Linux

Now that you know how to create new users, let’s also set the password for them. The passwd command
lets you set the password for your own account, or if you have the permissions, set the password for other
accounts.

Here are some examples of using the passwd command:

 Change the password for the current user:


 root@ubuntu:~# passwd

This will prompt you to enter a new password for the current user.

 Change the password for a specific user:


 root@ubuntu:~# passwd username

Replace username with the name of the user whose password you want to change.
 Force a user to change their password at the next login:
 root@ubuntu:~# passwd -f username

 Set an expiration date for a user’s password:


 root@ubuntu:~# passwd -e -n days -w warndays username

Replace days with the number of days before the password expires and warm days with the number of
days before the password expires that the user will be warned.

These are just a few examples of using the passwd command in Linux. By understanding how to use this
command effectively, you can manage user accounts and ensure that your system is secure.

Jump back to commands list ↑

The passwd command in Linux

Now that you know how to create new users, let’s also set the password for them. The passwd command
lets you set the password for your own account, or if you have the permissions, set the password for other
accounts.

Here are some examples of using the passwd command:

 Change the password for the current user:


 root@ubuntu:~# passwd

This will prompt you to enter a new password for the current user.

 Change the password for a specific user:


 root@ubuntu:~# passwd username

Replace username with the name of the user whose password you want to change.

 Force a user to change their password at the next login:


 root@ubuntu:~# passwd -f username

 Set an expiration date for a user’s password:


 root@ubuntu:~# passwd -e -n days -w warndays username
Replace days with the number of days before the password expires and warm days with the number of
days before the password expires that the user will be warned.

These are just a few examples of using the passwd command in Linux. By understanding how to use this
command effectively, you can manage user accounts and ensure that your system is secure.

Jump back to commands list ↑

 Set an expiration date for a user’s password:

root@ubuntu:~# passwd -e -n days -w warndays username

The passwd command in Linux

Now that you know how to create new users, let’s also set the password for them. The passwd command
lets you set the password for your own account, or if you have the permissions, set the password for other
accounts.

Here are some examples of using the passwd command:

 Change the password for the current user:


 root@ubuntu:~# passwd

This will prompt you to enter a new password for the current user.

 Change the password for a specific user:


 root@ubuntu:~# passwd username

Replace username with the name of the user whose password you want to change.

 Force a user to change their password at the next login:


 root@ubuntu:~# passwd -f username

 Set an expiration date for a user’s password:


 root@ubuntu:~# passwd -e -n days -w warndays username

Replace days with the number of days before the password expires and warm days with the number of
days before the password expires that the user will be warned.
These are just a few examples of using the passwd command in Linux. By understanding how to use this
command effectively, you can manage user accounts and ensure that your system is secure.

Jump back to commands list ↑

Common Errors and Debugging

When working with Linux commands, you may encounter various errors and issues. Here are some
common problems and how to resolve them:

1. Fixing “command not found” errors

If you receive a command not found error, it means that the command you are trying to run is not
recognized by the system. This can happen for several reasons:

1. The command is not installed on your system. You can install it using your package manager (e.g.,
apt, yum, dnf).

If you see:

bash: xyz: command not found

Use:

which xyz

If the command isn’t installed, try installing:

apt-get install <package-name>

2. The command is not in your system’s PATH. You can add the directory containing the command to
your PATH.
3. export PATH=$PATH:/path/to/command

4. You made a typo. Double-check the command for any spelling errors.
2. Resolving permission issues with sudo

If you encounter permission issues, you can use sudo to run the command with superuser privileges. For
example:

sudo command_name

3. Handling File Conflicts

File conflicts can occur when multiple users or processes attempt to modify the same file simultaneously.
Here are some ways to handle file conflicts:

1. Use Version Control Systems (VCS): Tools like Git can help manage file conflicts by allowing
users to merge changes and resolve conflicts manually.
2. git merge <branch_name>

If there are conflicts, Git will prompt you to resolve them. Open the conflicting files, make the
necessary changes, and then commit the resolved files.

git add <resolved_file>


git commit -m "Resolved merge conflict"

3. Locking Mechanisms: Implement file locking to prevent multiple processes from writing to the
same file simultaneously. Use flock in Linux to create a lock on a file.
4. flock -x <file> -c "<command>"

5. Atomic Operations: Use atomic operations to ensure that file writes are completed in a single step,
reducing the risk of conflicts.
6. mv temp_file target_file

Or, Use mv with -f (force) or cp with -i (interactive):

mv -f file1 file2
cp -i file1 file2

4. Debugging Performance Bottlenecks

Performance bottlenecks can significantly impact the efficiency of your system. Here are some steps to
debug and resolve them:

1. Identify the Bottleneck: Use tools like top, htop, vmstat, and iostat to monitor system
performance and identify the resource causing the bottleneck (CPU, memory, disk I/O, etc.).
2. top

3. Analyze Logs: Check system and application logs for any errors or warnings that might indicate
performance issues.
4. tail -f /var/log/syslog
5. Optimize Code: Review and optimize your code to improve performance. Look for inefficient
algorithms, unnecessary computations, and memory leaks.
6. Profile Your Application: Use profiling tools like gprof, perf, or valgrind to analyze your
application’s performance and identify slow functions or memory issues.
7. gprof <executable> gmon.out

8. Scale Resources: If the bottleneck is due to resource limitations, consider scaling up your hardware
or using load balancing to distribute the load across multiple servers.

Use:

which xyz

If the command isn’t installed, try installing:

apt-get install <package-name>

 The command is not in your system’s PATH. You can add the directory containing the command to
your PATH.

export PATH=$PATH:/path/to/command

Common Errors and Debugging

When working with Linux commands, you may encounter various errors and issues. Here are some
common problems and how to resolve them:

1. Fixing “command not found” errors

If you receive a command not found error, it means that the command you are trying to run is not
recognized by the system. This can happen for several reasons:

1. The command is not installed on your system. You can install it using your package manager (e.g.,
apt, yum, dnf).

If you see:

bash: xyz: command not found

Use:

which xyz

If the command isn’t installed, try installing:

apt-get install <package-name>


2. The command is not in your system’s PATH. You can add the directory containing the command to
your PATH.
3. export PATH=$PATH:/path/to/command

4. You made a typo. Double-check the command for any spelling errors.

2. Resolving permission issues with sudo

If you encounter permission issues, you can use sudo to run the command with superuser privileges. For
example:

sudo command_name

3. Handling File Conflicts

File conflicts can occur when multiple users or processes attempt to modify the same file simultaneously.
Here are some ways to handle file conflicts:

1. Use Version Control Systems (VCS): Tools like Git can help manage file conflicts by allowing
users to merge changes and resolve conflicts manually.
2. git merge <branch_name>

If there are conflicts, Git will prompt you to resolve them. Open the conflicting files, make the
necessary changes, and then commit the resolved files.

git add <resolved_file>


git commit -m "Resolved merge conflict"

3. Locking Mechanisms: Implement file locking to prevent multiple processes from writing to the
same file simultaneously. Use flock in Linux to create a lock on a file.
4. flock -x <file> -c "<command>"

5. Atomic Operations: Use atomic operations to ensure that file writes are completed in a single step,
reducing the risk of conflicts.
6. mv temp_file target_file

Or, Use mv with -f (force) or cp with -i (interactive):

mv -f file1 file2
cp -i file1 file2

4. Debugging Performance Bottlenecks

Performance bottlenecks can significantly impact the efficiency of your system. Here are some steps to
debug and resolve them:

1. Identify the Bottleneck: Use tools like top, htop, vmstat, and iostat to monitor system
performance and identify the resource causing the bottleneck (CPU, memory, disk I/O, etc.).
2. top

3. Analyze Logs: Check system and application logs for any errors or warnings that might indicate
performance issues.
4. tail -f /var/log/syslog

5. Optimize Code: Review and optimize your code to improve performance. Look for inefficient
algorithms, unnecessary computations, and memory leaks.
6. Profile Your Application: Use profiling tools like gprof, perf, or valgrind to analyze your
application’s performance and identify slow functions or memory issues.
7. gprof <executable> gmon.out

8. Scale Resources: If the bottleneck is due to resource limitations, consider scaling up your hardware
or using load balancing to distribute the load across multiple servers.

Common Errors and Debugging

When working with Linux commands, you may encounter various errors and issues. Here are some
common problems and how to resolve them:

1. Fixing “command not found” errors

If you receive a command not found error, it means that the command you are trying to run is not
recognized by the system. This can happen for several reasons:

1. The command is not installed on your system. You can install it using your package manager (e.g.,
apt, yum, dnf).

If you see:

bash: xyz: command not found

Use:

which xyz

If the command isn’t installed, try installing:

apt-get install <package-name>

2. The command is not in your system’s PATH. You can add the directory containing the command to
your PATH.
3. export PATH=$PATH:/path/to/command

4. You made a typo. Double-check the command for any spelling errors.
2. Resolving permission issues with sudo

If you encounter permission issues, you can use sudo to run the command with superuser privileges. For
example:

sudo command_name

3. Handling File Conflicts

File conflicts can occur when multiple users or processes attempt to modify the same file simultaneously.
Here are some ways to handle file conflicts:

1. Use Version Control Systems (VCS): Tools like Git can help manage file conflicts by allowing
users to merge changes and resolve conflicts manually.
2. git merge <branch_name>

If there are conflicts, Git will prompt you to resolve them. Open the conflicting files, make the
necessary changes, and then commit the resolved files.

git add <resolved_file>


git commit -m "Resolved merge conflict"

3. Locking Mechanisms: Implement file locking to prevent multiple processes from writing to the
same file simultaneously. Use flock in Linux to create a lock on a file.
4. flock -x <file> -c "<command>"

5. Atomic Operations: Use atomic operations to ensure that file writes are completed in a single step,
reducing the risk of conflicts.
6. mv temp_file target_file

Or, Use mv with -f (force) or cp with -i (interactive):

mv -f file1 file2
cp -i file1 file2

4. Debugging Performance Bottlenecks

Performance bottlenecks can significantly impact the efficiency of your system. Here are some steps to
debug and resolve them:

1. Identify the Bottleneck: Use tools like top, htop, vmstat, and iostat to monitor system
performance and identify the resource causing the bottleneck (CPU, memory, disk I/O, etc.).
2. top

3. Analyze Logs: Check system and application logs for any errors or warnings that might indicate
performance issues.
4. tail -f /var/log/syslog
5. Optimize Code: Review and optimize your code to improve performance. Look for inefficient
algorithms, unnecessary computations, and memory leaks.
6. Profile Your Application: Use profiling tools like gprof, perf, or valgrind to analyze your
application’s performance and identify slow functions or memory issues.
7. gprof <executable> gmon.out

8. Scale Resources: If the bottleneck is due to resource limitations, consider scaling up your hardware
or using load balancing to distribute the load across multiple servers.

If there are conflicts, Git will prompt you to resolve them. Open the conflicting files, make the necessary
changes, and then commit the resolved files.

git add <resolved_file>


git commit -m "Resolved merge conflict"

 Locking Mechanisms: Implement file locking to prevent multiple processes from writing to the same
file simultaneously. Use flock in Linux to create a lock on a file.

flock -x <file> -c "<command>"

Atomic Operations: Use atomic operations to ensure that file writes are completed in a single step,
reducing the risk of conflicts.

mv temp_file target_file

Or, Use mv with -f (force) or cp with -i (interactive):

mv -f file1 file2
cp -i file1 file2

Common Errors and Debugging

When working with Linux commands, you may encounter various errors and issues. Here are some
common problems and how to resolve them:

1. Fixing “command not found” errors

If you receive a command not found error, it means that the command you are trying to run is not
recognized by the system. This can happen for several reasons:

1. The command is not installed on your system. You can install it using your package manager (e.g.,
apt, yum, dnf).

If you see:

bash: xyz: command not found


Use:

which xyz

If the command isn’t installed, try installing:

apt-get install <package-name>

2. The command is not in your system’s PATH. You can add the directory containing the command to
your PATH.
3. export PATH=$PATH:/path/to/command

4. You made a typo. Double-check the command for any spelling errors.

2. Resolving permission issues with sudo

If you encounter permission issues, you can use sudo to run the command with superuser privileges. For
example:

sudo command_name

3. Handling File Conflicts

File conflicts can occur when multiple users or processes attempt to modify the same file simultaneously.
Here are some ways to handle file conflicts:

1. Use Version Control Systems (VCS): Tools like Git can help manage file conflicts by allowing
users to merge changes and resolve conflicts manually.
2. git merge <branch_name>

If there are conflicts, Git will prompt you to resolve them. Open the conflicting files, make the
necessary changes, and then commit the resolved files.

git add <resolved_file>


git commit -m "Resolved merge conflict"

3. Locking Mechanisms: Implement file locking to prevent multiple processes from writing to the
same file simultaneously. Use flock in Linux to create a lock on a file.
4. flock -x <file> -c "<command>"

5. Atomic Operations: Use atomic operations to ensure that file writes are completed in a single step,
reducing the risk of conflicts.
6. mv temp_file target_file

Or, Use mv with -f (force) or cp with -i (interactive):

mv -f file1 file2
cp -i file1 file2
4. Debugging Performance Bottlenecks

Performance bottlenecks can significantly impact the efficiency of your system. Here are some steps to
debug and resolve them:

1. Identify the Bottleneck: Use tools like top, htop, vmstat, and iostat to monitor system
performance and identify the resource causing the bottleneck (CPU, memory, disk I/O, etc.).
2. top

3. Analyze Logs: Check system and application logs for any errors or warnings that might indicate
performance issues.
4. tail -f /var/log/syslog

5. Optimize Code: Review and optimize your code to improve performance. Look for inefficient
algorithms, unnecessary computations, and memory leaks.
6. Profile Your Application: Use profiling tools like gprof, perf, or valgrind to analyze your
application’s performance and identify slow functions or memory issues.
7. gprof <executable> gmon.out

8. Scale Resources: If the bottleneck is due to resource limitations, consider scaling up your hardware
or using load balancing to distribute the load across multiple servers.

 Analyze Logs: Check system and application logs for any errors or warnings that might indicate
performance issues.

tail -f /var/log/syslog

 Optimize Code: Review and optimize your code to improve performance. Look for inefficient
algorithms, unnecessary computations, and memory leaks.

 Profile Your Application: Use profiling tools like gprof, perf, or valgrind to analyze your
application’s performance and identify slow functions or memory issues.

gprof <executable> gmon.out

Common Errors and Debugging

When working with Linux commands, you may encounter various errors and issues. Here are some
common problems and how to resolve them:

1. Fixing “command not found” errors

If you receive a command not found error, it means that the command you are trying to run is not
recognized by the system. This can happen for several reasons:

1. The command is not installed on your system. You can install it using your package manager (e.g.,
apt, yum, dnf).
If you see:

bash: xyz: command not found

Use:

which xyz

If the command isn’t installed, try installing:

apt-get install <package-name>

2. The command is not in your system’s PATH. You can add the directory containing the command to
your PATH.
3. export PATH=$PATH:/path/to/command

4. You made a typo. Double-check the command for any spelling errors.

2. Resolving permission issues with sudo

If you encounter permission issues, you can use sudo to run the command with superuser privileges. For
example:

sudo command_name

3. Handling File Conflicts

File conflicts can occur when multiple users or processes attempt to modify the same file simultaneously.
Here are some ways to handle file conflicts:

1. Use Version Control Systems (VCS): Tools like Git can help manage file conflicts by allowing
users to merge changes and resolve conflicts manually.
2. git merge <branch_name>

If there are conflicts, Git will prompt you to resolve them. Open the conflicting files, make the
necessary changes, and then commit the resolved files.

git add <resolved_file>


git commit -m "Resolved merge conflict"

3. Locking Mechanisms: Implement file locking to prevent multiple processes from writing to the
same file simultaneously. Use flock in Linux to create a lock on a file.
4. flock -x <file> -c "<command>"

5. Atomic Operations: Use atomic operations to ensure that file writes are completed in a single step,
reducing the risk of conflicts.
6. mv temp_file target_file
Or, Use mv with -f (force) or cp with -i (interactive):

mv -f file1 file2
cp -i file1 file2

4. Debugging Performance Bottlenecks

Performance bottlenecks can significantly impact the efficiency of your system. Here are some steps to
debug and resolve them:

1. Identify the Bottleneck: Use tools like top, htop, vmstat, and iostat to monitor system
performance and identify the resource causing the bottleneck (CPU, memory, disk I/O, etc.).
2. top

3. Analyze Logs: Check system and application logs for any errors or warnings that might indicate
performance issues.
4. tail -f /var/log/syslog

5. Optimize Code: Review and optimize your code to improve performance. Look for inefficient
algorithms, unnecessary computations, and memory leaks.
6. Profile Your Application: Use profiling tools like gprof, perf, or valgrind to analyze your
application’s performance and identify slow functions or memory issues.
7. gprof <executable> gmon.out

8. Scale Resources: If the bottleneck is due to resource limitations, consider scaling up your hardware
or using load balancing to distribute the load across multiple servers.

FAQs
1. What are the most used Linux commands?

The most used Linux commands include cd, ls, mkdir, rm, cp, mv, echo, cat, grep, find, man, sudo, apt-
get, ssh, ping, df, du, free, top, ps, kill, killall, service, systemctl, reboot, shutdown, whoami,
uname, uptime, history, and clear.

2. How do I list all available commands in Linux?

You can list all available commands in Linux by using the compgen -c command. This will display a list
of all commands that are available on your system.

3. How do I find a file in Linux?

You can find a file in Linux using the find command. The basic syntax is find <path> -name
"<filename>", where <path> is the directory where you want to start searching, and <filename> is the
name of the file you’re looking for. For example, find /home/user -name "example.txt".
4. How do I kill a process in Linux?

You can kill a process in Linux using the kill command. First, you need to find the process ID (PID) of
the process you want to kill using the ps or top command. Then, use the kill command followed by the
PID. For example, kill 1234, where 1234 is the PID of the process.

5. What is the difference between cp and mv?

The cp command is used to copy files or directories, while the mv command is used to move or rename
files or directories. cp creates a duplicate of the original file, leaving the original intact, whereas mv moves
the file to a new location, removing it from the original location.

6. How do I check my Linux system’s memory usage?

You can check your Linux system’s memory usage using the free command. This command displays the
total amount of free and used physical and swap memory in the system. For example, free -h will display
the memory usage in a human-readable format.

Linux is a powerful and versatile operating system that powers everything from servers to smartphones. If
you’re a student new to Linux, understanding basic commands is the first step toward becoming proficient
in using this OS. In this blog, we’ll explore 50 essential Linux commands with simple explanations and
examples to help you get started.

1. pwd

Print Working Directory: Displays the current directory.

$ pwd

/home/student

2. ls

List Directory Contents: Shows files and folders in a directory.

$ ls

Documents Downloads Pictures


3. cd

Change Directory: Navigate between directories.

$ cd Downloads

4. mkdir

Make Directory: Creates a new folder.

$ mkdir projects

5. rmdir

Remove Directory: Deletes an empty folder.

$ rmdir projects

6. touch

Create File: Creates an empty file.

$ touch file.txt

7. rm

Remove File/Folder: Deletes files or directories.

$ rm file.txt
$ rm -r folder_name

8. cp

Copy Files/Directories: Copies files or directories.

$ cp file1.txt file2.txt

$ cp -r dir1 dir2

9. mv

Move/Rename: Moves or renames files and folders.

$ mv file.txt new_name.txt

$ mv file.txt /home/student/Documents

10. cat

Concatenate and View Files: Displays file content.

$ cat file.txt Hello, Linux!

11. nano

Edit Files: Opens a text file in the nano editor.

$ nano file.txt
12. vi

Edit Files: Opens a text file in the vi editor.

$ vi file.txt

13. echo

Display Text: Prints text or writes to a file.

$ echo "Hello, World!"

$ echo "This is a test" &gt; test.txt

14. clear

Clear Terminal: Clears the terminal screen.

$ clear

15. history

Command History: Shows a list of recently executed commands.

$ history

16. find

Search for Files: Locates files in the system.


$ find /home -name file.txt

17. grep

Search in Files: Searches for patterns in files.

$ grep "Linux" file.txt

18. chmod

Change Permissions: Modifies file permissions.

$ chmod 755 file.txt

19. chown

Change Ownership: Changes file ownership.

$ chown user:group file.txt

20. man

Manual Pages: Displays command documentation.

$ man ls

21. uname

System Information: Displays system details.

$ uname -a
22. df

Disk Usage: Shows available and used disk space.

$ df -h

23. du

Directory Usage: Displays the size of a directory.

$ du -sh folder_name

24. top

Process Monitoring: Displays running processes.

$ top

25. ps

Process Status: Lists active processes.

$ ps

26. kill

Terminate Process: Stops a running process.

$ kill 1234
27. ping

Network Test: Checks connectivity to a host.

$ ping google.com

28. curl

HTTP Requests: Fetches data from URLs.

$ curl https://example.com

29. wget

Download Files: Downloads files from the internet.

$ wget https://example.com/file.zip

30. zip

Compress Files: Creates a ZIP archive.

$ zip archive.zip file1.txt file2.txt

31. unzip

Extract Files: Extracts a ZIP archive.

$ unzip archive.zip
32. tar

Archive Files: Archives and extracts files.

$ tar -cvf archive.tar folder

$ tar -xvf archive.tar

33. df

Check Disk Space: Displays disk usage information.

$ df -h

34. free

Check Memory: Shows RAM and swap usage.

$ free -h

35. hostname

Display Hostname: Shows the system’s hostname.

$ hostname

36. ifconfig

Network Configuration: Displays network settings.


$ ifconfig

37. ssh

Secure Shell: Connects to a remote machine.

$ ssh <a href="mailto:user@192.168.1.1">user@192.168.1.1</a>

38. scp

Secure Copy: Transfers files between machines.

$ scp file.txt user@192.168.1.1:/home/user

39. passwd

Change Password: Updates the user password.

$ passwd

40. whoami

Current User: Displays the current username.

$ whoami

41. uptime

System Uptime: Shows how long the system has been running.
$ uptime

42. shutdown

Power Off: Schedules a system shutdown.

$ shutdown -h now

43. reboot

Restart System: Reboots the system.

$ reboot

44. alias

Shortcut Commands: Creates a custom command alias.

$ alias ll='ls -la'

45. unalias

Remove Alias: Deletes a custom alias.

$ unalias ll

46. wc

Word Count: Counts words, lines, and characters in a file.


$ wc file.txt

47. head

View File Start: Displays the first lines of a file.

$ head file.txt

48. tail

View File End: Displays the last lines of a file.

$ tail file.txt

49. sort

Sort Lines: Arranges lines in a file.

$ sort file.txt

50. uniq

Remove Duplicates: Filters unique lines in a file.

$ uniq file.txt

Antivirus is cybersecurity software that detects and removes malicious software (malware) from a
computer, device, or network. If your network has end users, antivirus software is essential in the
prevention of data breaches. Read on to learn more about how antivirus works, the risks of malware and
ransomware, and more.
About antivirus software

Also known as anti-malware, antivirus software protects devices and systems from various types of
harmful software, typically delivered via email. Antivirus aims to detect viruses, worms, trojan horses,
spyware, adware, and ransomware. The primary purpose of antivirus software is to protect computers and
data from being compromised or damaged by these malicious programs.

Here are some critical functions of antivirus software:

 Virus Detection: Antivirus programs use various methods to identify known and emerging threats. This
includes signature-based detection, which involves matching the patterns or signatures of known malware,
and heuristic-based detection, which looks for behaviors or characteristics common to malware.
 Malware Prevention: Antivirus software aims to prevent malware from infecting a device or system. This
may involve real-time scanning of files and programs, monitoring network traffic, and blocking suspicious
activities.
 Destruction/Removal of Viruses: Antivirus software takes action to remove or quarantine the malicious
files if malware is detected. This process helps prevent further damage and protects the system and data.
 Monitoring and Scanning: Antivirus programs often provide options for on-demand or scheduled scans of
the entire system, specific drives, or individual files and folders. Scans help identify and eliminate potential
threats that may have infiltrated the system.

How does antivirus software work?

Antivirus software detects, prevents, and removes malicious software, commonly known as malware, from
a computer or network. Here's a general overview of how antivirus software works:

 Signature-Based Detection: Antivirus software programs maintain a database of known malware


signatures. These signatures are unique characteristics or patterns that can identify specific malware. When
you run a virus scan, the antivirus software compares the files on your computer against its signature
database. If a file matches a known malware signature, it is flagged as malicious.
 Heuristic-Based Detection: Antivirus software also uses heuristics to identify potentially malicious behavior
or characteristics that may not be explicitly defined in the signature database.
 Behavioral Analysis: The program may analyze the behavior of a program or file to determine if it acts like
malware. For example, if a file tries to access a large number of files rapidly or attempts to hide its
presence, it might be flagged as suspicious.
 Sandboxing: Some advanced antivirus solutions use sandboxing, which involves running suspicious files in a
virtual environment separate from the rest of the system. If the file exhibits malicious behavior in the
sandbox, the antivirus software can take appropriate action.
 Cloud-Based Detection: Many modern antivirus solutions rely on cloud-based databases and analysis.
When a new file is encountered, the antivirus software may send information about the file to the cloud for
analysis. This allows the antivirus program to benefit from the collective intelligence of an extensive
network of users.
 Real-Time Protection: Antivirus software often provides real-time protection by actively monitoring the
system for suspicious activity. This can include monitoring files and network activity to detect and block
potential threats.
 Automatic Updates: Antivirus software requires regular updates to combat new and evolving threats.
These updates include the latest virus definitions, security patches, and other improvements to enhance
the software's ability to identify and address new threats. Antivirus databases are constantly updated to
include information about new threats. Regular updates ensure that the antivirus software can recognize
and respond to the latest malware.
 Quarantine and Removal: If the antivirus software detects a malicious file, it may quarantine the file,
isolating it from the rest of the system to prevent further damage. Users can then decide whether to delete
or restore the quarantined file.

New and sophisticated malware can sometimes evade detection, which is why it's essential to practice safe
computing habits, such as keeping software up to date, being cautious of email attachments and links, and
using strong, unique passwords.

How are traditional antivirus and next-generation antivirus software different?

Traditional antivirus software is deployed on a computer and keeps an eye out for signatures to protect
against known attacks. The software must be installed on-site, and it can take weeks or months to deploy.

Next-generation antivirus software, on the other hand, uses artificial intelligence (AI) and other
technologies to stop known and unknown attacks. The software identifies suspicious behaviors and threats,
even if they have not been previously used in cyberattacks. It can be deployed in hours and doesn't require
any updates.

What are the risks of not using antivirus software?

The number one risk of forgoing antivirus software is that you open the door for malware to infect your
user devices and systems. Malware attacks pose significant risks to individuals, organizations, and even
nations.

Here are some of the key risks associated with viruses and malware attacks:

 Data Loss or Theft: Malware can be designed to steal sensitive information such as personal details,
financial information, intellectual property, or login credentials. This can be used for identity theft, financial
fraud, or sold on the dark web.
 Financial Loss: Malware can cause financial damage by disrupting business operations, leading to
downtime and loss of revenue. Ransomware can encrypt files or systems, demanding payment for their
release.
 System Disruption and Downtime: Malware can disrupt normal system operations, leading to downtime
and loss of productivity. Disruption is particularly damaging for businesses that rely heavily on their IT
infrastructure.
 Reputation Damage: A successful malware attack can tarnish an individual's or organization's reputation.
Customers and clients may lose trust if they perceive that their data is not secure.
 Intellectual Property Theft: Malware can target and exfiltrate intellectual property (IP), trade secrets, and
other proprietary information. This can have long-term consequences for businesses that rely on
innovation and unique offerings.
 Compromised Security: Some malware is designed to disable or bypass security measures, leaving systems
vulnerable to further attacks. This can lead to a perpetual cycle of security breaches.
 Network Compromise: Malware can spread across networks, infecting multiple systems and devices. This
can result in a broader and more severe impact on an organization's infrastructure.
 Botnet Formation: Malware can be used to create botnets, a type of cyber attack that involves controlling
computers controlled by a central server. These botnets can be used for various malicious activities, such as
distributed denial-of-service (DDoS) attacks.
 Legal Risk: Organizations may face legal consequences for failing to protect sensitive data or for being the
source of a malware attack. Data protection laws and data privacy regulations impose strict requirements
on how personal and sensitive information is handled.

To mitigate these risks, individuals and organizations should implement robust cybersecurity measures,
including regularly updating software, using antivirus and anti-malware solutions, educating users about
phishing and social engineering tactics, and regularly backing up important data.

How should I choose an antivirus software?

Choosing the right antivirus software is crucial for ensuring the security of your computer and data. Here
are a few factors to consider when selecting an antivirus program:

 Detection Effectiveness Rate: Look for antivirus software that has a high detection rate for malware,
viruses, and other threats. Check independent test results from organizations like AV-Test or AV-
Comparatives for performance evaluations.
 Modern Security Features: Consider the features offered by the antivirus software. Common features
include real-time scanning, firewall protection, email scanning, and automatic updates. Some may also
include additional features like password managers, VPNs, or parental controls.
 Overall Network System Impact: Evaluate the impact of the antivirus software on your system's
performance. Some antivirus programs can be resource-intensive and slow down your computer. Look for a
balance between effective protection and minimal impact on system performance.
 Ease of Use: Choose antivirus software that is user-friendly and easy to navigate. A complicated interface
can be frustrating and may lead to errors or missed security settings.
 Compatibility With Business Systems and Applications: Your antivirus software should be compatible with
your operating system and other business applications. Some antivirus programs are designed specifically
for Windows, while others also support macOS, Linux, or mobile platforms.
 Cost: Antivirus software comes in both free and paid versions. While free options can provide basic
protection, paid versions often offer more advanced features and better customer support. Consider your
budget and the level of protection you need.
 Customer Support: Check the level of customer support your vendor provides. In case you encounter issues
or have questions, responsive customer support can be valuable.
 Reputation: Research the reputation of the antivirus software and its vendor. Read reviews, both from
experts and users, to gain insights into the software's performance, reliability, and customer satisfaction.
 Frequent Updates: Regular updates are crucial for keeping your antivirus software effective against
evolving threats. Ensure that the software receives frequent updates to its virus definitions and program
features.
 Trial Versions: Many antivirus programs offer free trial versions. Take advantage of the trial offers to test
the software's features, performance, and compatibility with your system before making a final decision.
Remember, no antivirus software can provide 100% security, so it's also important to practice proper
cybersecurity hygiene, such as regularly updating your operating system and software, being cautious with
email attachments, and avoiding suspicious websites.

Can I outsource my antivirus protection?

Yes, antivirus solutions are often available from managed security service providers (MSSPs). MSSPs
offer a range of security solutions and services, and antivirus protection is commonly included in their
offerings. These services are designed to help businesses enhance their cybersecurity posture without the
need for in-house expertise in managing and maintaining security solutions.

MSSPs can provide antivirus software, deploy and manage it across an organization's network, ensure that
the software is up to date, and monitor for any security threats. This model is particularly beneficial for
businesses that prefer to outsource their IT management and security functions, allowing them to focus on
their core activities while relying on experts to handle their IT infrastructure and security.

When considering an MSSP for antivirus services, it's essential to assess their capabilities, experience, and
the specific features of the antivirus solution they provide. Additionally, businesses should ensure that the
MSSP follows best practices for security and regulatory compliance to protect sensitive data and maintain a
secure environment.

The last word on antivirus software

Sophos Intercept X antivirus software delivers high-impact server and container security for on-premises,
data center, and cloud. Sophos Intercept X with Extended Detection and Response (XDR) has been rated
the #1 XDR solution by G2 users in their spring 2023 reports (March 2023).

Benefits include:

 Cloud Native- Advanced Windows and Linux protection and visibility across your cloud, on-premises, and
virtual server workloads.
 Next-Gen Protection– Deep learning AI, anti-ransomware capabilities, and exploit prevention techniques
give you world-class protection.
 Optimized for Performance– Deploy as a lightweight agent or via API for Linux to integrate with your
security operations, IT, and DevOps processes.

Sign up for a free trial of Intercept X today. If you already have an active Sophos Central account, you can
start your trial from the Sophos Central Admin Console. Log in to Sophos Central, click Free Trials, and
select Intercept X Advanced for Server with XDR.

What is Antivirus Software?


In today’s digital era, the rise in cyber threats has dramatically highlighted the necessity for robust digital
security for both individuals and businesses. Antivirus software stands as a key defender in the ongoing
fight against cybercrime. This article offers a detailed exploration of antivirus software, including its
functions, various types, advantages, and guidelines for selecting the most effective solution in 2024.

What is Antivirus Software?

Antivirus software is a specialized program designed to detect, prevent, and remove malicious software,
commonly known as malware. It acts as a gatekeeper for your digital devices, monitoring data and
blocking potential threats from causing harm. Its primary function is to safeguard computers and mobile
devices from malware such as viruses, worms, trojans, ransomware, and spyware.

What Does Antivirus Software Do?

Antivirus software operates by scanning your device regularly, looking for known threats and new,
emerging malware strains. When a threat is detected, the software either blocks it or assists in its removal,
thereby protecting your device from potential harm. Apart from providing real-time protection, antivirus
software also helps in:

 Detecting, preventing, and removing malware and viruses: This is the primary function of any antivirus
software. It scans your devices for potential threats and takes necessary actions to neutralize them.
 Blocking intrusive pop-ups: Pop-up advertisements can be a source of malware. Antivirus software helps in
blocking these intrusive pop-ups, ensuring a safer browsing experience.
 Scanning in real time: Real-time scanning helps in protecting your devices as you browse the internet, open
emails, and download files.
 Protecting external devices: Antivirus software also scans external devices like hard drives and USB drives,
preventing potential threats from infiltrating your system.
 Blocking scam sites: By restricting access to harmful websites, antivirus software helps in preventing
phishing attempts and scams.
How Does Antivirus Software Work?

Antivirus software uses multiple detection methods to identify and block malicious programs. The key
methods include:

 Signature Detection: This method involves scanning files for known malicious code or ‘signatures’. The
limitation of this method is that it can only detect previously identified threats.
 Heuristic Detection: This method involves looking for suspicious behavior or code structures in files. It’s
designed to catch new, unknown threats by identifying general attributes of malware.
 Behavior-based Detection: This detection technique examines the behavior of programs and files to
identify suspicious activities. This method is useful in detecting unknown malware that behaves in a way
similar to known threats.
 Cloud-based and Sandbox Analysis: Some antivirus software uses cloud-based or sandbox analysis to test
suspicious files in a controlled environment before they can harm your system.
 Intrusion Prevention (HIPS): Host Intrusion Prevention Systems (HIPS) monitor activities within a system
and alert users to any potentially harmful actions.

What are the Types of Antivirus Software?

Antivirus software comes in various forms, each offering different levels of protection. Some of the
common types include:

 Standalone Antivirus Scanners: These are basic antivirus programs that provide protection against known
threats.
 Internet Security Suites: These are comprehensive packages that offer antivirus protection along with
additional security features like firewalls, privacy controls, and more.
 Cloud-based Antivirus Programs: These programs use cloud technology to analyze suspicious files in a
remote server, reducing the load on the user’s device.
 Machine Learning Antivirus Programs: These use artificial intelligence and machine learning to identify new
threats.

What are the Key Features of Antivirus Software?

When selecting an antivirus program, it’s essential to consider the following key features:

 Real-time Scanning: The software should be capable of scanning your system in real-time to detect and
block threats as they occur.
 Automatic Updates: An effective antivirus program should regularly update its virus definitions to protect
against the latest threats.
 Heuristic Scanning: This feature helps in detecting unknown threats that have not been defined in the virus
database yet.
 Sandboxing: This feature allows the antivirus to run potentially harmful programs in a separate, secured
environment, preventing them from causing damage to the system.
 Email Protection: The antivirus should scan emails and attachments for any potential threats.

Benefits of Antivirus Software

Using antivirus software comes with numerous benefits, including:

 Protection Against Cyber Threats: Antivirus software provides an essential layer of protection against
various cyber threats like viruses, ransomware, spyware, and more.
 Safe Browsing: By blocking harmful websites and downloads, antivirus software ensures a safer browsing
experience.
 Identity Protection: Some antivirus programs offer features that help protect your personal information
from being stolen.
 Improved PC Performance: By eliminating malware that can slow down your PC, antivirus software helps in
improving your system’s performance.
What is its Effectiveness Against Various Threats?

While antivirus software plays a crucial role in protecting your devices, its effectiveness can vary based on
the type and sophistication of the threat. Most modern antivirus solutions can effectively deal with common
threats like viruses, spyware, and ransomware. However, new and evolving threats may sometimes slip
through if the software is not updated regularly.

How to Install and Setup Antivirus Software?

Installing and setting up antivirus software is usually a straightforward process:


 Purchase or Download: Purchase a reputable antivirus software or download a free version from the
vendor’s official website.
 Installation: Run the installation file and follow the instructions. You may need to restart your computer
after the installation.
 Setup: After installation, open the software and go through the initial setup process. This may include
updating the virus definitions and scheduling regular scans.
 Scan: Perform an initial scan of your computer to check for existing threats.

Comparison: Antivirus Software vs. Firewall Software

While both antivirus and firewall software provide essential security, they serve different purposes.
Antivirus software is designed to detect, block, and remove malware from your devices, while a firewall
protects your devices by controlling network traffic and blocking unauthorized access to your system.

What Should be the Features of the Best Antivirus Software?

Choosing the best antivirus software depends on your specific needs. However, some key features to look
for include:

 Real-time Protection: The software should provide continuous protection against threats.
 Automatic Updates: It should regularly update its virus definitions to protect against the latest threats.
 Comprehensive Scanning: The software should be capable of performing in-depth scans of your system
and external devices.
 User-Friendly Interface: The software should be easy to use, with intuitive controls and settings.
 Customer Support: The vendor should provide reliable customer support in case of any issues with the
software.

In conclusion, antivirus software plays a critical role in protecting your digital devices and data from
various cyber threats. It’s crucial to choose an antivirus program that fits your needs and keeps your
systems safe and secure. By understanding how antivirus software works and the features it offers, you can
make an informed decision and ensure optimal digital security.

Overview – Antivirus Software

Anti-virus software is a program designed to detect, prevent, and remove malicious software (malware)
from computers and networks. It plays a crucial role in protecting systems from viruses, worms, trojans,
ransomware, spyware, adware, and other types of malwares. Antivirus programs use various detection
methods and algorithms to identify and neutralize threats.
From Nortan Antivirus

How Antivirus Software Works

Step-by-Step Process:

1. Signature-Based Detection:
o Definition: This is the most common method. The antivirus software uses a database of known
malware signatures (unique strings of data or code patterns) to identify malware.
o Process: When a file is scanned, the antivirus software compares its contents against the database
of known signatures. If a match is found, the file is flagged as malicious.
o Update Mechanism: The antivirus database is regularly updated with new signatures to protect
against the latest threats.
2. Heuristic Analysis:
o Definition: This method involves analysing the behaviour or structure of a file to determine if it is
malicious, even if it does not match any known signatures.
o Process: The software examines code for suspicious behaviour or patterns that are typical of
malware, such as attempts to modify system files or registry entries.
3. Behavioural Analysis:
o Definition: This method monitors the behaviour of programs in real-time to detect any suspicious
activity.
o Process: If a program exhibits behaviour characteristic of malware (e.g., attempting to encrypt
large numbers of files or making unauthorized network connections), the antivirus software can
block the activity and quarantine the program.
4. Sandboxing:
o Definition: This involves running suspicious files in a controlled, isolated environment to observe
their behaviour without risking harm to the actual system.
o Process: The antivirus software executes the file in the sandbox and monitors its actions. If the file
behaves maliciously, it is flagged and quarantined.
5. Real-Time Scanning:
o Definition: Also known as on-access scanning, this feature continuously monitors the system for
threats, scanning files as they are accessed or modified.
o Process: The antivirus software scans files when they are opened, executed, or saved, providing
real-time protection against malware.
6. Full System Scans:
o Definition: This involves scanning all files and programs on the system for malware.
o Process: The antivirus software performs a comprehensive scan of the entire system, including the
operating system, installed applications, and user files.

Advantages of Antivirus Software

1. Protection Against Malware:


o Anti-virus software provides essential protection against a wide range of malware, including
viruses, worms, trojans, ransomware, spyware, and adware.
2. Real-Time Threat Detection:
o Real-time scanning ensures that threats are detected and neutralized immediately as they occur,
preventing malware from causing damage.
3. Regular Updates:
o Antivirus programs are regularly updated with new malware signatures and detection algorithms to
protect against the latest threats.
4. Quarantine and Removal:
o Detected threats are quarantined to prevent them from causing harm, and users can safely remove
or restore the affected files.
5. Improved System Performance:
o By detecting and removing malware, antivirus software can help maintain optimal system
performance and prevent slowdowns caused by malicious activities.
6. User-Friendly:
o Most antivirus programs are designed to be user-friendly, with intuitive interfaces and automated
scanning and update features.

Disadvantages of Antivirus Software

1. Performance Impact:
o Anti-virus software can consume significant system resources, leading to slowdowns, especially
during full system scans or when running on older hardware.
2. False Positives:
o Legitimate files or programs can sometimes be mistakenly identified as malware, leading to false
positives. This can cause disruptions if important files are quarantined or deleted.
3. Incomplete Protection:
o Anti-virus software may not detect all threats, especially new or sophisticated malware that uses
advanced evasion techniques. It is not a foolproof solution and should be part of a broader security
strategy.
4. Cost:
o While there are free antivirus solutions available, many offer limited features. Comprehensive
protection often requires purchasing a subscription, which can be costly.
5. User Dependency:
o The effectiveness of antivirus software depends on user behaviour. If users disable real-time
protection, ignore warnings, or fail to update the software regularly, the level of protection
diminishes.
6. Potential Conflicts:
o Running multiple antivirus programs simultaneously can cause conflicts and system instability. It is
generally recommended to use only one primary antivirus solution.

Example of Using Antivirus Software

Scenario: A user wants to protect their computer from malware using Anti-virus software.

1. Installation:
o The user downloads and installs a reputable antivirus program, such as Norton, McAfee,
Bitdefender, or Kaspersky.
2. Initial Scan:
o After installation, the antivirus software performs an initial full system scan to detect and remove
any existing threats.
3. Real-Time Protection:
o The Anti-virus software enables real-time scanning, which continuously monitors the system for
any suspicious activity or files.
4. Regular Updates:
o The software is configured to automatically update its virus definitions and detection algorithms to
stay protected against new threats.
5. Scheduled Scans:
o The user schedules regular scans (e.g., weekly) to ensure ongoing protection and detection of any
new threats.
6. Quarantine and Removal:
o If the Anti-virus software detects a threat, it quarantines the affected file and notifies the user. The
user can then review the threat and choose to delete or restore the file.

Summary

Anti-virus software is a critical component of computer and network security, designed to detect, prevent,
and remove malware. It employs various detection methods, including signature-based detection, heuristic
analysis, behavioural analysis, and sandboxing, to identify and neutralize threats. The advantages of
antivirus software include protection against malware, real-time threat detection, regular updates,
quarantine and removal capabilities, improved system performance, and user-friendly interfaces. However,
there are also disadvantages, such as potential performance impact, false positives, incomplete protection,
cost, user dependency, and potential conflicts with other security programs.

You might also like