LINUX FOR BEGINNERS Discover The Essentials of Linux Operating System

Download as pdf or txt
Download as pdf or txt
You are on page 1of 134

LINUX

FOR BEGINNERS

Discover the essentials of Linux operating system.


Best Practices to learn Installation, Configuration
and Command Line Efficiently

NATHAN JONES

Text Copyright © [Nathan Jones] 2019


All rights reserved. No part of this guide may be reproduced in any form without permission in
writing from the publisher except in the case of brief quotations embodied in critical articles or
reviews.
Legal & Disclaimer
The information contained in this book and its contents is not designed to replace or take the place of
any form of medical or professional advice; and is not meant to replace the need for independent
medical, financial, legal or other professional advice or services, as may be required. The content and
information in this book has been provided for educational and entertainment purposes only.
The content and information contained in this book has been compiled from sources deemed reliable,
and it is accurate to the best of the Author's knowledge, information and belief. However, the Author
cannot guarantee its accuracy and validity and cannot be held liable for any errors and/or omissions.
Further, changes are periodically made to this book as and when needed. Where appropriate and/or
necessary, you must consult a professional (including but not limited to your doctor, attorney,
financial advisor or such other professional advisor) before using any of the suggested remedies,
techniques, or information in this book.
Upon using the contents and information contained in this book, you agree to hold harmless the
Author from and against any damages, costs, and expenses, including any legal fees potentially
resulting from the application of any of the information provided by this book. This disclaimer
applies to any loss, damages or injury caused by the use and application, whether directly or
indirectly, of any advice or information presented, whether for breach of contract, tort, negligence,
personal injury, criminal intent, or under any other cause of action.
You agree to accept all risks of using the information presented inside this book.
You agree that by continuing to read this book, where appropriate and/or necessary, you shall consult
a professional (including but not limited to your doctor, attorney, or financial advisor or such other
advisor as needed) before using any of the suggested remedies, techniques, or information in this
book.
Table of Contents
INTRODUCTION
Chapter 1. : what is Linux
Chapter 2. : terminology
Chapter 3. :Linux desktop technology
Chapter 4. : most of the popular Linux program
Chapter 5. : installing Linux OS
Chapter 6. :types of installation
Chapter 7. : exercises
How to create a blank file
Copying a file or a directory
Chapter 8. setting up Linux
Chapter 9. navigating Linux
Chapter 10. essential Linux commands
Changing Directories
‘Less’ Command
‘Ln’ Command
‘Locate’ Command
‘Logout’ Command
‘Ls’ Command
‘More’ Command
‘Sudo’ Command
‘Mkdir’ Command
‘Uname’ Command
‘Touch’ Command
‘Cal’ Command
‘Date’ Command
Chapter 11. instruction to Linux terminals
Chapter 12. becoming a LInux power user
Chapter 13. using the shell
Chapter 14. moving around the files system
Chapter 15. working with text files
Chapter 16. managing running process
Chapter 17. becoming a Linux system administrator
Chapter 18. managing users account
Chapter 19. managing disks and file systems
Other Useful Commands

Chapter 20. configuring system logging


Chapter 21. learning Linux security techniques
Chapter 22. understanding basic Linux security
Chapter 23. understanding advanced Linux security
Chapter 24. enhancing Linux security with selinux
Chapter 25. securing Linux on a Networking
Chapter 26. extending Linux into the Cloud
Conclusion
INTRODUCTION
So, what is Linux, actually?
For starters, Linux is a free and open-source Operating System, based on
UNIX and PSOIX codes. In short, it is free to download, and free to use,
and was originally based on the paradigm of Intel x86. In fact, out of all
Operating Systems, Linux has the largest base that has been installed,
compared to the rest.
This is why a computer or device that works on Linux works fast, and are
sometimes even compared to those amazing supercomputers! This is
because Linux gets to be tailored to any kind of system where it’s being
used for—compared to other operating systems that work best on a certain
kind of device alone.
This so happens because of the so-called open source software
collaboration that can support various kinds of libraries and directories.
The next step is to learn more about creating and editing shell scripts and
create automation scripts that will allow you to use Linux in a more
efficient manner.
The Linux operating system (OS) is not something your average consumer
realizes the extent to which it is the most utilized platform and is tailored to
devices such as Android phones, Smart watches, refrigerators, washing
machines, video game consoles and DVRs just to name a few.
Linux can be used to host a website, create a new and secure file or e-mail
server, diagnose another system you own, and possibly recover crashed
files. It can enhance Chromebooks. Even NASA, Dell, IBM, and Hewlett-
Packard have tapped into the Linux OS.
It was first developed as a family extension of the various iterations of
UNIX. It is free, open-source code and released October of 1991 by Linus
Torvalds. Torvalds is a Finnish-American Engineer who believes that open
source is the only way to go. Thankfully he thought so. At first, Linux was
primarily for personal computers but as you can see it has a use that has
expanded exponentially and now runs some of the largest super computers
as well as the devices just named.
Since Linux release, other programmers have developed their own versions
or distributions of Linux. These are also called distros . These next
generation developers were able to do this because of the open sourcing of
Linux. This is a good thing, but having many different versions has its
challenges as you will see.
Necessary Software
Before you get started with programming, you will need either a text editor
that is Linux-compatible or an integrated development environment. If you
use a text editor, you will also need a compiler that will enable your code to
be patched into the Linux framework. If you use an integrated development
environment, this will usually be done automatically. There are plenty of
text editors and integrated development environments that are available for
free as open-source software.
As an alternative, you can begin by using the Linux shell. There are some
programs and commands that can only be implemented with the shell, and
you can also make some configurations and customizations to your own
system with the shell. How you access it may vary based on the distribution
that you use, but in many cases, you can access it be pressing Ctrl – Alt – T
on the keyboard.
You will also want to have a sandbox, which is a necessary tool in any
programmer’s arsenal. A sandbox allows a program to run using a limited
amount of the computer’s environment. This way, if there is a problem with
the program, such as a bug or unintended error, only the resources that are
located within the sandbox will be affected. The rest of the computer will be
unharmed. Sandboxes are very important when writing codes for a new
program, as they enable programmers to test out new developments without
running the risk of harming their computers. There are several different
sandboxes available for Linux, most of which are free.
Programming Language
The programming language most commonly associated with Linux is C, a
language that first appeared in 1972 at Bell Labs (then a part of AT&T).
Once written, it is translated into a machine language with a compiler
program. Unix, the forerunner of Linux, was one of the first programs to be
written in C, and when Linus Torvalds first created the Linux kernel, it was
written in C.
With this information in mind, you would be forgiven for believing that any
programming in Linux must be written in C. Not so. Programming
languages have evolved and developed due to increased needs, both in
complexity and abstraction. Newer languages, such as Java, C++, and
Python enable higher functionality and more complex programs, including
the building of blockchains! If Linux was limited to running only code
written in C, it would have become obsolete long ago.
Virtually any programming language can be used to write code in Linux, so
whichever language you are most proficient in is what will be most suited
to writing code in Linux. The exception may (but not necessarily is) be
specialized languages, such as Solidity, which was developed specifically
for programming on the Ethereum blockchain. What is necessary to get
coding done in different languages to work on Linux is a compiler that will
translate that language so that it is compatible with the Linux kernel. How
to do this will be explained in the next chapter.

That’s about all that you need to get started with programming on Linux. In
addition to a good, reliable computer and a Linux distribution, you need a
text editor, the Linux shell, or integrated development environment, a
sandbox, and knowledge of a programming language. Now is the time to
start writing the code to your program! This process will probably involve
quite a bit of trial and error, and you may need to execute the program
several times before it is perfect. .
Chapter 1 : what is Linux
Early Beginnings
Back in 1969, the UNIX Operating System—also known as the forefather
of Linux—was created at the AT & T Bell Laboratories, with C-
Programming basics, and high availability of languages that could be used
for porting purposes. With that kind of background, this OS became the
most relied-on operating system of business and school administrators.
However, certain controversies happened when an anti-trust case prevented
UNIX from continually being used for businesses, but since its developers
—and its supporters—believed that there’s still more to UNIX than what
people think, they decided to develop the GNU Kernel—and it was because
of this that LINUX finally came to fruition.
Enter Linux
With the help of its principal author, Linus Trovalds, and his principle of
finding a truly functional Operating System that everyone can use, he
decided to work on the GNU Kernel. He wanted something that people,
whether they’re professionals or just wanting to use the computer and other
devices for entertainment, could really use. He then began to upload files
created from the Kernel to the FTP Server, and wanted to call it “Freax”,
but his collaborators and other professionals at the time didn’t think it was a
good idea, and so playing with his name, Linux was born in 1991!

1. To create an Open-Source Programming Language, so it


would be free, and everyone would be able to contribute
to its development;
2. To create something that’s as good as its predecessors and
competitors, but make sure that it is easy to understand,
and that it is intuitive;
3. To create a programming language that would be useful
for everyday tasks, and;
4. To simply create a programming language that could be
compared to plain English, when readability is concerned.
When it was first published (to be used) in 1991 as Version 0.9.0, core
datatypes, functions, and inheritance such as str, dict, and list were already
available. In 1994, Version 1.0 was released and it involved reduce, filter,
map, and lambda, amongst others, and in 1995, Van Rossum continued to
work on developing Linux while at the Corporation for National
Research Initiatives in Virginia!
In 2000, the BeOpen Linux Labs team was established, and Version 1.6 of
the language was put out, with important bug-fixes. Another version called
Version 2.0 was released in 2008, followed by 3.0—which could coexist
with the other!
Linux Now
Today, Linux is partly responsible for helping the world work like it should.
From people who only work with computers at home, to larger feats such as
NASA using Linux-powered computers, it is no surprise why Linux is
getting the attention of many—and today, you have the chance to learn
about it, and more!
Chapter 2 : terminology
• Adware: Software that forces ads to display on a computer or a
mobile device.
• Attack: An incident where access is gained or data is extracted.
• Back Door: A hidden way to gain entry into a system or software
that bypasses network security.
Black Hat: A hacker who hacks predominately for personal gain, fame, or
to deface a company. Black hats are the “bad guys.”
• Bot: An automated program that can do something repeatedly at a
fast rate.
• Botnet: Multiple computers that are controlled without permission
that generally do automated tasks. Also referred to as a zombie army.
• Brute Force Attack: An automated attack that tries different logins
and password combinations until access is granted.
• Buffer Overflow: Buffer overflow is when more data is written to a
computer system than a buffer can hold.
• Clone Phishing: Modifying an email with a fake link in an attempt to
extract personal information.
• Cracker: A black hat that modifies software to gain unintended
features.
• Cryptojacking: An attack on cloud computing services to mine
cryptocurrency.
• Cryptocurrency: A type of digital currency where there is a way to
verify funds, generate currency, and transfer funds with the need of a central
bank.
• Denial of Service Attack (DoS): An attempt to make resources of a
system unavailable to legitimate users by overloading the computer system.
• Distributed Denial of Service Attack (DDoS): A Denial of Service
attack that comes from several computers at once. This is usually achieved
with a botnet.
• Exploit Kit: The software that runs on web servers to identify
vulnerabilities in client machines. It exploits vulnerabilities to install and
run malicious code or malware.
• Exploit: An exploit is software or data that takes advantage of a bug
or vulnerability.
• Firewall: A filter designed to protect against intruders while allowing
communication between the systems behind the firewall and the internet.
Grey Hat: A hacker who blurs the line between white hat and black hat. A
grey hat can hack either to help protect or to attack a system maliciously.
Hacktivist: Someone who hacks for political, social, or religious reasons.
• Keystroke Logger: Software that records keystrokes, which is the
keys that are pushed on a keyboard or the places touched on a touchscreen.
Often used to record logins and passwords.
• Logic Bomb: A virus that delivers a malicious action when some
conditions are met.
• Malware: A group of malicious software that includes adware,
ransomware, viruses, trojan horses, worms, etc.
• Master Program: A master program is a software that controls
infected computers to send out spam or Denial of Service attacks.
• Phishing: An email fraud technique where the hacker sends out
official looking emails to gather personal information like passwords,
logins, credit card numbers, and other personal data.
• Phreaker: One of the original hacker sub-cultures that revolved
around using blue boxes to make expensive long distance calls for free or to
tap phones.
Risk: The chance for a threat to take advantage of a vulnerability.
Rootkit: Generally malicious software that hides processes and programs
from detection and enables privileged access to the device.
Shrink Wrap Code: An attack that exploits unpatched software.
Social Engineering: An attempt to deceive to gain personal information.
Spam: Unwanted emails sent to a large number of people without the
recipient’s permission.
Spoofing: Attempt to gain access to a computer by sending a message that
appears to come from a trusted host.
Spyware: Software that collects information about the user without
permission. It may transfer that information to another computer or take
control of the computer.
SQL Injection: An attack where SQL code is injected into entry fields to
gain access, data, or install malware.
Trojan: A program that appears valid but that destroys files and alters or
steals information.
Threat: A hacker or software that can exploit a vulnerability.
Virus: Code that replicates itself inside a computer and damages data or
corrupts the computer system.
Vulnerability: A weakness in a computer system that can be exploited.
White Hat: A white hat is an ethical hacker who hacks to find exploits,
bugs, and vulnerabilities to better protect computer systems. White hats are
the “good guys.”
Worm: A type of virus that self-replicates in active memory.
Cross-Site Scripting (XSS): A type of vulnerability in web applications that
allows attackers to inject code into websites.
Zombie Drone: A computer that is unknowingly controlled by another
computer without the user’s knowledge. A zombie drone is also known as a
soldier or a drone.
Command Line Prompts
Ethical hacking uses many tools, and command line prompts (CLP) are one
of them. It is important to have a working knowledge of CLPs, as many of
the tools use CLPs to operate them. Here are some helpful CLPs that come
in handy while hacking.
Ping
Ping is a command that allows the user to determine TCP/IP, IP addresses,
and networks.
Ping x.x.x.x (replace x with an IP address) or “ping www.example.com”.
Either syntax will run a ping on the server and respond with data about the
ping.
nslookup
nslookup is a command used to query the domain name server (DNS) to
obtain the IP address or domain name.
nslookup www.example.com
To find out the IP address of specific Mail Servers with nslookup use the
following code:
NSLOOKUP (Press Enter)
SET TYPE=MX (Press Enter)
GOOGLE.COM/YAHOO.COM
tracert
tracert is a command line prompt that traces the route between the user’s
computer and a destination on the internet. This command also calculates
the time each transfer takes.
tracert x.x.x.x (replace x with the IP address) or tracet www.google.com
Chapter 3 : Linux desktop technology
Now we will talk about how to install the desktop version of the Ubuntu
distribution of Linux. When you install this version, at the end of it, you
will get a nice graphical user interface—you will be able to see files and
folder icons that you can click and use to navigate around the Linux
operating system. It will also have basic applications like web browsers to
navigate websites online, and word processing applications such as
OpenOffice for when you need to type documents, etc. Again, installation is
a pretty simple procedure; you just click a few buttons and you are good to
go.
Download – Just like with the server version, go to http://www.ubuntu.com/
and download the desktop version of Ubuntu Linux.

Click the option on top that says "Desktop" to proceed to the page where
you can download the desktop version of Ubuntu.
Once you are there, go ahead and click on the orange button that says
"Download Ubuntu." After you click that, you will be presented with two
versions of the desktop version of Ubuntu Linux: Ubuntu 14.04.4 LTS and
Ubuntu 15.10.
If you notice on the right hand side, it will ask you to choose your flavor of
that particular version. This is them asking you whether you want to 32-bit
or the 64-bit version of the Ubuntu Linux desktop. Just choose the version
that applies to your system and then click "Download."

Go ahead and wait until ISO file download is finished. Once that's done,
burn that ISO file to a CD or DVD, put that into the system where you want
to install Linux, and then boot off of it. Now we'll proceed with the
installation process.
The interesting part that you will probably notice during the desktop
version's installation is that it will give you two options: try Ubuntu or
install Ubuntu. The curious thing about Linux is that they have things called
Live CDs. What a Live CD means is that the entire operating system is
installed and can be run off of the CD.
When you are dealing with Windows, Mac OS, or even Linux server, you
always have to install the operating system for it to work on the computer.
With a Live CD, you can actually boot straight off of the CD and use all of
the functionality of the operating system without installing it. You can surf
the web, manage files, edit text, etc. by just running the entire operating
system from the CD itself.
In addition, if you have a Windows computer, you can put in a Linux Live
CD, boot from it, and do whatever you want to do with it without affecting
the computer at all. This is a great way for a user to test a particular Linux
distribution first without going through the lengthy installation process.
So, going back to our installation process, just go ahead and click install
Ubuntu for now.

Next, you will be asked to choose your region and time zone. Go ahead and
choose the region and time zone that applies to you and click "Forward."
Again, just like in the server edition, the installation will now ask you to
choose your keyboard layout. Go ahead and choose the one that applies to
you and click "Forward."

Next, the installation will ask you to prepare the disk space in your hard
drive prior to installation. If you want to use your entire disk for Ubuntu
alone, go ahead and choose the option that says, "Erase and use the entire
disk." However, if you have another operating system on your hard drive
and you want to install Linux inside a different disk partition, then choose
the option that says, "Specify partitions manually."
Specifying partitions manually involves telling the installation process how
much disk space you want to allocate for the Linux installation. For now,
since you are still a beginner, let us assume that you are just installing
Linux alone in your hard drive, and that you are not going to do any
partitioning. So go ahead and choose, "Erase and use the entire disk" and
press forward.

After you press "Forward," the installation will ask you what your name is,
what name you want to use to log in, the password that you want to put for
the user account, and the name you want to give the Linux computer.

Also, if you scroll down a little bit, you will see that the installation is
asking you whether you want to log into the computer automatically once it
boots up, require a password during login, and require a password during
login and decrypt your home folder. The latter option only applies if you
installed Linux with the encryption feature enabled.
Go ahead and enter the information needed and then press "Forward." Next,
the installation process will show you the all the settings and options you
have chosen so far and what it is about to do. If everything looks okay, go
ahead and press "Install."

Once you click install, the installation will now proceed and you will see a
window that has a progress bar at the bottom. At this point, just exercise
patience and wait until the progress bar reaches 100%.

Once the progress bar reaches 100%, it will tell you that the installation is
complete and that you need to restart your computer to finalize and use the
new installation. Go ahead and click "Restart Now."
Again, the actual time that it will take for the process to finish will depend
on your hardware. Do realize you should look at the hardware requirements
for the desktop version of the Ubuntu Linux operating system. Remember,
the server version is extremely stripped down. There is almost nothing to it
really.
The desktop version has all these fancy graphics and user interfaces, as you
can evidently see even from the installation itself. Where the installation of
the server version basically is text based, the installation for the desktop
version actually has graphical user interface windows and option buttons
that you can actually click on.
All of these fancy graphical niceties actually does require pretty decent
hardware. It is therefore recommended that if you are going to use the
desktop version of Ubuntu Linux, your computer should be at least five
years or younger with at least 1Gigabyte of RAM. If you have any less than
that, it may not have the resources it requires to run.
But in the grander scope of things, the desktop version of Linux still has a
much lighter system requirement compared to Microsoft Windows or Mac
OS.
After the restart sequence of your computer is done and you finish logging
into Linux using the credentials that you entered during installation, you
will now reach the desktop of Ubuntu Linux.
Just like what we have mentioned prior, you now have something that
vaguely looks like Microsoft Windows or the Mac OS operating system. As
you can see right off the bat, you have your applications on the left hand
side such as Firefox for web browsing, OpenOffice Suite for word
processing tasks, your home folder, Linux settings, Amazon, and much,
much more.
Chapter 4: most of the popular Linux program
Fedora is a Red Hat Linux code based OS that provides users latest free and
open source software. It provides this software in a stable, easily
manageable and secure form. It is one of the software created by the Fedora
project funded by Red Hat Linux.
Online Linux training invariably includes Fedora as a part of the
curriculum. Why is it so?
Fedora focuses on innovation, integration of new technologies and works
with many Linux developing communities. Being freely distributed with
updates every six months it is the most evolving OS in the Linux
community. Continuous upgrade means it is loaded with the newest
technologies which make it the best technology for experimentation.
This is the reason it is a part of beginner Linux and rhce training as well.
The cutting edge technology which is stable is the USP of Fedora and the
reason behind it being part of Red Hat Linux basics.
Is Fedora being used as a test platform for Red Hat Linux?
Red Hat Linux community is promoting Fedora for the development of new
technology is indeed true. However, it is not true that it is only Red Hat
Linux that uses and contributes to the development of Fedora.
There are many other contributors and just like some technology of Fedora
is being used by the Red Hat Linux Enterprise, other distributors are also
using it. Another thing is that Fedora though is upgraded every 6 months is
a very stable and pre-tested software. So it is quite safe to use Fedora to
learn new things. This is why it is being used by most online Linux training
as a part of Linux introduction for beginners.
Red Hat Linux Enterprise and Fedora relationship
Red Hat Linux Enterprise and Fedora project have a relationship which is
mutually beneficial for both. It ensures rapid innovation for Red Hat Linux
and Fedora gets the sponsorship and feedback on issues with the new
technologies.
When the new tested technology migrates to Red Hat Linux, it is available
to a broader community which makes the technology robust for users. So
Fedora is the incubator for latest technologies and innovation in Linux.
In fact, Red Hat Linux always tries to make Fedora rich with features which
make handling computers much easier. Various features of Fedora like
Network Manager and Pulse Audio make it an enjoyable experience with
the option of experimentation.
After all, Linux is open source which benefits from the feedback from its
users and developers community. This is the reason for Fedora being part of
Linux essentials and rhcsa training.
Ubuntu and Fedora
Now let us discuss the question of choice of Linux Operating system.
Ubuntu is the most popular and user friendly while Fedora is loaded with
the latest technology. So which one to choose?
Well it depends on the use. If the user is just using the computer for office
jobs which does not include programming then Ubuntu is of course the
better deal.
However with latest technology and regular development Fedora scores
over Ubuntu in benchmarking tests. So it largely depends on the use of the
software. If the question is to migrate from Windows Ubuntu is the obvious
choice and if you are a serious programming nerd then Fedora is the best
bet.
Linux Foundation recommends learning both Ubuntu and Fedora for a
complete experience of Linux.
Chapter 5 : installing Linux OS
Versions

We now will have a quick word about which version of Linux to install.
This is very popular distro and has many features. It also offers a lot of
support from the FLOSS community. Ubuntu itself also has many
"variations" however. They're basically the same Ubuntu core with a
different graphic/desktop environments. You will see these listed as either
XFCE, Openbox, GNOME, Unity, or KDE, just to name a few.
These different variations of the distros themselves also have different
elements to them such as window managers and desktop environments.
A window manager is the software that allows all of the interactions with a
graphical user interface. These elements provide the different window
panels, menus and taskbars, settings and appearances. If coupled, the two
provide you with more options (this would apply to desktop environments
such as GNOME and KDE versions of Linux). You also could download
more than one environment, and switch between them when you want a
different desktop environment at each boot up. Most of these environments
for Ubuntu come with both the environment and with the window manager.

Desktop Installation:
Again, this version of Linux will give you the graphics interface (GUI) that
many are used to and expect from using computer.
To install
Before you start you should make sure you have backed up your computer
before trying either version as a precaution. Linux is not as likely as
Windows to crash, but it is best to be prudent and protect your data.
Pull up the website for www.Ubuntu.com. Always use legitimate websites
for your distros and other needs. Once you see the distro that you need,
check your computer’s requirements. Is there enough room for install? Are
there hardware or software components that do not match what the distro is
stated to require? At this stage, you can decide if you need to repair or add
anything before moving forward. You may even decide to go with another
distro.
From the webpage, select the Linux CD image (an .ISO file) that you would
like, and choose to download to a disc or a USB. This is highly
recommended to download to the external media over a direct install to
your hard drive. It is portable, it is non-permanent, and will not make
changes to your computer system. You can boot the system straight from
the copy that you make. More will be said about this. The desktop version
also will be a lot smaller than the server edition.

After the download, you should boot it off of the CD drive or USB. This is
called a live environment. The good news is that this is not going to affect
or change your computer at all. However you also have the option to install
the distro to your computer. Be patient during the download, as in either
case, the download may take a while. Remember that this version is a bit
bigger than the server version in comparison. It also depends on your
hardware, the age of your system as well as your internet speed.
With an install you can easily save settings, files and other components
between uses that you can’t get with the USB or disc reboot. However, you
could also save files to your drive to use on your next reboot with a USB
drive, by enabling the “persistence” setting.
Options to Try (Use Live) or Install Ubuntu (www.linuxandubuntu.com)
For the install on your drive:
For hard installation we recommend to use the guided installation, unless
you are more advanced with Linux (in which case, you probably would not
be reading this guide).
Ubuntu makes the following, additional recommendations prior to installing
the system:

Make sure you are plugged in and also connected to the


internet. Stay connected.
Download updates while installing and choose to also install
third-party software.
You should remember that by installing Ubuntu on your entire hard disk
you will erase all data that is currently on the drive. Backup all data before
you install Ubuntu on your actual drive! If this scares you, you may want to
look at the Live installation instead. If you want to also keep another
backup copy in a location where they are safe and away from corruptible
hardware. Try a cloud based program such as Jungle Disk. It does have a
low cost to subscribe but the service is worth it, and it plays well with
Linux.
www.ubuntu.com

For the CD/USB (Live) install:


If you wisely chose to do a live environment installation, once it has been
downloaded and rebooted from the CD or USB you just follow the series of
prompts. Some prompts are simple information from you such as language
and preferences. Some prompts will ask questions about what you want to
do with your system afterwards, or who may have access to the system.
Other prompts include a question to partition (for advanced users). You may
have to disable the “Secure Boot” setting if it will not allow you to boot
Linux with some newer versions on Windows.
Upon rebooting, you will immediately see that your tabs include functions,
applications, an internet browser, and tools similar to MAC or Windows.
Home or My computer is your “C” Drive.
Note: If your computer doesn’t read the CD or USB and install
automatically, try the F12 key for the menu to allow you to boot.

Virtualization:
Another great feature of any distro is the virtual desktop, which enables you
to toggle between operating systems. A virtualized desktop is exactly that.
It is the user interface in a virtual environment, and it is stored on a remote
server instead of locally. The virtual operating system runs within an
application. This can be much easier and more efficient than dual booting.
You can get these in an App. Some popular ones for Linux are Microsoft
Virtual PC, VMWare, VMWare Workstation, or VirtualBox. Do some
research on these to explore this option as well.

VirtualBox Manager Screenshot (www.lifehacker.com)

Dual Boot Option:


So you have the choice to install Linux or to use the live environment. You
also have the choice to run Linux by itself, wipe out your current operating
system entirely and substitute it with Linux. You also could opt to run it
side by side with your current system such as Windows.
If you chose the latter, you can partition the system to allow for both, and
toggle between them as needed. Being able to troubleshoot Windows or
recover data is another benefit to having the partition, or to having the live
USB or disc. Some people like the option of having both types of systems,
and some will keep one or the other exclusively.
One option to maintain both is to set up a dual boot configuration where
you actually keep two operating systems. Wubi is a program that will
automate installation, and won’t affect partitioning (sectioning off) of your
computer. If you want to explore this, go to the Wubi website at:
www.wubi-installer.org to access this program.
If you are more tech savvy you can manually create your own dual boot
install, create partitions. Another point to note is that if you have a MAC
OS, there may be other things to consider when sharing the space. The
system may need something special to help with the co-existence. The
program “rEFInd” can be installed and will help you access the particular
OS you want at start up.
The Look of Ubuntu Desktop Version
So, by now you have chosen a version you would like, and you are deciding
to use the Desktop Version of Ubuntu.

This is what the Desktop Version may look like once you have it up and
running. As you can see, the GUI provides an interface that is very familiar
to Windows and MAC users. You will see icons, task bars, tools, and see
how you could multitask by toggling the windows.
Server Version:
Again, using Ubuntu as an example for an installation, you will start by
fetching and downloading the ISO file from the website www.Ubuntu.com .
Chose the version you will need for the task (desktop, netbook, server,
cloud, etc.), and burn the one you need after you check your computer
settings. Make sure the requirements are compatible.
You will probably want to choose a larger bit if you want a server.
Download it to a disc or USB, in the live environment again, which is
preferable, and reboot off of this and not your hard drive.
It make take some time due to its large size and internet speed. Be patient. It
also won’t take up too much space. It also does not matter the age of your
system. In most cases, you can go back 5-6 years and use an old system.
Remember that the server version is bare bones, no graphics.

Ubuntu Installer Boot Menu Screen (www.pendrivelinux.com)

Follow any prompts. You will see something asking for a Name/ Hostname
and you can just call it Server, unless you feel inclined to give in a moniker.
Answer yes to any of the settings offered in the guides, with the exception
of some questions of choice when you need to provide a particular
response. Some of the questions may get too technical for a beginner. It is
recommended to stay only with what you are comfortable in doing.
When you do this reboot and go through the set up prompts, immediately
you will notice the Shell. Remember that the server edition will make it so
that you must have knowledge of commands after following the installation
the guides. A Filesystem Hierarchy Standard (FHS) will help you navigate
locations and commands for using Linux by Commands.
At the install you follow prompts to add your user name, password and
other set up features. The option for encryption would secure the files in
your home directory, but it is not suggested to do this right now until you
have more knowledge about Linux. The frequency of updates also are not
needed but you can later do periodic, manual updates will be fine. Unlike
Windows, you will not need the frequent, automatic updates.
You will also chose what type of server you would like it to be. If you aren’t
sure, you should do some Google searches. For example, what type of
server for a website, or files? Once you chose the type, it will install what
you need, and only what you need. Again, it is a pared-down version and
you will have this opportunity to choose exactly what you need, for exactly
what you chose.

Example of Ubuntu Server Edition (www.pwrusr.com )

Dual Booting Servers


There is also the option to partition the Server version as well. This
however, if usually much more complicated than with the process for the
Desktop. It is suggested that you really do some research before you decide
to partition the Server, to share space with another Operating System. It
may not be something for a beginner to delve into just yet. Then again, you
won’t be able to learn if you cannot explore.
Chapter 6 : types of installation
Debian offers a variety of methods for a proper setup. This includes a
graphical and a text-based installation; we will use the former. For
installation media the Debian developers offer three variants:

A CD or DVD for 32 bit and 64 bit


A network image for 32 bit and 64 bit (a so-called Netinst-
ISO)
A tiny CD for 32 bit or 64 bit
We also have test media available. These include live images for 32 bit and
64 bit, and allow you to try Debian before installing it on your computer.
During the time of writing this document, version 9.5 is the current stable
release of Debian. The setup described here is based on this release and the
amd64 architecture.
After downloading the network image from www.debian.org/distrib, no
further static images are required to be referenced in the system. Instead, it
depends on the internet connection to retrieve the packages to be installed
and keep your operating system up-to-date.
The entire process will take you about an hour, and it allows you to have a
lean software selection according to your specific needs. Software packages
that you do not use will not be available on your system. They can be added
whenever you feel the need for them.
The target system of our installation is an XFCE-based desktop system for a
single user with a web browser and a music player. For the web browser we
use Mozilla Firefox and for the music player, VLC. Both programs are a
permanent component of the Linux distribution. The environment we use
for demonstration purposes is a virtual machine based on VirtualBox with 4
GB of RAM and 15 GB of disc space.
Chapter 7 : exercises
As we have already learnt above, the creation of a directory is pretty easy.
In the same manner, removing or deleting a directory from the Linux
system is also very simple. One thing that you have to bear in mind,
however, once you remove or delete a directory from the Linux system,
there is no way to undo that task. Therefore, the best thing is whenever you
are running any command on Linux; the first thing is to be careful with
what you do. If it means double checking the command before running it,
the better. The command we are going to use to remove or delete a directory
is rmdir which stands for remove directory. The things that you have to take
note of here is that rmdir command supports the –p and –v options in the
same manner as mkdir command. Additionally, the directory has to be
empty before t is removed. We will learn how to get around this later.

1. rmdir linux_tutorial/beginner/commands
2. ls linux_tutorial/beginner

How to create a blank file


Many commands that are involved in data manipulation within a file have a
superb feature that they will create a file automatically when we refer to it,
and we find that it does not exist. As a matter of fact, we can manipulate
this feature to create a blank file using the touch command. In other words,
you type the command touch followed by the command line option and the
file name.

1. pwd
2. /home/Gary/linux_tutorial
3. ls
4. beginner
5. touch practice_exercise1
6. ls practice_exercise1 commands

Copying a file or a directory


Let us consider the following example:

1. user@bash: ls
2. practice_exercise1 commands
3. cp practice_exercise1 Exercise1
4. ls
5. practice_exercise1 Exercise1 commands

An important thing that we have to note in this case is the source and the
destination point at the paths. Some examples that we can consider here
include:

cp /home/Gary/linux_tutorial/Exercise1 Exercise2
cp Exercise2 ../../backups
cp Exercise2 ../../backups/Exercise3

When you use the cp command, the destination of the file can represent a
path to a file or a directory. If the destination is to a file such as Exercise1, 2
and 3, then this will create a copy of the files in the destination file, but the
original remains in the source file or directory. If we copy the files into a
directory, the files will maintain the names in the destination directory. In
the default behavior of the cp command, it will only copy a file. The term
recursive in this case means that you would wish to copy the directory and
all the contents of that very directory which could include files, directories,
and subdirectories among others.

Let us consider the following example:


1. user@bash: ls
2. Gary Practicals transfers
3. user@bash: cp Practicals Practicals_beginner
4. cp: omitting directory ‘Practicals.'
5. user@bash: cp -r Practicals Practicals_beginner
6. user@bash: ls
7. Gary Practicals transfers Practicals_beginner

Bear in mind that any files or directories that are within the Practicals
directory will be copied into the Practicals_beginner directory.
Chapter 8 : setting up Linux
As mentioned before, we will be using Debian for our demonstrations. To
recap, Debian is a distribution that provides excellent stability and scales up
exceptionally well once your skills and knowledge progress past the
beginner stages. In this section, we will highlight the process of installing
and configuring Debian, showing you every single step along the way.
Installing Linux Step-by-Step
Boot Menu
In order to begin with the installation of Debian, first, boot the computer (in
our case the VirtualBox image) from the ISO image you have downloaded.
If you are also using a virtual machine, see your virtual machine vendor
website for help on how to enable the ISO image. Next, wait for the boot
menu to appear on the screen. The image below shows you the different
options that are offered. Using the cursor keys, you can navigate the boot
menu, and the Enter key selects an entry.
The different options are:
Graphical install: start the installation process using a graphical installer
Install: starting the installation process using a text-based installer
Advanced options: select further options like Expert mode, Automated
install or Rescue mode (see image below for more details)
Help: get further help
Install with speech synthesis: starting the installation process with speech
support
From the main boot menu choose the Graphical entry install, and press the
Enter key to proceed.
Language Selection
Next, choose the language you prefer to be used during the entire
installation process. The dialogs and messages are translated accordingly.
This selection does not determine the language irrevocably your Linux
system will have; you can always choose a different language later.
The image below shows the dialog box. English is already pre-selected, and
so you just have to click the Continue button on the lower-right corner of
the dialog box in order to continue.

Location Selection
Third, make a selection regarding your location (see image below). Based
on your language setting made before, the countries are listed in which the
chosen language is mainly spoken. This also influences the locale settings
like the time zone your computer is in. In order to have a different setting
choose the entry titled other from the end of the list and go on from there.
Immediately you are over, click the Continue button to proceed with step
four.
Keyboard Selection
Fourth, choose your keyboard layout from the list (see image below). For
the United States, the pre-selection is American English. If you use a
different keyboard layout select the right one from the list. If done, click the
Continue button to proceed with step five.
Network Setup
Step five includes loading the installer components from the ISO image,
and the detection of the network hardware in order to load the correct
network driver. Then, the installer tries to connect to the internet to retrieve
an IP address via DHCP from your local network server.
When done, you can set up the hostname of your computer (see image
below). Choose a unique name for your machine that consists of a single
name and does not exist yet in your local network segment. It is common to
use names of fruits, places, musical instruments, composers and characters
from movies. In this case, we choose the name debian95 that simply
represents the Linux distribution and its number version
When you are done, press the Continue key in order to proceed with step
six to add a domain name like yourcompany.com (see image below). In this
case, it is not needed. That’s why we leave the entry field empty. Click the
Continue button on the lower-right corner to proceed with the installation.
Users and Roles
Our Linux system needs at least two users in order to be appropriately
operated. One is an administrative user that has a fixed name root and the
other is a regular user that we just give the name of User in this case.
In the next two steps, you set the password for the user root (see image
below) and both the full name and account name for the regular user. For
simplicity, we use Debian User as the full name and User as the account
name. For both users, choose a password that is dissimilar and that you can
remember. You will need these passwords later in order to log onto your
computer.
Time Zone
Setting the correct time zone is of significant importance for
communication with other services, especially in a network. Choose the
value from the list as seen in the image below. The entries in the list are
based on the location you have selected before. When done, click the
Continue button to define the storage media and the accompanying
partitions.
Storage Media and Partitioning
A Linux system can be distributed across a number of different storage
media like hard disks and flash drives. Over and above, a storage media can
be separated into multiple disk partitions. In order to do so, the setup
program of Debian has the following methods available (see image below):
Guided - use entire disk: follow the steps as provided and use the entire disk
space for the Linux installation. This creates partitions with fixed sizes.
Guided - use the entire disk and set-up LVM: follow the steps as provided
and use the entire disk space for the Linux installation. This option makes
use of Logical Volume Management (LVM) in order to create partitions
with sizes that can be changed later on.
Guided - use the entire disk and set-up encrypted LVM: follow the steps as
provided and use the entire disk space for the Linux installation. This option
makes use of Logical Volume Management (LVM) in order to create
encrypted partitions with sizes that can be changed later on.
Manual: create partitions individually. This is the expert mode and requires
more profound knowledge about partitions and file system parameters.
From the list choose the entry Guided-use the entire disk. The values for
partition sizes are chosen according to experience, implemented as an
algorithm. A manual calculation is not required. Click the Continue button
on the lower-right corner to proceed with the installation.
Next, select the disk to partition. As for our case, we have only one disk
available (see image below). Later on in this guide, the disk will be referred
to as /dev/sda for the 1st SCSI disk.
A disk partition refers to a piece of the storage media that is organized
separately and is intended to contain a branch of the Linux file system tree.
There is no universal way to do this separation correctly. This guide shows
a simple but safe solution that works for a basic system. The menu in the
dialog box offers the following options:
All files in one partition: use just a single partition to keep programs and
user data
Separate /home partition: store programs and user data in separate
partitions
Separate /home, /var, and /tmp partitions: keep user data, variable data and
temporary data in separate partitions
Click the Continue button on the lower-right corner to proceed with the
installation.
The next step is to confirm the partition scheme. This is calculated
automatically based on experience and contains these partitions:
sda1: the first partition of the first SCSI disk is a primary partition with a
size of 3 GB, formatted with the ext4 file system, and referred to as the root
part of the file system tree (indicated with /)
sda5: the fifth partition of the first SCSI disk is a logical partition with a
size of 1.3 GB, formatted with the ext4 file system, and reserved to store
variable data of the file system tree (indicated with /var)
sda6: the sixth partition of the first SCSI disk is a logical partition with a
size of 3.3 GB, formatted as a swap file system
sda7: the seventh partition of the first SCSI disk is a logical partition with a
size of 311 MB, formatted with the ext4 file system, and reserved to store
temporary data of the file system tree (indicated with /tmp)
sda8: the eighth partition of the first SCSI disk is a logical partition with a
size of 8.8 GB, formatted with the ext4 file system, and reserved to store the
user data of the file system tree aka home directories (indicated with
/home)
Due to historical reasons, a hard disk can contain four primary partitions
only. The fourth one is called an Extended Partition if divided into so-called
logical partitions or logical drives. In our case the logical partitions
/dev/sda5, /dev/sda6, /dev/sda7 and /dev/sda8 are stored on the primary
partition /dev/sda4. The partitions /dev/sda2 and /dev/sda3 are not in use.
From the above list, choose the entry Finish partitioning and write changes
to disk. Click the Continue button on the lower-right corner to proceed and
to confirm the partition scheme (see below image). Choose yes from the list
and click the Continue button to partition the disk. Note that all the data on
the selected storage device will be lost and the disk will be empty.
Having divided the storage media into single partitions, the partitions will
be formatted with the file system as defined before. In our case the
partitions /dev/sda1, /dev/sda5, /dev/sda7 and /dev/sda8 will get an ext4 file
system, and the partition /dev/sda6 will get a swap filesystem. As soon as
this step is completed, the base system of Debian will be installed next.
Package Management
The ISO image contains the installer and a number of packages to set up the
Linux base system. For example, this includes the Linux kernel being
installed below.
The next step is that you have to decide whether to use additional
installation media or not. In our case, we have just a single installation disk
and can consequentially select No from the menu (see image below). Then
click the Continue button to proceed. As pointed out earlier, the software
for Debian is organized in packages. These packages are provided in
multiple software repositories. The repositories are made available via
package mirrors that are maintained by universities, private persons,
companies and other organizations. These mirrors are located in different
countries. In the next step, you will have to decide from which country you
would like to retrieve your Debian packages. It is recommended to choose a
mirror that is geographically located near you to minimize the time that is
needed to transport the data from the mirror to your computer via a
network. As an initial step, choose your desired country. As a second step
choose a preferred mirror from the list (see image below). The list contains
universities, internet providers, government services and other
organizations. In case your computer network includes a proxy server to
communicate with the outside world, enter the according to information
here. In such an instance, we do not have that and leave the entry field
empty. Click the Confirm button to proceed. As soon as the single
parameters are set, the Debian installer connects to the previously selected
package mirror and retrieves the package lists from there. A package list
contains the packages that are available, including the name, size, and
description. Depending on the quality and bandwidth of your network
connection this step can take a while. Next, you are asked to take part in
Popcon, the Debian package popularity contest (see image below). This
information is optional and is used only by the team of developers that is
responsible for the Debian packages. Based on Popcon, they figure out
which Debian packages are the ones that are installed most often. The
information has a direct influence on the preparation of installation images
and which packages to keep or to dismiss for the different architectures.
In our case, we do not participate in Popcon, and leave the selection to No.
Click the Confirm button to proceed with the selection of software tasks
(tasksel).
Software Selection
Debian offers carefully arranged selections of packages, so-called tasks.
The idea behind them is to group packages for specific uses in order to
simplify the installation. From the list in the dialog window (see image
below) you can choose between different desktop environments, as well as
a web server, a print server, an SSH server and the standard system utilities.
To have a minimal installation just enable the last two entries from the list.
We will install the XFCE desktop environment later.
Having confirmed the software selection, the Debian installer retrieves the
needed packages from the package mirror, unpacks and then installs them.
The bar below shows the progress. In this case, 140 packages have to be
downloaded.
Setting up GRUB
In order to start our newly installed Debian system, we have to set this
information too. This process is called booting the system. The software
component that handles this step is named Grand Unified Boot Loader
(GRUB or GNU GRUB to be precise). The entry Yes is already pre-
selected, and so we can click Continue to proceed. The Debian installer
needs to know where to install GRUB. The menu in the image below lists
the storage media to be considered. In our case, we choose the second entry
from the list (/dev/sda). Then, click Continue to proceed. Now that we are
nearly finished with the basic installation, the only thing left to do is just a
single dialog box to read.
Finishing the Installation
The following dialog box informs you that the installation is complete.
Then click Continue to reboot the newly installed system.
After a few seconds, the text-based GRUB boot menu will appear on the
screen. The boot menu includes two options: Debian GNU/Linux and
Advanced options for Debian GNU/Linux. The first menu item is
highlighted and pre-selected. The second menu entry allows you to set
specific boot options. For a comprehensive list of these options have a look
at the GNU GRUB manual at www.gnu.org/software/grub/manual/grub
Keep the first menu item selected and press Enter to proceed and boot the
new system. Your Debian system will start and initialize the necessary
system services. This step will take a few seconds to be completed. Finally,
a black-and-white screen will be visible on the first text terminal named
tty1 (see image below) and ask you to log into the system. The login prompt
consists of two components: the hostname of your Linux system (debian95)
followed by space and the word login.
Debian GNU/Linux 9 debian95 tty1
debian95 login: _
Having logged into the system, you will add further software to be able to
use a graphical user interface, based on the XFCE desktop. At this step of
the installation process, adding further software can only be done by
logging in as the administrative root user.
In order to do so, type in root at the login prompt, press Enter, wait for the
text Password: to appear and type in the password set for the root user you
defined before. The Linux system will welcome you (see image below)
with a login message. The first line of the login message will give you a
display on the time of your last login followed by the version of the Linux
kernel that is currently running (line two) and the usage advice (lines five to
eight).
After the welcome message Debian opens a command-line prompt:
root@debian95 ~#
This command-line prompt consists of four components:
root: the name of the user who logged in
debian95: the hostname of the Linux system
~: the current directory. In this case, it is the home directory of the user
currently logged in. If not otherwise set, this is defined as /home/username
for regular users and /root for the administrative user. ~ is just an
abbreviation of it.
#: the login symbol. The # symbol represents the user root whereas $ is
used by regular users without administrative rights
Important: You are now logged in as the administrative root user. Take care
which commands you type in, and check twice if in doubt. Any mistakes
can lead to the necessity to install or repair your Linux system.
Adding a Graphical User Interface
At its current stage, the Debian system is fully active and can be used in
production. For a desktop system suitable for a regular user, it still lacks an
excellent and easy-to-use graphical user interface. In this step, we will
change that and install the XFCE desktop manager.
In order to do so, we will install the following packages:
The aptitude package manager
The xdm display manager
The xfce4 desktop environment
Debian uses the package manager apt to handle the installation, the update
and the removal of software packages and the related package lists. Also,
apt resolve all the package dependencies and ensures that the relevant
software is available on the system. In our case, a total of roughly 450 MB
of data/software have to be retrieved from the package mirror and installed.
As pointed out earlier, this requires a working internet connection to
download the needed software packages.
In order to install the three packages, type in the following commands at the
command-line prompt. Just type the command after the # symbol:
root@debian95 ~# apt-get install aptitude xdm xfce4
apt will display further information regarding the packages to be installed.
This includes the list of depending packages and recommended packages.
In the end, you will see a command-line prompt. Type Y or press Enter to
install aptitude, xdm and xfce4 as well as the depending packages. For the
xdm display manager, two dialog boxes have to be confirmed (see images
below). Press Enter two times to confirm the use of xdm.
The retrieval of the software packages to be installed takes a while. When
finished, the command-line prompt will appear again. In order to activate
the changes regarding the graphical desktop environment, restart the
system. Type the command reboot at the command-line prompt as follows:
root@debian95 ~# reboot
Having restarted the Linux system, Debian welcomes us with a graphical
boot screen (see image below). Press Enter to start the Linux system with
the default settings.
A few seconds later a graphical login screen will be visible (see image
below). Log in to the system with the regular user named user as created
earlier. Type in user, press Enter and type in the password for the user.
Then, press Enter again to confirm and log in.
Next, the XFCE desktop will be visible (see image below). The desktop
comes with a number of default elements: an upper navigation bar, a lower
navigation bar and desktop icons. All the mentioned elements are explained
in more detail below.
Upper navigation bar: this shows buttons to access the different
applications, the four virtual desktop screens, the clock and a button for
various user actions such as to lock the screen, change the user, change to
standby mode and exit the current session
Lower navigation bar: this bar contains several buttons to hide all the
opened windows and show the empty desktop, to open a terminal, the file
manager, a web browser, to find an application and to open the file manager
directly with your home directory.
Desktop icons: from top to bottom there is a trash bin, file manager icons
that link to the computer, and the home directory
A right-click on the desktop opens a context menu that allows you to access
the various applications
Adding Additional Software
Up until now the software available to be used on your Linux system has
been somewhat limited. After all that, the next thing to do is to add the
following four Debian packages to make your life a bit easier:
firefox-esr: the web browser Mozilla Firefox (Extended Support Release)
gnome-terminal: a terminal emulation maintained by the GNOME project
xscreensaver: a basic screensaver for the X11 system
vlc: the video player Video Lan Client (VLC)
The installation of the three packages will be done using the command-line
in a terminal emulator (we will look at terminals in detail later in the guide).
Currently, on your system, the X11 terminal emulator xterm is installed. In
order to open xterm, click on the terminal button in the lower navigation bar
or select the entry Application > System > Xterm from the context menu.
As step one, open xterm. Next, type in the command su next to the
command-line prompt as follows and press Enter:
user@debian95: ~$ su
Password:
You may remember from the previous steps that only an administrative user
can install, update or remove software on a Debian system. The su
command abbreviates switch user and changes your current role. Used
without an additional name, the role changes to the administrative root user.
At the password prompt type in the password for the administrative user
and press Enter.
As an administrative user, install the packages: firefox-esr, gnome-terminal,
xscreenserver and vlc as follows:
root@debian95: ~# apt-get install firefox-esr gnome-terminal xscreensaver
vlc
The output is seen below:
After the installation of the four packages, you can switch back to your role
as a regular user. Press Ctrl+D to quit the admin part, and press Ctrl+D
again to close xterm.
The installation of Firefox has the following effects:
The new software Firefox is available from the application menu
The new command Firefox is available from the command-line
The earth icon from the lower navigation bar links to the Firefox web
browser
The installation of the GNOME terminal package has the following effects:
The new software gnome-terminal is available from both the command-line
and the application menu
The terminal icon from the lower navigation bar links to the GNOME
terminal
The entry Open Terminal Here from the context menu refers to the
GNOME terminal
In order to see the changes, select the entry Open Terminal Here from the
context menu. The image below shows the terminal window. It comes with
a white background and a bigger font that is easier to read.
Exiting Linux
In order to use Linux properly, you also have to learn how to exit Linux and
to reboot the system. Below you will learn how to quit the XFCE desktop
environment, to shut down the Linux system and to reboot the system. We
will look at two methods; the first is based on the graphical interface and
the second can also be used on non-graphical systems like servers and
wireless routers.
Quitting the XFCE Desktop Environment
The easiest way to quit the XFCE desktop and to log out from your current
session is to click on the button in the right corner of the upper navigation
bar. The button is labeled with your username, which in our case is Debian
User. From the small menu select the last item labeled Log Out (see image
below). Alternatively, you can choose either the item labeled Log Out from
the Application button in upper-left corner or from the context menu.
A second window opens that contains the five buttons labeled Log Out,
Restart, Shutdown, Suspend and Hibernate (see image below). Click on Log
Out to quit your session. Subsequently, you will return to the login screen.
Shutting Down the Linux System
The way to shut down the entire Linux system is similar to exiting XFCE.
Click on the button in the right corner of the upper navigation bar. The
button is labeled with your username which in our case is Debian User.
From the small menu (see image above) select the item labeled Shut Down.
From the next dialog window click on the button labeled with Shut Down to
stop the Linux system.
From a terminal session you can run the commands halt or shutdown -h
now as an administrative user. A regular user is not allowed to issue these
commands.
# halt
Rebooting the Linux System
In order to restart the Linux system, click on the button in the right corner
of the upper navigation bar. The button is labeled with your username,
which in our case is Debian User. From the small menu select the item
labeled Restart (see image above). From the next dialog window click on
the button labeled Restart to reboot the Linux system.
From a terminal session, you can run the command reboot or shutdown -r
now as an administrative user. A regular user is not allowed to issue these
commands.
# reboot
Subsequently, the system will reboot and you will return to the boot screen.
Chapter 9 : navigating Linux
Now we need to talk about basic folder navigation in the Linux operating
system. This is slightly different from Microsoft Windows. However, the
funny thing is it looks close enough to Windows that when things do not
work right, people have the urge to want to pick up their computer and
throw it out the window.

Take the above diagram for example. In Linux, you also have the cd
command. Just like in Windows, the cd command stands for change
directory. If you want to go to a different directory or folder, you type in cd.
If you are in a folder, let us say you are in the var folder in our illustration,
and you want to go to a folder within the var folder, which in this case is
the abc folder, all you need to do is type in the command below:
$ cd abc
So, that is cd, a space, and then the name of the folder that you want to go
to. That will drop you in the folder that you are trying to go into. Now, the
problem is, people in the Windows world are used to following the cd
command with a forward slash symbol. If we were to apply this in our
previous command, it will look like the one below:
$ cd /abc
What Linux does in this case is it interprets the forward slash symbol as the
root folder. Linux will think that you want to change to the root folder, and
then look for the abc folder within the root folder. Of course, once Linux
executes this command, it will not be able to find an existing abc folder
since in actuality, the abc folder is located in the var folder. That is where
you have to be extremely careful.
This is one reason why a lot of Linux administrators always type in the full
path to wherever they are trying to go, no matter where they are at. If a
Linux administrator is trying to go in and change something in the abc
folder, they will just type in the command below:
$ cd /etc/var/abc
Linux is finicky about this whole change directory syntax. As we have
mentioned before as well, capitalization matters in Linux. If you are trying
to reach a folder whose name is written in all lowercase, and you type the
folder in all capital letters, Linux will not be able to find it; it will say that
the directory cannot be found.
All of this is important for you to understand. It can be extremely
frustrating if you do not grasp it.

So, the first thing you want to do when navigating files and folders in Linux
is make sure that you are in the root directory. To do this, you must type the
command below:
$ cd /
That is cd, a space, and then a forward slash. This is automatically bring
you to do the root directory if you are not already there. Now the next
logical thing to do would be to see what folders are within the root folder
itself. To do this, you must type the command below:
$ ls
The ls, or list command will list all the files and folders within a particular
directory--root, in this case.

As you can see after typing in the ls command, Linux will now show you
all the folders that are within in the root directory. You can see lots of
folders here like the bin, dev, opt, sbin, sys, var, boot, etc lib, and so forth.
Now, let’s say we want to go to inside the etc folder. All you need to do is
type in the command below:
$ cd etc
The command above will automatically drop you inside the etc folder. If
you look beside the blinking cursor of the command prompt, it will say
/etc$. That is the main indication that you are indeed inside the actual folder
that you want to go into. If you do the ls command again, it will show you
all the files within the etc folder.
In order to go back to the root folder, all you need to do is type:
$ cd /
This will automatically return you to the root directory no matter how deep
you are within the folders.
Now let’s say you want to go back to the etc folder. But this time, instead of
typing etc in all lowercase, you typed it in all uppercase.

As you can see, Linux will not be able to find the directory with an
uppercase ETC. Why? Because Linux cares about capitalization.
Uppercase letters are different from lower case letters in the Linux world.
Basically, that is all there is to it in Linux basic navigation.
Chapter 10 : essential Linux commands
In this section, we will explore the basic Linux commands that are
necessary to get started. You can now open the terminal. Right click on the
Desktop and choose ‘Open Terminal’.
If you don’t see this option, look for ‘Applications’ at the top of the
window. Click on ‘Applications’ and go to ‘Accessories’. Choose ‘Open
terminal’ and open the text editor, that is, ‘Gedit’. Just click on the search
and type “text editor”. Add some text of your choice to the file and save it,
maybe on the desktop.
Changing Directories
You might also want to navigate or change directories via the terminal. To
achieve this, use the command ‘cd’ which stands for “change directory”.
Example:

cd /home

The above command will change the working directory to the ‘/home’
directory. The use of forward slash (/) is to mean relative to the root,
meaning that this command will be executed regardless of the directory that
you are currently in. Now type the following command:

cd httpd

The directory will be changed to ‘httpd’ but relative the ‘/home’ directory.
The full working directory will be ‘/home/httpd’. Now type the following
command:

cd ..

This command will change the working directory to the parent directory of
the current directory. In our case, we will move from ‘/home/httpd’ to the
‘/home’ directory. Type the following command:
cd ~

This command changes the directory to the user’s home directory


‘/home/(username)’. The “username” will be the name you have used on
the computer. The symbol “~” is called the tilde and it is used in Linux to
represent the user’s home directory.

Copying Files

The command ‘cp,’ which stands for “copy files” is used for copying files.
Note that the file is not deleted from its initial location and a duplicate of
the same is made at the specified location. Type the following command:

cp first me

The command above will make a duplicate of the file first at the same
directory but with a new name, that is ‘me’. If the file ‘me’ exists in the
directory, it will be overwritten and you will not be warned before this
command is executed. Consider the command below:

cp –i first me

Notice that in the above command we have added the ‘–i' option. If the file
‘me’ exists in the directory, you will be notified before it is overwritten.
Next, try the following command:

cp –i /d/file

With the above command, the file ‘/d/file’ will be copied into the same
current directory and then named ‘file’. Note that we have used the ‘–i'
option so if it already exists we will be notified before it is overwritten.
You might also need to copy all the files contained in a particular directory
to another directory. This can be achieved as follows:
cp -dpr sourcedirectory destinationdirectory

All the files in the directory ‘sourcedirectory’ will be copied to the directory
‘destinationdirectory’. Notice that we have used the option ‘–dpr’. This
means the following:

-d – means that links will be preserved


-p – file attributes will be preserved
-r – copying will be done recursively

It is good to specify those options if needed while copying all the files from
a directory, otherwise, the default settings will be applied which might
produce an unwanted result.
To show the amount of space on a disk used on each of the mounted file
systems, use the command ‘df’.

‘Less’ Command

The less command is the same as the more command. The difference comes
in that with this command the user can page up or down through the file.
Consider the example below:

less first

The above command will display the contents of the file ‘first’.

‘Ln’ Command

This command creates a symbolic link to a certain file. Write and run the
following command:

ln –s first slink
The command above will create a symbolic link named ‘slink’ which will
link to the file ‘first’. The command ls ‘–i first slink’ will show that the two
files are different and have different “inodes”.

‘Locate’ Command

This is used for searching in the database. Run the following command:

slocate –u

A database named ‘slocate’ will be created. This will take some time to
complete, so be patient. Before you will be able to search for a file, this
command must be run first. However, on most systems, ‘cron’ will run this
command on periodical basis. Again, run the following command:

locate whois

This command will look for files in your system whose name contains the
string “whois”.

‘Logout’ Command

The command is used to logout the user who is currently logged into the
system. Just go to the terminal and type this command:

logout

You will then be logged out and returned to the login screen.

‘Ls’ Command

‘Ls’ stands for list. It is used for listing files in a directory. However, it
comes with many options which needs to be known as well, otherwise you
will become confused. If you need to list all the files in the current directory
with the exception of those starting with “.” then just type in the command:

ls

The figure above is the Desktop directory and it contains the files shown.
Note that only the file names will be listed. You might need to show more
details about the files in the directory such as the ownership permissions,
their size, time and date stamp, etc. This can be achieved with the following
command:

ls –al

As shown above, the command ‘ls-al’ is more extensive compared to the


previous command. You can use it if you want more details about the file.

‘More’ Command

Send contents of a file one page at a time to the screen. It can also work on
piped output. Let us list the contents of the file ‘/etc/profile’ to the screen.
This is an in-built file, meaning that it comes with the operating system and
it contains the profiles for the users of the system:

more /etc/profile
Note that the contents of the file will be displayed one page at a time. This
is because the content is too big to be displayed on a single page. Consider
the command below:

ls –al | more

The command will list all files in the directory and output will be piped
through ‘more’. If the output from the directory can’t fit in one page, it will
be listed on an additional page.

‘Mv’ Command

This command stands for “move” and is used for renaming or moving files.
Consider the command below:

mv –i first first2

The file will be moved from ‘first’ to ‘first2’, meaning it will be renamed to
‘firts2’ rather than ‘first’.
mv /d/first

The above command will move the file ‘first’ from the directory ‘/d’ to the
current working directory. Now you have seen how the ‘mv’ command is a
powerful tool.
Now that we have been talking of working directories, what are they
exactly? And how can we know in which directory they currently are? Just
type the command:

pwd

After pressing the enter key, you notice that the output is a directory. This
shows the directory which you are currently in. The abbreviation ‘pwd’
stands for “print working directory” and is used for the purpose of showing
the current working directory.

‘Shutdown’ Command

This command is used for shutting down the system. The purpose of this
command is to halt the current process and shut down the system
immediately. To do this use the following code:

shut down –h now –.

The next command is used to reboot the system, meaning that it will
immediately shut down and the restart the system. To do this use the
command below:

shut down –r now-

‘Whereis’ Command

This command is used for showing the manual, source, and binary files for
a command. Consider the command below:
whereis ls

This command will show the manual and binary files for the command ‘ls’.
To see the list of commands which have been on your system previously,
use the command ‘history’:

Above is the list of commands which have been run on my system. You can
try on your system and observe the output.

‘Sudo’ Command

This stands for “super user do”. It has the purpose of allowing a permitted
user to execute commands as a “super user”. This is usually defined in the
‘sudo’-er’s list. It has the importance of ensuring security by making sure
that sensitive commands are only executed by the correct people. Another
command, the ‘su’ command enables you to log in to the system as a super
user. The purpose of ‘sudo’ is to borrow privileges from the super user. This
explains the difference between these two commands, the ‘su’ and the
‘sudo’ commands. The ‘sudo’ command is normally used in commands
which will change the system files, such as when updating or upgrading the
OS. This shows how secure the command is compared to the ‘su’
command.

‘Mkdir’ Command

This command stands for “make directory”. It creates a new directory and
names its path. If this path is already in existence, an error saying that the
folder cannot be created will be outputted. Consider the figure shown
below:

I have made a directory named “m”. Once I list the available directories
after creating the directory, I find that it has been created. Notice that I have
run the command as ‘sudo’. Without this, the command won’t run. This is
for security purposes. Once you use the ‘sudo’ command for the first time,
you will be prompted to provide the password for the super user to do so. It
is good to note that you can only create a directory inside a folder and you
must have a “write permission” on that folder. Otherwise, you will be
unable to do so.

‘Uname’ Command

It stands for “Unix name”. With this command, you can get detailed
information about the operating system, kernel and the machine. Consider
the figure below:

Information about the OS, the kernel, and the machine have been shown.
Ubuntu- the name of the kernel of the machine
SMP- the machine’s node name
I686- processor configuration
GNU/Linux- the name of the operating system.
You can see how the command gives detailed information.

‘Touch’ Command

This command is used to create a file if and only if it does not exist. It
stands for Update the access and modification times of each file to the
current time. In case the file already exists, its timestamp will be changed
but its contents will remain the same. It is possible to use the command to
create a file in which you have a “write permission” if the file does not
exist. To create a file named ‘touchfile’:

touch touchfile

If the file does not exist in the directory, it will then be created.

‘Cal’ Command

It can be used to display the month of the current date or the month of a past
or advancing year.

Let us show the month February for the year 1900:


You can also show the month of an advancing year as shown below:

We have shown the month February of the year 2100. This command is
very good when it comes to determining the dates of future or previous
events.

‘Date’ Command

Used for displaying both the current date and time on the terminal as shown
below:

If the current date of your system is wrong, you can set it to the correct date
and time as follows:
Date –set=’21 march 2015 18:50’

In the above command, we have set both the date and the time.
Chapter 11 : instruction to linux terminals
If you change directory to /etc and then type “l”, you would see the contents
of the /etc directory. Let’s say you want to edit this newly created file. You
will use nano to edit this file. We will go into nano more later. Nano is a
Terminal application for text editing.
Open the file: nano ./file
That’s great. You can open it. But what happens when you try to write to it?
If you use CTRL O on your keyboard, which is the command to save this
file, and hit Enter, Terminal will return an error, warning that you don’t
have permission to write to this file. If you use CTRL X on your keyboard,
it will ask you if you want to save changes, and you can say no, because
you can’t. Well then, how do you edit that file?
You need to use administrator privileges in order to be able to edit a file for
which you don’t have permissions. There’re two ways to do this. The first
one is to type “sudo” before the command, which is an abbreviation for
“super user do”. It is a term in Linux that identifies your privilege level. So,
sudo allows you to make changes to files and performs administrative tasks
for this one command.
Try it: sudo nano ./file
Now you can edit the file. Try to write a line to the file: test343
Use CTRL O and hit Enter. Success. You will see a message that says you
wrote 1 line. Now you can exit and your changes will be saved.
What if you don’t want to retype the entire command?
Try it: nano ./file
If you try to write to the file, it will fail because permission is denied. You
haven’t run the specific command at sudo. You need to type “sudo !!”. The
two exclamation marks mean run the previous command.
Try it: sudo !!
Write to the file: test 343
Success!
What if you have a lot of things to do, and you don’t want to write sudo
before every single command? You could do this using the “su” command,
which means switch user. Generally, you type switch user, or “su”, followed
by the name of the user account that you want to switch use.
You can type “sudo su” and this will move you to the root account. The root
user has 100% control of everything.
Try it: sudo su
And now that you are in the root, cerate a file: nano file
Write to the file: This is a new line
Save and close the file.
When you want to switch back to your user account, type “su username”,
using your user name.
If you get a permission error when running a command, you may need to
run that command as sudo. For instance, if you’re editing files in a directory
other than your home directory, you won’t have permission to edit those
files. Later we will look at how to get permission to edit those files, but for
right now, this is when you would run your command pre-pended by sudo.
If you have a lot of these commands to run, and you don’t want to type sudo
before every command, just type “sudo su”.
Chapter 12 : becoming a Linux power user
Linux is basically divided into three main components: the kernel, the
environment, and file structure. The kernel is the main program, controlling
and managing the hardware devices like the printer. The environment gives
the user with the interface. Commands are received by the environment and
transmitted as instructions to the kernel for execution. The way files are
stored on the storage system is organized by the file structure. Files are
saved and organized in the form of directories. A directory may hold
subdirectories, each containing many files. The basic structure of Linux
operating system is formed by these three constituents. You can operate the
system by interacting and managing files. We will have a look at them
separately to form an understanding of how they work.
The operating system has many parts that make it function successfully, and
the list of important ones is mentioned below:
The Kernel
It is known to be one of the most important parts of the operating system.
No operating system can function properly without this piece. It is the core
of the operating system and controls the entire Central Processing Unit.
This part has control over the processes occurring in the OS. It is known to
be the first element that the system is loaded with, without this, you cannot
move forward to the next step. Microkernels were initially used, and they
encompassed only the CPU, memory, and IPC. Linux, on the other hand, is
a monolithic kernel. It also encompasses the device drivers, file system
management, and server system calls. Monolithic kernels are more
accessible to hardware and good at multitasking because it can directly
access information from the memory or other processes and doesn't have to
wait. The Kernel manages the remainder of the system. This part is also
responsible for running memory as well as communicating with peripherals
such as speakers and others.
The Bootloader
As the name indicates, it is the software that controls the boot procedures of
the laptop or computer. Many users would have noticed this as a splash
screen popping up and then going away to the boot in an operating system.
With Linux, you get the ability to shift between different versions of Linux
kernel or other operating systems you might have installed on your system.
A boot management utility, the Grand Unified Bootloader (GRUB) is
responsible for selecting and starting a particular operating system or
kernel. It is a versatile management tool which not only lets you load
different operating systems but also gives you the choice to choose from
different kernels installed, and all of this on a single Linux system.
The Environment
The kernel and user interact through an interface provided by an
environment. This interface acts as an interpreter. Commands which are
entered by the users are interpreted by the interface and sent to the kernel.
There are different kinds of environments, namely, desktop, window
managers, and command line shells. A user can set his or her user interface.
The environments can be altered by the users according to their special
needs, regardless of the kind of environment they opt. The operating system
works as an operating environment for the user, in this respect which can be
controlled by the user. It is known to be among one of the most creative and
interesting programs. It is a puzzle that the users interact with. This
program is also one of the most interactive pieces of the operating system.
The system has a number of desktop environments to select from according
to their preferences, such as Cinnamon, KDE, Enlightenment, XFCE, Unity,
etc. Every desktop environment has a number of built-in applications like
web browsers, games, tools, configurations and more.
The environment plays a vital part in the working of Linux. We will have a
look at two most popular environments in order to understand what they
entail.
Chapter 13 : using the shell
Effective Linux professional is unthinkable without using the command
line.
The command line is a shell prompt that indicates the system is ready to
accept a user command. This can be called a user dialogue with the system.
For each command entered, the user receives a response from the system:
1. another invitation, indicating that the command is executed and you can
enter the next.
2. error message, which is a statement of the system about events in it,
addressed to the user.
Users who are accustomed to working in systems with a graphical interface,
working with the command line may seem inconvenient. However, in
Linux, this type of interface has always been basic, and therefore well
developed. In the command shells used in Linux, there are plenty of ways to
save effort, that is, keystrokes when performing the most common actions:

automatic addition of long command names or file names


searching and re-executing a command that was once performed before
substitution of file name lists by some pattern, and much more

The advantages of the command line are especially obvious when you need
to perform similar operations on a variety of objects. In a system with a
graphical interface, you need as many mice dragging as there are objects,
one command will be enough on the command line.
This section will describe the main tools that allow you to solve any user
tasks using the command line: from trivial operations with files and
directories, for example, copying, renaming, searching, to complex tasks
requiring massive similar operations that occur as in the user's application
work, when working with large data arrays or text, and in system
administration.

Shells
A command shell or command interpreter is a program whose task is to
transfer your commands to the operating system and application programs,
and their answers to you. According to its tasks, it corresponds to
command.com in MS-DOS or cmd.exe in Windows, but functionally the
shell in Linux is incomparably richer. In the command shell language, you
can write small programs to perform a series of sequential operations with
files and the data they contain — scripts.
Having registered in the system by entering a username and password, you
will see a command line prompt – a line ending in $. Later this symbol will
be used to denote the command line. If during the installation a graphical
user interface was configured to start at system boot, then you can get to the
command line on any virtual text console. You need to press Ctrl-Alt-F1 -
Ctrl-Alt-F6 or using any terminal emulation program, for example, xterm.
The following shells are available. They may differ depending on the
distributor:
bash
The most common shell for Linux. It can complement the names of
commands and files, keeps a history of commands and provides the ability
to edit them.
pdkdh
The korn shell clone, well known on UNIX shell systems.
sash
The peculiarity of this shell is that it does not depend on any shared
libraries and includes simplified implementations of some of the most
important utilities, such as al, dd, and gzip. Therefore, the sash is especially
useful when recovering from system crashes or when upgrading the version
of the most important shared libraries.
tcsh
Improved version of C shell.
zsh
The newest of the shells listed here. It implements advanced features for
autocompletion of command arguments and many other functions that make
working with the shell even more convenient and efficient. However, note
that all zsh extensions are disabled by default, so before you start using this
command shell, you need to read its documentation and enable the features
that you need.
The default shell is bash Bourne Again Shell. To check which shell you're
using, type the command: echo $ SHELL.
Shells differ from each other, not only in capabilities but also in command
syntax. If you are a novice user, we recommend that you use bash, further
examples describe the work in this particular area.
Bash shell
The command line in bash is composed of the name of the command,
followed by keys (options), instructions that modify the behavior of the
command. Keys begin with the character – or –, and often consist of a
single letter. In addition to keys, after the command, arguments
(parameters) can follow – the names of the objects on which the command
must be executed (often the names of files and directories).
Entering a command is completed by pressing the Enter key, after which the
command is transferred to the shell for execution. As a result of the
command execution on the user’s terminal, there may appear messages
about the command execution or errors, and the appearance of the next
command line prompt (ending with the $ character) indicates that the
command has completed and you can enter the next one.
There are several techniques in bash that make it easier to type and edit the
command line. For example, using the keyboard, you can:
Ctrl-A
go to the beginning of the line. The same can be done by pressing the Home
key;
Ctrl-u
delete current line;
Ctrl-C
Abort the execution of the current command.
You can use the symbol; in order to enter several commands in one line.
bash records the history of all commands executed, so it’s easy to repeat or
edit one of the previous commands. To do this, simply select the desired
command from the history: the up key displays the previous command, the
down one and the next one. In order to find a specific command among
those already executed, without flipping through the whole story, type Ctrl-
R and enter some keyword used in the command you are looking for.

Commands that appear in history are numbered. To run a specific


command, type:

! command number
If you enter !!, the last command typed starts.
Sometimes on Linux, the names of programs and commands are too long.
Fortunately, bash itself can complete the names. By pressing the Tab key,
you can complete the name of a command, program, or directory. For
example, suppose you want to use the bunzip2 decompression program. To
do this, type:
bu
Then press Tab. If nothing happens, then there are several possible options
for completing the command. Pressing the Tab key again will give you a list
of names starting with bu. For example, the system has buildhash, builtin,
bunzip2 programs:
$ bu
buildhash builtin bunzip2
$ bu
Type n> (bunzip is the only name whose third letter is n), and then press
Tab. The shell will complete the name and it remains only to press Enter to
run the command!
Note that the program invoked from the command line is searched by bash
in directories defined in the PATH system variable. By default, this
directory listing does not include the current directory, indicated by ./ (dot
slash). Therefore, to run the prog program from the current directory, you
must issue the command ./prog.

Basic commands

The first tasks that have to be solved in any system are: working with data
(usually stored in files) and managing programs (processes) running on the
system. Below are the commands that allow you to perform the most
important operations on working with files and processes. Only the first of
these, cd, is part of the actual shell, the rest are distributed separately, but
are always available on any Linux system. All the commands below can be
run both in the text console and in graphical mode (xterm, KDE console).
For more information on each command, use the man command, for
example:
man ls
cd
Allows you to change the current directory (navigate through the file
system). It works with both absolute and relative paths. Suppose you are in
your home directory and want to go to its tmp / subdirectory. To do this,
enter the relative path:
cd tmp /
To change to the / usr / bin directory, type (absolute path):
cd / usr / bin /
Some options for using the command are:
cd ..
Allows you to make the current parent directory (note the space between cd
and ..).
cd -
Allows you to return to the previous directory. The cd command with no
parameters returns the shell to the home directory.
ls
ls (list) lists the files in the current directory. Two main options: -a - view all
files, including hidden, -l - display more detailed information.
rm
This command is used to delete files. Warning: deleting the file, you cannot
restore it! Syntax: rm filename.
This program has several parameters. The most frequently used ones are: -i
- file deletion request, -r - recursive deletion (i.e. deletion, including
subdirectories and hidden files). Example:
rm -i ~ / html / *. html
Removes all .html files in your html directory.
mkdir, rmdir
The mkdir command allows you to create a directory, while rmdir deletes a
directory, provided it is empty. Syntax:
mkdir dir_name
rmdir dir_name
The rmdir command is often replaced by the rm -rf command, which allows
you to delete directories, even if they are not empty [26].
less
less allows you to page by page. Syntax:
less filename
It is useful to review a file before editing it; The main use of this command
is the final link in a chain of programs that outputs a significant amount of
text that does not fit on one screen and otherwise flashes too quickly [27].
To exit less, press q (quit).

grep
This command allows you to find a string of characters in the file. Please
note that grep searches by a regular expression, that is, it provides the
ability to specify a template for searching a whole class of words at once. In
the language of regular expressions, it is possible to make patterns
describing, for example, the following classes of strings: “four digits in a
row, surrounded by spaces”. Obviously, such an expression can be used to
search in the text of all the years written in numbers. The search capabilities
for regular expressions are very wide. For more information, you can refer
to the on-screen documentation on grep (man grep). Syntax:
grep search_file

ps

Displays a list of current processes. The command column indicates the


process name, the PID (process identifier) is the process number (used for
operations with the process — for example, sending signals with the kill
command). Syntax:
ps arguments
Argument u gives you more information, ax allows you to view those
processes that do not belong to you.
kill
If the program stops responding or hangs, use this command to complete it.
Syntax:
kill PID_number
The PID_number here is the process identification number, You can find
out the process number for each executable program using the ps command.
Normally, the kill command sends a normal completion signal to the
process, but sometimes it does not work, and you will need to use kill -9
PID_number. In this case, the command will be immediately terminated by
the system without the possibility of saving data (abnormal). The list of
signals that the kill command can send to a process can be obtained by
issuing the command kill -l.
File and Directory Operations

Here we consider utilities that work with file system objects: files,
directories, devices, as well as file systems in general.
cp
Copies files and directories.
mv
Moves (renames) files.
rm
Removes files and directories.
df
Displays a report on the use of disk space (free space on all disks).
du
Calculates disk space occupied by files or directories.
ln
Creates links to files.
ls
Lists files in a directory, supports several different output formats.
mkdir
Creates directories.
touch
Changes file timestamps (last modified, last accessed), can be used to create
empty files.
realpath
Calculates absolute file name by relative.
basename
Removes the path from the full file name (i.e., shortens the absolute file
name to relative).
dirname
Removes the file name from the full file name (that is, it displays the full
name of the directory where the file is located).
pwd
Displays the name of the current directory.

Filters

Filters are programs that read data from standard input, convert it and
output it to standard output. Using filtering software allows you to organize
a pipeline: to perform several sequential operations on data in a single
command. More information about standard I / O redirection and the
pipeline can be found in the documentation for bash or another command
shell. Many of the commands listed in this section can work with files.
cat
combines files and displays them to standard output;
tac
combines files and displays them on standard output, starting from the end;
sort
sorts rows;
uniq
removes duplicate lines from sorted files;
tr
performs the replacement of certain characters in the standard input for
other specific characters in the standard output, can be used for
transliteration, deletion of extra characters and for more complex
substitutions;
cut
systematized data in text format can be processed using the cut utility,
which displays the specified part of each line of the file; cut allows you to
display only the specified fields (data from some columns of the table in
which the contents of the cells are separated by a standard character — a
tabulation character or any other), as well as characters standing in a certain
place in a line;
paste
combines data from several files into one table, in which the data from each
source file make up a separate column;
csplit
divides the file into parts according to the template;
expand
converts tabs to spaces;
unexpand
converts spaces to tabs;
fmt
formats the text in width;
fold
transfers too long text lines to the next line;
nl
numbers file lines;
od
displays the file in octal, hexadecimal and other similar forms;
tee
duplicates the standard output of the program in a file on disk;

Other commands
head
displays the initial part of the file of the specified size;
tail
outputs the final part of a file of a given size, since it can output data as it is
added to the end of the file, used to track log files, etc.;
echo
displays the text of the argument on the standard output;
false
does nothing, comes out with a return code of 1 (error), can be used in shell
scripts if an unsuccessful command is being attempted;
true
does nothing, comes out with a return code of 0 (successful completion),
can be used in scripts if a successful command is required;
yes
infinitely prints the same line (by default, yes) until it is interrupted.
seq
displays a series of numbers in a given range of successively increasing or
decreasing by a specified amount;
sleep
suspends execution for a specified number of seconds;
usleep
suspends execution for a specified number of milliseconds;
comm
compares 2 pre-sorted (by the sort command) files line by line, displays a
table of three columns, where in the first are lines unique to the first file, in
the second are unique to the second, in the third they are common to both
files;
join
combines lines of two files on a common field;
paste
For each pair of input lines with the same common fields, print the line to
standard output. By default, the general field is considered first, the fields
are separated by whitespace.
split
splits the file into pieces of a given size.
Calculations
In addition to simple operations with strings (input/output and merging), it
is often necessary to perform some calculations on the available data. Listed
below are utilities that perform calculations on numbers, dates, strings.
test
returns true or false depending on the value of the arguments; The test
command is useful in scripts to check conditions;
date
displays and sets the system date, in addition, it can be used for calculations
over dates;
expr
evaluates expressions;
md5sum
calculates checksum using MD5 algorithm;
sha1sum
calculates checksum using SHA1 algorithm;
wc
counts the number of lines, words, and characters in the file;
factor
decomposes numbers into prime factors;

Search

The search for information in the file system can be divided into a search by
file attributes (understanding them extensively, that is, including the name,
path, etc.) and content search. For these types of search, the programs find
and grep are usually used, respectively. Thanks to convenient interprocess
communication tools, these two types of search are easy to combine, that is,
to search for the necessary information only in files with the necessary
attributes.

Attribute search

The main search tool for file attributes is the find program. A generalized
call to find looks like this: find path expression, where path is a list of
directories in which to search, and expression is a set of expressions that
describe the criteria for selecting files and the actions to be performed on
the files found. By default, the names of found files are simply output to
standard output, but this can be overridden and the list of names of found
files can be transferred to any command for processing. By default, find
searches in all subdirectories of directories specified in the path list.

Expressions

Expressions that define file search criteria consist of key-value pairs. Some
of the possible search options are listed below:
-amin, -anewer, -atime
The time of the last access to the file. Allows you to search for files that
were opened for a certain period of time, or vice versa, for files that nobody
has accessed for a certain period.
-cmin, -cnewer, -ctime
The time the file was last changed.
-fstype
The type of file system on which the file is located.
-gid, -group
User and group that owns the file.
-name, -iname
Match the file name to the specified pattern.
-regex, -iregex
Match the file name to a regular expression.
-path, -ipath
Match the full file name (with the path) to the specified pattern.
-perm
Access rights.
-size
File size.
-type
File type.
Actions
The find program can perform various actions on the found files. The most
important of them are:
-print
Output the file name to the standard output (the default action);
-delete
delete a file;
-exec
execute the command by passing the file name as a parameter.
You can read about the rest in the on-screen documentation for the find
command, by issuing the man find command.

Options

Parameters affect the overall behavior of find. The most important of them
are:
-maxdepth
maximum search depth in subdirectories;
-mindepth
minimum search depth in subdirectories;
-xdef
Search only within the same file system.
You can read about the rest in the on-screen documentation for the find
command.

Terminals

The terminal in Linux is a program that provides the user with the ability to
communicate with the system using the command line interface. Terminals
allow you to transfer to the system and receive only text data from it. The
standard terminal for the Linux system can be obtained on any textual
virtual console, and in order to access the command line from the graphical
shell, special programs are needed: terminal emulators. Listed below are
some of the terminal emulators and similar programs included in the ALT
Linux 2.4 Master distribution.
xterm
Programs: resize, uxterm, xterm.
Standard terminal emulator for the X Window System. This emulator is
compatible with DEC VT102 / VT220 and Tektronix 4014 terminals and is
designed for programs that do not use the graphical environment directly. If
the operating system supports changing the terminal window (for example,
a SIGWINCH signal on systems that have gone from 4.3bsd), xterm can be
used to inform programs running on it that the window size has changed.
aterm
Aterm is a color emulator of the terminal rxvt version 2.4.8, supplemented
with NeXT-style scroll bars by Alfredo Kojima. It is intended to replace the
xterm if you do not need a Tektronix 4014 terminal emulation.
console-tools
This package contains tools for loading console fonts and keyboard layouts.
It also includes a variety of fonts and layouts.
In case it is installed, its tools are used during boot / login to establish the
system / personal configuration of the console.
screen
The screen utility allows you to execute console programs when you cannot
control their execution all the time (for example, if you are limited to
session access to a remote machine).
For example, you can perform multiple interactive tasks on a single
physical terminal (remote access session) by switching between virtual
terminals using a screen installed on a remote machine. Or this program can
be used to run programs that do not require direct connection to the physical
terminal.
Install the screen package if you may need virtual terminals.
vlock
The vlock program allows you to block input when working in the console.
Vlock can block the current terminal (local or remote) or the entire system
of virtual consoles, which allows you to completely block access to all
consoles. Unlocking occurs only after successful authorization of the user
who initiated the console lock.
Chapter 14 : moving around the files system
Linux’s file system is outstanding when it comes to flexibility. Its design
allows it to support regular, as well as particular types of file formats. It can
support text, programs, images, services, output, and input devices.
Therefore, since it supports a variety of file formats, it can coexist with
another OS. Moreover, in the system, there is hardly a distinguishable factor
between a file and a directory. It follows that directions are merely locations
of file stacks.
How to categorize files:
To ensure a better understanding of the Linux file system, files are
categorized. While it is considered safe to assume, knowing more
information about a particular file allows programmers and system
administrators to avoid complexities when using Linux. This also prevents
them from performing great listings.
File categories:
Directory (d) – a file that is a list of a stack of files
Link (l) – a system that allows the visibility of a particular file in multiple
parts of a file tree
Pipe (p) – a system that allows inter-process communication
Regular (-) – a normal file
Socket (s) – a special file that provides inter-process networking
Special (c) – a mechanism used for output and input
The partitioning art
Partitioning in Linux began when power failures threatened the majority of
Linux users. There were days when an outage meant severe damages to a
system.
Moreover, a primary reason for partitioning is to achieve a much higher
data security level. The hard disk’s division allows safe grouping and
protection.
Due to successful partitioning, you can prioritize data groups with more
importance. When part of a hard disk is compromised, only that part of the
disk is affected. The rest that is stored in other partitions remains
untouched.
Two significant partitions in a Linux system:
Swap – refers to extra memory or an expansion
Data – refers to normal data; refers to the necessities for starting and
running a system
Recommended partitions:

A partition for necessary data


A partition for server programs and configuration data
A partition for programs and applications
At least one partition for user mails, archives, and
database tables
At least one partition for specific files
At least one partition for virtual memory
Common partitions:

A partition that contains personal data


A partition that stores temporary files
A partition that stores third-party data
A partition that is solely for programs
Directories: (the root directory & subdirectories)
In Linux, there is a directory called The Root Directory. It serves as the
main directory and as programmers and system administrators would refer
to it, it is the directory of all directories.
With The Root Directory come the subdirectories. These subdirectories
manage files according to their assigned tasks.
Subdirectories and their content:

/home – home directory


/boot – the kernel and startup files; files that attempt to
eliminate unnecessary bootloaders
/initrd – data regarding booting information
/dev – contains references to all CPU hardware
peripherals
/bin – commonly shared system programs
/etc – essential systems configuration data
/lib – library files
/lost+found – retrieved data from failures
/opt – files from third party sources
/net – remote file systems’ standard mount point
/misc – miscellaneous data
/proc – information regarding system resources
/mnt – external file systems’ standard mount point
The role of an inode
In a Linux file system, an inode represents a file. An inode is a type of
serial number that contains essential information. Its primary role revolves
around defining the number of files in a partition.
Throughout a Linux file system, especially one with multiple partitions,
there are files with the similar inode. To avoid complications, each partition
is assigned its own inode.
Moreover, an assigned inode provides a description of a hard disk’s data
structure. Once a hard disk’s initialization is finished, it can accept data
storage during two points. One, data storage is acceptable during the
installation process. Two, data storage is acceptable upon the addition of
storage space to an existing system.
The information contained in an inode:

File type
File size
Owner or group owner of the file
Date and time of creation
Date and time of latest modification
Permissions
Number of links
Data address
Superblock
In Linux’s file system, the information about necessary file size and shape
is called The Superblock. It allows a file system manager to peruse and
maintain a file system’s quality.
Information in The Superblock:
Free blocks – displays the number of a system’s free
blocks
Free inode – shows the original inode assignment
Free inodes – displays the number of a system’s free
inodes
Block group number – refers to a number assigned to The
superblock
Blocks per group - displays a group’s number of blocks
Block size – refers to a system’s block size; information is
shown in bytes
Magic number – refers to the permission granted to
mounting software for assessment
Mount count – refers to a system’s allowance for
assessment
Revision level – refers to a system’s allowance for
revision level confirmation
All about group descriptor
A group descriptor is in charge of labeling a file’s data structure. It contains
details to avoid duplication of data. Due to its role, a system’s possibility of
corruption is minimal.
Information in a group descriptor:

Blocks bitmap
Free blocks count
Free inodes count
Inode bitmap
Inode table
Used directory count
File modification: finding, mounting & changing sizes
A Linux file is usually easy to locate. Just search for a directory and the
name that succeeds a “/” or a forward slash might be your preferred file.
Example:
/home/lp.txt
As the sample shows, “/home/” is the directory, and “lp.txt” is a file.
You can then start mounting. When mounting a file, the availability of a
Linux kernel is necessary to check the standards. Its presence allows the
validation of all of a system’s passed arguments.
Example:
# mount
iso898 /dev/rom /dev/cdrom
As the sample shows, you are mounting three kinds of information.
“iso898”, “/dev/rom,” and “/dev/cdrom.”
Apart from finding and mounting a file, you have the option to change a
file’s size. This is done due to the occurrence of a file’s fragmentation.
Since files become inefficient during fragmentation, changing a file’s size
allows the allocation of files. Consequently, a system becomes more stable.
You are introduced to the commands “truncate” and “fallocate.” Both
commands allow you to create a file with a preferred size.
Example:
# truncate -s 19MB mop1.txt
# fallocate -l 19000000 mop2.txt
# ls -ls mop.txt
0 -rw-rw--r-- 2 trs trs 19000000 Aug 12 02:44 mop1.txt
14819 -rw-rw--r-- 2 trs trs 19000000 Aug 12 02:45 mop2.txt
Chapter 15 : working with text files
The Internal field separator ‘IFS’ is used by bash to split strings into distinct
words. You can think of it as the way excel splits a comma-separated-values
(CSV) text file into spreadsheets; according to it, commas separate the
columns.
We’ll assume that IFS is set to something arbitrary, such as Z. When a
variable is expanded by bash, which contains a ‘Z’, that value’s variable
will be split into distinct words (in that case, the literal Z disappears):

The IFS variable is by default set to three characters, which include space,
tab and newline. If you echo ‘$IFS’, you will not be able to see anything
since, obviously, it wouldn’t be possible to see a space character without
any visible characters. So what is the upshot? Simple, you may see snippets
of code online in which the variable ‘IFS’ is changed to $ ‘\n’ (this stands
for ‘newline character’) or something similar.
Imagine having a text file that has a set of lines of text, which, for instance,
may refer to filenames as follows:
When each line of the file is read, the IFS’ default value (which definitely

includes a space character), causes bash to treat the file: ‘rough draft . txt’

as a double or two files which are ‘rough’ and ‘draft . txt’, this is because

splitting words uses the space character.

When IFS is set to the newline character, the ‘rough draft . txt’ becomes

treated as one filename.

As you will notice, this concept will make sense when it comes to reading

text files and operating on each and every line. It might not be possible to

understand this fully but you it is important you become aware of it, at least

just in case you’re used to copy-pasting code from the internet haphazardly.

How Bad Can Unquoted Variables Be?

In a nice, ideal world, we all would keep our string values short and devoid

of space or newlines, and any other special characters. In such a world, the

unquoted variable reference below would work perfectly:


However, when we start adding special characters to filenames, like spaces
and expanding variables without using double quotes, it can be detrimental.
In the example below, I want the file by the name ‘junk final.docx’ deleted:

Unanticipated word-splitting

Nonetheless, when referenced without double quotes, bash perceives


‘file_to_kill’ as one that has two separate values that include ‘junk’ and
‘final.docx’ below:

Unanticipated special characters

You might think, “but there’s no harm done” because those files did not
even exist in the first place. That’s fine, but what would happen if someone
placed an asterisk into a filename? You do know what happens when
someone does ‘grep *’ and ‘rm *’ don’t you? The star acts like a hungry
bear, grabbing all the files.

Given that ‘junk’ and ‘final.docx’ are nonexistent, you’ll be able to see the

previous errors. However, in between those tried deletions, ‘rm’ runs on the

asterisk. So, just say goodbye to all the files in that directory.
You do see how ‘rm “$filename” only affects the file named ‘* LOL BYE

FILES’. Therefore, the main takeaway here is always use double quotes

in your variable references as often as you can.

Here’s a little more info that you deserve…

You might be thinking ‘who in the world would place a star character in

their filename?’ For one, we do have folks who enjoy star-shaped symbols;

also, we have malicious hackers and annoying prank-stars who wouldn’t

mind using a star character. Note that variables are usually not just assigned

as a result of human typing; as you already know, at times, the result of

commands are stored in a variable. In the instance raw data is being

processed by such commands, it is possible that that kind of data does

contain special characters that can damage certain bash programs.

You always have to keep it in mind the dangers of just pasting in code that

seems safe. The syntax and behavior of bash in handling strings is quite

difficult to understand, which is why developers turn to other languages to

go about more complex applications.


Chapter 16 : managing running process
A process in Linux (as in UNIX) is a program that runs in a separate virtual
address space. When a user logs into the system, a process is automatically
created in which the shell is executed, for example, / bin / bash.
Linux supports the classic multiprogramming scheme. Linux supports
parallel (or quasi-parallel if there is only one processor) user processes.
Each process runs in its own virtual address space, i.e. processes are
protected from each other and the collapse of one process will not affect the
other running processes and the system as a whole. One process cannot read
anything from the memory (or write to it) of another process without the
"permission" of another process. Authorized interactions between processes
are allowed by the system.
The kernel provides system calls for creating new processes and for
managing generated processes. Any program can start executing only if
another process starts it or some interruption occurs (for example, an
external device interrupt).
In connection with the development of SMP (Symmetric Multiprocessor
Architectures), a mechanism of threads or control threads was introduced
into the Linux kernel. A thread is a process that runs in virtual memory,
used together with other threads of a process that has separate virtual
memory.
If the shell encounters a command corresponding to the executable file, the
interpreter executes it, starting from the entry point. For C programs, the
entry point is a function of main. A running program can also create a
process, i.e. run some program and its execution will also begin with the
function main.
Two system calls are used to create processes: fork () and exec. fork ()
creates a new address space that is completely identical to the address space
of the main process. After executing this system call, we get two identical
processes: the main and the generated ones. The fork () function returns 0 in
the spawned process, and the PID (Process ID is the spawn of the spawned
process) basically. PID is an integer.
Now that we have already created the process, we can start the program by
calling exec. The exec function parameters are the name of the executable
file and, if necessary, the parameters that will be passed to this program. A
new program will be loaded into the address space of the fork () process
and will start from the entry point (the address of the main function).
As an example, consider this fragment of the program.
if (fork () == 0) wait (0);
else execl ("ls", "ls", 0); / * spawned process * /
Now let's take a closer look at what happens when you execute a fork ()
call:
1. Memory is allocated for the new process handle in the process table.
2. Assign process ID PID.
3. A logical copy of the process is created that performs fork () – full
copying of the virtual memory contents of the parent process, copying the
components of the nuclear static and dynamic contexts of the ancestor
process.
4. Increase the file opening counters (the child process inherits all open files
of the parent process).
5. Returns the PID to the return point from the system call in the parent
process and 0 in the descendant process.

General process control scheme.

Each process can spawn a completely identical process using fork (). The
parent process can wait until all its descendant processes have completed
executing using the wait system call.
At any time, a process can change the contents of its memory image using
one of the exec call types. Each process responds to signals and, of course,
can set its own response to signals produced by the operating system. The
priority of the process can be changed using the nice system call.
A signal is a way of informing the core process of the occurrence of an
event. If several events of the same type occur, only one signal will be sent
to the process. A signal means that an event has occurred, but the kernel
does not report how many such events have occurred.
Examples of signals:
1. termination of the child process (for example, due to the exit system call
(see below))
2. the occurrence of an exceptional situation
3. signals from the user when you press certain keys

You can set the response to a signal by using the signal system call.
func = signal (snum, function);
snum is the signal number, and function is the address of the function to be
executed when the specified signal arrives. The return value is the address
of the function that will respond to a signal. Instead of function, you can
specify zero or one. If a zero was specified, then when the snum signal
arrives, the process will be interrupted similarly to the exit call. If you
specify a unit, this signal will be ignored, but it is possible
For normal completion of the process call is used.
exit (status);
where status is an integer returned by the ancestor process to inform it about
the reasons for the termination of the descendant process.
The exit call can be set at any point in the program, but it can also be
implicit, for example, when exiting the main function (when programming
in C), the operator return 0 will be interpreted as the system call exit (0);

input / output Redirection

Virtually all operating systems have an input/output redirection mechanism.


Linux is no exception to this rule. Usually, programs enter text data from
the console (terminal) and output data to the console. When you enter the
console means the keyboard, and then output, the terminal display. The
keyboard and display are standard input and output (stdin and stdout),
respectively. Any input/output can be interpreted as input from a file and
output to a file. Work with files is done through their descriptors. UNIX
uses three files for input/output: stdin (handle 1), stdout (2), and stderr (3).
The> symbol is used to redirect standard output to a file.
Example:
$ cat> newfile.txt The standard input of the cat command will be redirected
to the file newfile.txt, which will be created after the execution of this
command. If a file with this name already exists, it will be overwritten.
Pressing Ctrl + D will stop the redirect and abort the execution of the cat
command.
The <symbol is used to reassign standard command input. For example, if
you run the cat <file.txt command, the file.txt file will be used as standard
input, not the keyboard.
The >> symbol is used to append data to the end of the file (append) of the
standard command output. For example, unlike the case with the symbol>,
the execution of the command cat >> newfile.txt will not overwrite the file
if it exists but will add data to its end.
Symbol | is used to redirect the standard output of one program to the
standard input of another. For example, ps -ax | grep httpd.

Process Management Commands

Ps command
Designed to display information about running processes. This command
has many parameters that you can read about in the manual (man ps). Here I
will describe only the most frequently used commands:
✓ “a” display all processes associated with the terminal (all user
processes are displayed)
✓ “e” show all processes

✓ “t” terminal list, display terminal-related processes

✓ “u” user identifiers, display the processes associated with these


identifiers
✓ “g” group IDs, display the processes associated with these group
IDs.
✓ “x” display all non-terminal processes

Program “top”

Designed to display information about processes in real time. Processes are


sorted by maximum CPU time, but you can change the sort order (see man
top). The program also reports free system resources.
You can view information about RAM with the help of the free command,
and about the disk memory - df. Information about users registered in the
system is available using the w command.

Changing process priority useful command

nice [-reduction factor] command [argument]


The nice command executes the specified command with a lower priority,
the reduction factor is specified in the range 1..19 (by default it is equal to
10). The superuser can increase the priority of the command. For this you
need to specify a negative factor, for example - --10. If you specify a
coefficient greater than 19, then it will be considered as 19.
nohup - ignore interrupt signals
nohup command [argument]
nohup runs a command in the ignore mode. Only the SIGHUP and
SIGQUIT signals are not ignored.
kill - forced completion of the process
kill [signal number] PID
where PID is the process identifier that can be found using the ps command.

Commands for running processes in the background - jobs, fg, bg

The jobs command lists the processes that run in the background, fg - puts
the process in normal mode ("to the foreground" - foreground), and bg - in
the background. You can run the program in the background using the
<command> &
Chapter 17: becoming a Linux system
administrator
The most important thing at this level is to choose the right kind of
distribution to go for. This is not a big deal at all if you know what you
need. This should guide you:
a) What kind of computer user are you? Are you well skilled or a
beginner? Choose a Linux distribution that matches the level of
computer skills you have so that you will benefit from it. You also need
a distribution that you can learn faster and use better all the time.

b) Would you prefer a standard or modern desktop interface? This


varies from one person to another. There are a good number of people
who prefer the modern desktop interface, and there are also a good
number of computer users who go for the standard desktop interface.
It is good to take time and learn about them both, the pros and cons so
that you will choose a better interface for your needs.

c) Do you want a server or desktop distribution? This depends on


whether you want to be the system administrator, or the system is only for
your computer.
If your computer skills are just basic, it is good to stick to a beginner-
friendly distribution like Ubuntu Linux and Linux Mint or Deepin.
Computer users with above average skills could choose distributions like
Fedora or Debian. Computer gurus who have mastered the skills of
computer use and system administration can choose a distribution like
Gentoo. This is a muchadvanced kind of Linux distribution.
Users that are looking for server-only distribution will have to choose
between desktop interfaces or to decide whether they want to have it
through a command-line only.
System administrators can choose a distribution as per the kind of features
they want to go for. If you are looking for a server kind of distribution that
will offer you everything that you need from a server and out of box
features, go for centOS. If you are looking for a desktop distribution that
will allow you to add features as you need them, you can go for Ubuntu
Linux or Debian distributions.
New users could make work much easier if they compared distributions that
are fit for use by newbies only. This way, you will save time in making the
right choice and make the best choice in the end.
Chapter 18 : managing users account
See what you do on your computer most of the time. If it is surfing the
Internet, then Linux on your computer will fit better than MS Windows. On
the Internet, computers are waiting for malicious sites, which are just
waiting to get your computer and your crap out of you, exploiting various
MS Windows vulnerabilities.
In the modern Internet, in order to survive, MS Windows must be
additionally protected using firewalls and antiviruses. Read more about this
in the “Old Computer” argument.
The fact is aggravated by the fact that the first user in MS Windows by
default has unlimited administrator rights and a virus, like any other
program when it arrives at the computer, it starts up with user rights. That
is, in this case, with all-authoritative administrator rights. In modern
versions of MS Windows such as MS Windows 7, the UAC mechanism is
introduced – Control of User Accounts. It helps, but it does not solve the
problem, as it is either turned off for confirming the appearance of
confirmation windows. Or poking "Yes", without reading and expanding it,
it is not clear to whom privileges belong.
In Ubuntu Linux, the user is not "sitting" in the system by the administrator
and does not risk his security.
Many users are at great risk on the Internet in MS Windows, using Internet
Explorer (this is such a blue letter E). The fact is that the majority of pirated
MS Windows and many do not have the right to update from the site of the
manufacturer Microsoft, but also the Internet Explorer browser is not
updated either! Believe me, your old Internet Explorer browser is just
happiness for virus writers and Trojans, their heart trembles with joy when
such users visit sites that have exploits installed to introduce malware to
you. In Germany, the authorities officially recommend not using Internet
Explorer on ALL versions of MS Windows but use alternative browsers.
Installing Ubuntu Linux you will find there are such browsers as Opera,
Mozilla Firefox, Google Chrome. If you used them under MS Windows,
then absolutely the same versions of these remarkably secure browsers are
waiting for you in Ubuntu Linux.
In MS Windows, there is a software restriction on the number of
connections, so Microsoft does not allow client versions of MS Windows to
“cross” the road of MS Windows Server, for example, MS Windows XP
can “serve” only 10 user clients. This is necessary for Microsoft so that
users do not arrange servers from home computers and do not spoil
Microsoft’s business.
Read on the Internet how many people suffer with the problem, when the
torrent client is started and uses many connections, it is impossible in MS
Windows to comfortably surf the Internet in the browser, everything slows
down. People patched the MS Windows system libraries and run the risk of
the system’s performance in order to remove the software limitations on
their honestly purchased computer – some horror!
There are no restrictions in Ubuntu Linux; all 65535 TCP + 65535 UDP
ports are yours, there are simply no more ports! In Linux, a strong network
subsystem, with settings that will be hard for you to fill up on the network,
an enemy in the network under MS Windows will unload if he attacks you
with some kind of network attacks.
Chapter 1 : managing disks and file systems
As a Linux user, managing files via the terminal is very essential.
Rarely will you encounter cases where you switch from terminal to GUI control.
In this section, we are going to see how to manage files from the terminal similar
to how you would use a GUI (graphical user interface) file manager.
Launch the terminal and let us get started.
❖ pwd. This command stands for print working directory; it shows your
current working directory in the file system.
❖ cd – We use this command to navigate to the targeted directory. The
complete syntax is cd <name of target directory>. If the directory is outside
the current working directory, the path is required. If you do not specify the
target directory, it takes you to your home directory. To go back to the
previous directory since your last cd call, type cd .. or cd –
❖ ls – We use the command ls to list all the files and directories within the
current working directory. The syntax for ls command is ls <option>
[file|dir] . The table below shows some of the options for ls command.

❖ mkdir – We use this command to create new directories. To create a new


directory in your current workspace, type mkdir <dir name> For example,
mkdir newFolder. For cases where you want to create a directory outside
your current directory, you must specify a path. For example, mkdir
/user1/Desktop/Report/lastWeek where in this case, lastWeek is the name of
the directory you want created.
❖ rmdir – We use the rmdir command to remove directories. Similar to the
mkdir command, this command takes options that determine how the system
deletes files.
❖ mv and cp – We use the mv command to move and rename directories
and files. We use the cp command to copy files. The syntax for copying files
is cp <source file> <target-file> . Here is an example, mv helloDir >
/usr/share/.
Other Useful Commands
Apart from the file management commands we have discussed above, Linux
supports a wide array of commands.
In this section, we are going to look at some of the must know.
COMMAND Description
help This lists all the commands in the
terminal.
tar We use this to extract, create, and
view tar files.
find We use this command to search files
matching certain criteria in a
specified location.
gzip We use this to command extract and
create gzip archives
unzip We use the inzip command to extract
or unzip a zip archive.
whatis This command shows the use of a
certain command; it gives a short
description of a command
Man This command shows the manual of
a specified command.
exit The exit command ends the current
bash session. We can have multiple
bash sessions in one terminal.
sudo We use this command to run a
specified command as the superuser
or root user.
su In the terminal, we use this command
to switch current user to a specified
one.
top This command acts as a task manager
in terminal and shows top processes.
shutdown This command shuts down the
computer after a specified time.

NOTE: Linux Commands are case Sensitive. If you type them incorrectly, they
will not work. If you want to master Linux, Master the shell.
Chapter 20 : configuring system logging
In Linux, it is possible and easy to configure the network settings via the
command line. This includes specifying the ip address of the network, the
subnet mask and the proxy server port.
You can first check whether the network interfaces are up or down. These
network interfaces are defined in the file ‘/etc/network/interface’. You can
open it on the vim editor and view its contents. To configure a particular
interface via the command line, use the following command syntax:

ifconfig interface_name ip_address netmast sunet_mask.

If you want to configure the interface ‘eth1’, the following command can be
used:

ifconfig eth1 192.168.160.1 netmask 255.255.255.0

If you need to see all of the network connections which are currently
opened on your system, use the following command:

netstat

The routing table is used to store host machines and their ip addresses for
networking purposes. It is what determines to which host a particular data
or packet is sent. To see the contents of this table, use the command:

netstat –r
You might also realize that a particular interface is down. If you need to
bring it up, use the following command:

ifup interface_name

This will definitely bring the interface up.


To see whether your machine is connected to another device you need to
ping the other machine. If connected, the machine will send ICMP echo
packets to your machine. If not connected, these will not be sent to your
machine. Pinging the other machine can be done using its ip address as
shown below:

ping 192.168.160.2

The above command will ping the machine with the above ip address.

In my case, as shown in the figure above, the machine is unreachable since


my computer is not connected to the machine with the above ip address.
You will also notice that the process will continue to try and ping this
machine even though it’s not connected. To stop it abruptly, just press Ctrl +
C and will stop instantly. Let us see what will happen after pinging the local
machine itself:

ping 127.0.0.1
As you can see from the above figure, the local host is reachable. Again, the
process will continue to ping the machine, so, again, just press Ctrl + C and
the process will be killed. Rather than sending packets which will never
end, you can specify the number of ICMP echo packets which you need to
receive as follows:

Ping –c4 127.0.0.1

This will return only four ICMP echo packets on your standard output.
After that, the process will stop as shown below.

You will also notice that the ICMP echo packets will be shown on the
standard output as they are sent to your machine. You might not be
interested with this verbal mode. To make it silent, you can do as follows:

ping –c4 127.0.0.1 –q


As shown in the above figure, the pinging was silent rather than displaying
verbally. To make it verbalize the process when it is silent the ‘–v’ option
can be used in place of the ‘-q’ option.
Chapter 21 : learning Linux security techniques
To help you gain better security, and make sure your OS would always be in
a “healthy” state, it’s best that you take note of the commands given below:
Cross Platforms
You could also do cross-platform programming for Linux. For this, you
have to keep the following in mind:
1. windows.h and winsock.h should be used as the header files.
2. Instead of close(), closesocket() has to be used.
3. Send () and Receive() are used, instead of read() or write().
4. WSAStartup() is used to initialize the library.
Internet Message Protocol
Host Resolutions
One thing you have to keep in mind about this is that you should use the
syntax gethostname() so the standard library could make the right call.
This also happens when you’re trying to look for the name of a certain part
of the program, and when you want to use it for larger applications. It’s
almost the same as python as you could code it this way
Linux Sockets
What you have to understand about Linux is that it is an Open System
Interconnect (OSI) Internet Model which means that it works in sockets () .
In order to establish connections, you need to make use of listening sockets
so that the host could make calls—or in other words, connections.
By inputting listen (), the user will be able to accept () blocks on the
program. This binds () the program together and makes it whole. For this,
you could keep the following in mind:
Server: socket() → bind() → listen() → accept() → read() → write() →
read()
Send Request: write() → read()
Receive Reply: write() → read()
Establish connections: connect → accept()
Close Connection: close() → read()
Client: socket() → connect → write() → read() → close()
Chapter 22: understanding basic Linux security
Construct and Destruct
These are connected to the descriptor of the socket that allow peer TCP
Ports and peer IP Addresses to show up onscreen. Take note that this does
not use other languages, except for C++, unlike its contemporaries in Linux.
Destructors are then able to close any connections that you have made. For
example, if you want to log out of one of your social networking accounts,
you’re able to do it because destructors are around.
Linux and SMTP Clients
As for SMTP Client, you could expect that it involves some of the same
characters above—with just a few adjustments. You also should keep in
mind that this is all about opening the socket, opening input and output
streams, reading and writing the socket, and lastly, cleaning the client portal
up. You also have to know that it involves the following:
1. Datagram Communication. This means that local sockets would work
every time your portal sends datagrams to various clients and servers.
2. Linux Communications. This time, stream and datagram
communication are involved.
3. Programming Sockets. And of course, you can expect you’ll program
sockets in the right manner!
Echo Client Set-ups
In Linux, Echo Clients work by means of inserting arguments inside the
socket() because it means that you will be able to use the IP together with
the PF_INET function so that they could both go in the TCP socket. To set
up a proper client structure, just remember you have to make a couple of
adjustments from earlier codes.
Linux and its Sockets
You also have to understand that you can code Linux in C mainly because
they both involve the use of sockets. the socket works like a bridge that
binds the client to the port, and is also responsible for sending the right
kinds of requests to the server while waiting for it to respond. Finally,
sending and receiving of data is done.
At the same time, the Linux Socket is also able to create a socket for the
server that would then bind itself to the port. During that stage, you can
begin listening to client traffic as it builds up. You could also wait for the
client at that point, and finally, see the sending and receiving of data to
happen. Its other functions are the following:
socket_description. This allows the description of both the client and the
server will show up onscreen.
write buffer. This describes the data that needs to be sent.
write buffer length. In order to write the buffer length, you’ll have to see
the string’s output.
client_socket. The socket description will also show on top.
address. This is used for the connect function so that address_len would be
on top.
address_len . If the second parameter is null, this would appear onscreen.
return. This helps return description of both the client and the socket. This
also lets interaction become easy between the client and the server.
server_socket . This is the description of the socket that’s located on top.
backlog. This is the amount of requests that have not yet been dealt with.
You could also put personal comments every once in a while—but
definitely not all the time!
Chapter 23: understanding advanced Linux
security
Internet Protocol is all about providing boundaries in the network, as well
as relaying datagrams that allow internet-networking to happen.
The construction involves a header and a payload where the header is
known to be the main IP Address, and with interfaces that are connected
with the help of certain parameters. Routing prefixes and network
designation are also involved, together with internal or external gateway
protocols, too. Reliability also depends on end-to-end protocols, but mostly,
you could expect the framework to be this way:
UDP Header | UDP DATA → Transport
IP Header | IP Data → Internet
Frame Header | Frame Data | Frame Footer → Link
Data → Application

Getting Peer Information


In order to get peer information, you have to make sure that you return both
TCP and IP information. This way, you could be sure that both server and
client are connected to the network. You could also use the getpeername()
socket so that when information is available, it could easily be captured and
saved. This provides the right data to be sent and received by various
methods involved in Linux, and also contains proper socket descriptors and
grants privileges to others in the program. Some may even be deemed
private, to make the experience better for the users.
To accept information, let the socket TCPAcceptor::accept() be prevalent
in the network. This way, you could differentiate actions coming from the
server and the client.
Construct and Destruct
These are connected to the descriptor of the socket that allow peer TCP
Ports and peer IP Addresses to show up onscreen. Take note that this does
not use other languages, except for C++, unlike its contemporaries in Linux.
Destructors are then able to close any connections that you have made. For
example, if you want to log out of one of your social networking accounts,
you’re able to do it because destructors are around.
All Linux distros come with a robust selection of applications that you can
use for almost all of your daily computing needs. Almost all of these
applications are easily accessible using your distro’s GUI desktop.
In this chapter, you will get to know some of the most common Linux
applications and learn how to access them whenever you want to. You will
also get to know some of the file managers used by different GUIs, which
will allow you to make changes or browse files in your computer.
Almost all applications used by Linux have dedicated websites in which
you can find detailed information about them, including details on where
and how to download them. At the same time, all distros come with
different sets of utilities and apps that you can choose to install as you setup
your chosen distro.
If you have a missing app in a Debian or Debian-based distro, such as
Ubuntu, you can easily get that application as long as you have a high-
speed internet connection.
Linux and SMTP Clients
As for SMTP Client, you could expect that it involves some of the same
characters above—with just a few adjustments. You also should keep in
mind that this is all about opening the socket, opening input and output
streams, reading and writing the socket, and lastly, cleaning the client portal
up. You also have to know that it involves the following:
1. Datagram Communication. This means that local sockets would work
every time your portal sends datagrams to various clients and servers.
2. Linux Communications. This time, stream and datagram
communication are involved.
3. Programming Sockets. And of course, you can expect you’ll program
sockets in the right manner!
Echo Client Set-ups
In Linux, Echo Clients work by means of inserting arguments inside
the socket() because it means that you will be able to use the IP
together with the PF_INET function so that they could both go in
the TCP socket. To set up a proper client structure, just remember
you have to make a couple of adjustments from earlier codes.
Linux and its Sockets
You also have to understand that you can code Linux in C mainly because
they both involve the use of sockets. the socket works like a bridge that
binds the client to the port, and is also responsible for sending the right
kinds of requests to the server while waiting for it to respond. Finally,
sending and receiving of data is done.
At the same time, the Linux Socket is also able to create a socket for the
server that would then bind itself to the port. During that stage, you can
begin listening to client traffic as it builds up. You could also wait for the
client at that point, and finally, see the sending and receiving of data to
happen. Its other functions are the following:
socket_description. This allows the description of both the client and the
server will show up onscreen.
write buffer. This describes the data that needs to be sent.
write buffer length. In order to write the buffer length, you’ll have to see
the string’s output.
client_socket. The socket description will also show on top.
address. This is used for the connect function so that address_len would be
on top.
address_len . If the second parameter is null, this would appear onscreen.
return. This helps return description of both the client and the socket. This
also lets interaction become easy between the client and the server.
server_socket . This is the description of the socket that’s located on top.
backlog. This is the amount of requests that have not yet been dealt with.
You could also put personal comments every once in a while—but
definitely not all the time!
Chapter 24:enhancing Linux security with selinux
Technically speaking, Linux is not an operating system per se, as are the
distros that are based on the Linux kernel. Linux supported by the larger,
Free/Libre/Open Source Software community, a.k.a. FLOSS. This is also
essential for security enhanced Linux (SElinux). Linux kernel version 4.0
released in 2015 is important in the integration of Selinux with the access
policies. The coding has increased in length exponentially since its
development.
Before you get started with programming on Linux, you need to have a
clear idea of what your goals are. If your goal is to make money, you can
create apps that are sold for a fee. If your goal is to contribute to the
community, you need to figure out what particular niche you can help fill. If
you are running a large business, you may want to hire a small army of tech
personnel to create patches and applications that will help to better run your
business’s software. A goal is not something that a book can give you; it is
something that you have to come up with yourself. What the rest of this
book will give you is some of the basic know-how that you will need to get
started with making those goals regarding Linux attainable.
There is a permission setting that can be seen as threatening to security,
which is called setuid or suid (set user ID). This permission setting applies
to files that you can run, or executable files. When the setuid/suid
permission is allowed, a file is executed under the owner’s user ID. In short,
if the suid permission is on and the file is owned by the root user, the
targeted program will view the root user to be the one running the file and
not check on who ran the program in reality. This also means that the
permission for suid will allow the program to do more functions than what
the owner intends all the other users to perform. It also helps to take note
that if the said program that contains the suid permission has some security
vulnerabilities, criminal hackers can create more havoc through these
programs.
To find all enabled suid permissions, you can use the find command like
this:
After entering this command, you will see a list of files that appears like
this example:

Take note that there are numerous programs that are set with a suid
permission because they require it. However, you may want to check the
entire list to make sure that there are no programs that have odd suid
permissions. For example, you may not want to have suid programs located
in your home directory.
Here is an example: typing the ls –l /bin/su will give you the following
result:

The character s in the permission setting alluded to the owner (appears as –


rws) shows that the file /bin/su has suid permission. This means that the su
command, which allows any user to have superuser privileges, can be used
by anyone.
Chapter 25 : securing Linux on a Networking
Connection to the Internet is carried out using a physical channel between
your computer and the provider's server.
There are three main methods for organizing a physical connection:

wireless network;
the local network;
A modem through which PPP is exchanged.
In the first case, a wireless access point is required. Only if available is it
possible to set up a wireless network with the Internet.
The second method is used when your computer is connected to a local
network, in which there is a server for access to the World Wide Web. In
this case, you do not need to put your efforts into the organization of the
connection – the local network administrator will do all that is necessary for
you. Just launch a browser, enter the URL you are interested in, and access
it.
And the third way is a dial-up modem connection. In this case, the
administrator will not help you, so you have to do everything yourself. For
these reasons, we decided to consider this method in more detail.
First, naturally, you should have a modem and a telephone. Next, you need
to decide on the provider that provides access to the Internet and get from it
the phone number by which your PC will connect to the modem pool of the
provider and, of course, your username and password to access the global
network.
Next, you need to configure the PPP protocol. This can be done manually,
or you can use the configuration program. Manual configuration is quite
complicated and requires editing files and writing scripts. Therefore, it is
preferable for beginners to work with a special program that automates the
entire process of setting up access to the Internet.
This program is called kppp and is originally included in the KDE graphical
environment. This utility makes it much easier to set up a connection and,
in most cases, requires you to only correctly specify accounting
information.
Chapter 26 : extending Linux into the Cloud
Are you searching Linux Cloud Hosting Servers then it is the better
appropriate solution if you wish to get your web site or perhaps e-
commerce website to get more efficient and also ensure excellent overall
performance?
Linux Cloud Hosting Servers affords the clients with additional
reconfigurability and also modifications can also de bone fragments
according to their particular qualification. This hard drive server provided
for you enhances your sites overall performance plus delivers a lot more
management on the processing assets offered.
Linux server software makes use of the most recent technological know-
how that allows every person to successfully work their very own type
involving Linux and also delivering these using superior overall
performance, tougher reconfigurability and also superior supply routes.
100 % Uptime is a confirmed this means your blog will be working
successfully continuously with virtually no lagging. Regarding making
certain your blog is usually about back-up server Auto-failover function is
present.
Regarding ensuring utmost stability state-of-the-art, DDOS Safety is
provided with Linux server web hosting service. Geographically repetitive
DNS and also clientele are forwarded to 8 transit companies.
Linux Shared Web Hosting sustains the most recent and reliable web
hosting variations similar to Fedora 7, CentOS 7, Ubuntu age 14. 04 LTS
and also Debian 7. 8. The two server and also PC features involving OS are
provided towards the clients. These pre-installed hosts are instantaneously
deployed which allows clients to work with these in their particular web
hosting service offer.

Committed help workers are present that can present specialized


alternatives if you're facing any problem together with your web site. Any
common and also wide understanding bottom can be provided towards the
clientele to guide these using easy requests.
Customers are provided using personal hard drives that have identical
creating to order as being a physical server. Linux web hosting service
software allows your hosts to plug towards the web by using gigabit uplinks
involving Internap's carrier.
Newest section variations are supplied so that clients might have entire
management. Internap's
The standard VPS web hosting service is now no more some preferred
choice because the carrier's networks slice up the specific hosts for them to
easily share these relating to the clientele.
VPS companies employ container technological know-how to segregate this
numerous end user on a single discussed Linux type which usually reduces
this operation and also productivity.
Conclusion
I hope that this book has helped you learn how to use Linux confidently,
from installing it into your computer to creating your own programs using
this operating system.
I also hope that this book has served as a guide in choosing the best Linux
distribution for your needs, as well as applications that will help you
perform daily computing tasks. By the end of this book, you should have
also learned how to operate within Linux environment using the command
line and have managed to learn some steps in making your system secure.
While not as popular as Windows—at least, for some—Linux is definitely
one of the most reliable Operating Systems around—and the best part about
it is that it’s free, so you don’t really have to pay for anything just to get it,
and you also wouldn’t have to go for counterfeit types of Operating
Systems just because you could not pay for the legal copy.

You might also like