Linux 4th It
Linux 4th It
Linux
4th-IT
CIS-College
Every time you execute a search on the internet, watch a video on your phone or order something
online, that’s likely Linux at work. It epitomizes a whole that is greater than the sum of its parts, a
vast undertaking, done voluntarily, by some of the smartest people on the planet.
While your journey will be ongoing, be comforted that you are learning a set of technologies,
commands, and methods that have stood the test of time. Linux utilizes and expands upon many of
the commands and ways of accomplishing computing that UNIX began, with a rate of change per
year that’s very manageable. Now, some 30+ years on, many of those learned commands are still
active and used every day by sysadmins, dev ops, and architects. Linux is a revolution of evolution,
allowing you to learn the majority once and keep up with the small percentage of changes in a
continual learning process.
1
CIS-College
The story of Linux begins with UNIX, an operating system developed at AT&T Bell Labs in the 1970s
Linux started in 1991 as a hobby project of Linus Torvalds
2
CIS-College
3
CIS-College
BENFITS OF LUNIX
Summary:
1- Linux means the kernel of the system, which is the central controller of everything that
happens on the computer.
2- They are really referring to a group of programs called GNU/Linux,
3- GNU is the free software that provides open source equivalents to many common UNIX
commands.
4- The development of Linux closely parallels the rise of open source software.
5- The open source philosophy is that you have a right to obtain the software source code and
to modify it for your own use.
6- People that say their computer runs Linux usually refer to the kernel, tools, and suite of
applications that come bundled together in what is referred to as a distribution.
7- by learning the CLI, a user can easily be productive almost instantly on ANY distribution of
Linux
4
CIS-College
5
CIS-College
computing system
Computer users today have a choice mainly between three major operating systems: Microsoft
Windows, Apple macOS, and Linux.
6
CIS-College
Red Hat started as a simple distribution that introduced the Red Hat Package Manager (RPM). The
developer eventually formed a company around it, which tried to commercialize a Linux desktop for
business. Over time, Red Hat started to focus more on the server applications, such as web- and file-
serving and released Red Hat Enterprise Linux (RHEL), which was a paid service on a long release cycle.
SUSE
SUSE, originally derived from Slackware, was one of the first comprehensive Linux distributions, it has
many similarities to Red Hat Enterprise Linux. The original company was purchased by Novell in 2003,
which was then purchased by the Attachmate Group in 2011.
Android
Linux is a kernel, and many of the commands covered in this course are actually part of the GNU
package. That is why some people insist on using the term GNU/Linux instead of Linux alone.
Android, sponsored by Google, is the world’s most popular Linux distribution. It is fundamentally
different from its counterparts. Android uses the Dalvik virtual machine with Linux, providing a robust
platform for mobile devices such as phones and tablets.
Summary
1- An operating system is software that runs on a computing device and manages the hardware
and software components that make up a functional computing system
2- Computer users today have a choice mainly between three major operating
systems: Microsoft Windows, Apple macOS, and Linux.
3- Linux Distributions: Red hat, SUSE, Android
7
CIS-College
8
CIS-College
9
CIS-College
10
CIS-College
11
CIS-College
12
CIS-College
13
CIS-College
14
CIS-College
Each Linux desktop distribution is slightly different, but the application terminal or x-term will open
a terminal window from the GUI. While there are subtle differences between the
terms console and terminal window sessions, they are all the same from an administrator’s
standpoint and require the same knowledge of commands to use.
15
CIS-College
3.2 Applications
Applications make requests to the kernel and in return receive resources, such as memory, CPU,
and disk space. If two applications request the same resource, the kernel decides which one gets it,
and in some cases, kills off another application to save the rest of the system and prevent a crash.
The kernel also abstracts some complicated details away from the application. For example, the
application doesn’t know if a block of disk storage is on a solid-state drive, a spinning metal hard
disk, or even a network file share. Applications need only follow the kernel’s Application
Programming Interface (API) and therefore don’t have to worry about the implementation details.
The kernel also handles the switching of applications, a process known as multitasking. A computer
system has a small number of central processing units (CPUs) and a finite amount of memory. The
kernel takes care of unloading one task and loading a new one if there is more demand than
resources available.
When we, as users, think of applications, we tend to think of word processors, web browsers, and
email clients, however, there are a large variety of application types. The kernel doesn’t differentiate
between a user-facing application, a network service that talks to a remote computer, or an internal
task.
• Server Applications
Software that has no direct interaction with the monitor and keyboard of the machine it runs
on. Its purpose is to serve information to other computers, called clients. Sometimes server
applications may not talk to other computers but only sit there and crunch data.
• Desktop Applications
Web browsers, text editors, music players, or other applications with which users interact
directly. In many cases, such as a web browser, the application is talking to a server on the
other end and interpreting the data. This is the “client” side of a client/server application.
• Tools
A loose category of software that exists to make it easier to manage computer systems.
Tools can help configure displays, provide a Linux shell that users type commands into, or
even more sophisticated tools, called compilers, that convert source code to application
programs that the computer can execute.
16
CIS-College
17
CIS-College
The most well known MTA (software that is used to transfer electronic messages to other
systems) is Sendmail. Postfix is another popular one and aims to be simpler and more
secure than Sendmail.
Also called the Local Delivery Agent, it takes care of storing the email in the user’s
mailbox. Usually invoked from the final MTA in the chain.
• POP/IMAP Server
The Post Office Protocol (POP) and Internet Message Access Protocol
(IMAP) are two communication protocols that let an email client running on your computer
talk to a remote server to pick up the email.
18
CIS-College
19
CIS-College
3.2.3.1 Email
The Mozilla Foundation came out with Thunderbird, a full-featured desktop email client.
Thunderbird connects to a POP or IMAP server, displays email locally, and sends email through an
external SMTP server.
3.2.3.2 Creative
For the creative types, there is Blender, GIMP (GNU Image Manipulation Program),
and Audacity which handle 3D movie creation, 2D image manipulation, and audio editing
respectively. They have had various degrees of success in professional markets.
3.2.3.3 Productivity
Use of common open source applications in presentations and projects is one way to strengthen
Linux skills. The basic productivity applications, such as a word processor, spreadsheet, and
presentation package are valuable assets. Collectively they’re known as an office suite, primarily
due to Microsoft Office, the dominant player in the market.
LibreOffice is a fork of the OpenOffice (sometimes called OpenOffice.org) application suite.
Both offer a full office suite, including tools that strive for compatibility with Microsoft Office in both
features and file formats.
20
CIS-College
LibreOffice can also work with other file formats, such as Microsoft Office or Adobe Portable
Document Format (PDF) files. Additionally, through the use of extensions, LibreOffice can be
made to integrate with Wiki software to give you a powerful intranet solution.
21
CIS-College
3.3.1 Shells
At the basic level, users interact with a Linux system through a shell whether connecting to the
system remotely or from an attached keyboard. The shell’s job is to accept commands, like file
manipulations and starting applications, and to pass those to the Linux kernel for execution. The
Linux shell provides a rich language for iterating over files and customizing the environment, all
without leaving the shell. For example, it is possible to write a single command line that finds files
with contents matching a specific pattern, extracts useful information from the file, then copies the
new information to a new file.
Linux offers a variety of shells to choose from, mostly differing in how and what can be customized,
and the syntax of the built-in scripting language. The two main families are the Bourne shell and
the C shell. The Bourne shell was named after its creator Stephen Bourne of Bell Labs. The C shell
was so named because its syntax borrows heavily from the C language. As both these shells were
invented in the 1970s, there are more modern versions, the Bourne Again Shell (Bash) and
the tcsh (pronounced as tee-cee-shell). Bash is the default shell on most systems, though tcsh is
also typically available.
Programmers have taken favorite features from Bash and tcsh and made other shells, such as
the Korn shell (ksh) and the Z shell (zsh). The choice of shells is mostly a personal one; users
who are comfortable with Bash can operate effectively on most Linux systems. Other shells may
offer features that increase productivity in specific use cases.
22
CIS-College
23
CIS-College
Virtualization
Virtualization is one of the most significant advancements that has contributed to the enablement
cloud of computing.
Linux is a multi-user operating system, which means that many different users can work on the
same system simultaneously and for the most part can’t do things to harm other users. However,
this does have limitations – users can hog disk space or take up too much memory or CPU
resources and make the system slow for everyone. Sharing the system in multi-user mode also
requires that everyone run as unprivileged users, so letting each user run their own web server, for
example, is challenging.
Virtualization is the process where one physical computer, called the host, runs multiple copies of an
operating system, each copy called a guest. These guest images can be pre-configured for specific
functions to allow rapid deployment, often automatically, when needed. The host system runs
software called a hypervisor that switches resources between the various guests just like the Linux
kernel does for individual processes. With bare metal hypervisors, the hypervisor runs directly on
computer hardware rather than on top of an OS freeing up more resources for guest images.
like VMWare and Openbox, you can now take a powerful CPU and by using it to run multiple
virtual machines administrators can optimize usage of physical resources and dramatically reduce
costs over the previous one-machine, one-OS data center model.
Since it is possible to run multiple instances of an operating system on one physical machine and
connect to it over the network, the location of the machine doesn’t matter. Cloud computing takes
this approach and allows administrators to have virtual machines in a remote data center owned by
another company, and only pay for the resources used. Cloud computing vendors can take
advantage of scales of economy to offer computing resources at far lower prices than operating an
on-site data center.
Containers and Bare Metal Deployments
With the rise of containerization technologies like Docker and Kubernetes application software is
now being written that runs in a serverless environment. Essentially, programmers are creating
software that does one single function of a system (like database processing or storage) that runs in
a container. These containers are organized in pods that run within a node and can talk with each
other, and the outside world if needed. Nodes, in turn, are organized and controlled by a master
node that provides services to each component within the structure. Building applications in this way
decouples each of the components from the others, and from the overhead of running an OS. Since
each piece of the puzzle can be automatically destroyed and recreated by the master node they no
longer need to be as robust as software that runs on top of an OS. Although these new programming
architectures are in many ways bypassing the need for a traditional OS the underlying technology
that makes them work is still Linux. So, working in Linux will increasingly be working within a
development team that draws on the disciplines of programming, database design, networking, and
systems administration to create the systems of the future.
24
CIS-College
Summary
1- Using Linux for productivity tasks, rather than depending on Windows or Macintosh
systems.
2- Most Linux distributions allow users to download a “desktop” installation package that
can be loaded onto a USB key. This is one of the first things aspiring system
administrators should do; download a major distribution and load it onto an old PC.
3- The command line interface (CLI) is a simple text input system for entering anything from
single-word commands to complicated scripts. Most operating systems have a CLI that
provides a direct way of accessing and controlling the computer.
4- Each Linux desktop distribution is slightly different, but the application terminal or x-
term will open a terminal window from the GUI.
5- Applications make requests to the kernel and in return receive resources, such as memory,
CPU, and disk space.
6- Linux software generally falls into one of three categories:
Server Applications
Software that has no direct interaction with the monitor and keyboard of the machine it runs
on. Its purpose is to serve information to other computers, called clients. Sometimes server
applications may not talk to other computers but only sit there and crunch data.
Desktop Applications
Web browsers, text editors, music players, or other applications with which users interact
directly. In many cases, such as a web browser, the application is talking to a server on the
other end and interpreting the data. This is the “client” side of a client/server application.
Tools
A loose category of software that exists to make it easier to manage computer systems.
Tools can help configure displays, provide a Linux shell that users type commands into, or
even more sophisticated tools, called compilers, that convert source code to application
programs that the computer can execute.
25
CIS-College
The most well known MTA (software that is used to transfer electronic messages to other
systems) is Sendmail. Postfix is another popular one and aims to be simpler and more
secure than Sendmail.
Also called the Local Delivery Agent, it takes care of storing the email in the user’s
mailbox. Usually invoked from the final MTA in the chain.
• POP/IMAP Server
The Post Office Protocol (POP) and Internet Message Access Protocol
(IMAP) are two communication protocols that let an email client running on your computer
talk to a remote server to pick up the email.
8- At the basic level, users interact with a Linux system through a shell whether connecting to
the system remotely or from an attached keyboard.
9- Most Linux systems provide a choice of text editors which are commonly used at the console
to edit configuration files.
10- Linux plays a pivotal role in cloud computing. It powers 90% of the public cloud workload,
most virtual servers are based on some version of the Linux kernel
11- , Linux scales efficiently, allowing it to run anything from a tiny remote sensor to an entire
server farm.
12- The nature of Linux, built on the C programming language, also lends itself to automated
management tools.
13- Linux is a multi-user operating system
14- Docker and Kubernetes application software is now being written that runs in
a serverless environment
26
CIS-College
4.1 Introduction
Software projects take the form of source code, which is a human-readable set of computer
instructions. Since source code is not understood directly by the computer, it must be compiled into
machine instructions by a compiler. The compiler is a special program that gathers all of the source
code files and generates instructions that can be run on the computer, such as by the Linux kernel.
The development of Linux closely parallels the rise of open source software. Early on there was
shareware, freely available programs where users did not necessarily have access to the source
code. There were a lot of good things about this, but it was also problematic because malicious
programs could be disguised as innocent-looking games, screensavers, and utilities.
Soon, Linux servers and open source programs began to outperform the expensive, proprietary
systems already in place.
Open source software is a collaboration of different people with different needs and backgrounds all
working together to make something better than any one of them could have made individually.
Standards are what makes this possible, and the many organizations that create, maintain and
promote them are integral to the industry.
27
CIS-College
In most cases, the ownership of the software remains with the person or company that created it.
Users are only granted a license to use the software; this is a matter of copyright law. The money
transfer depends on the business model of the creator. It’s the licensing that differentiates open
source software from closed source software.
28
CIS-College
29
CIS-College
Summary
1- FOSS licenses are mostly related to software. People have placed works such as drawings and
plans under FOSS licenses, but this was not the intent
2- Creative Commons
An organization created to address the intentions behind FOSS licenses for non-software
entities.
3- The development of Linux closely parallels the rise of open source software
5.1 Introduction
Most consumer operating systems are designed to shield the user from the ins and outs of the CLI.
The Linux community is different in that it positively celebrates the CLI for its power, speed and
ability to accomplish a vast array of tasks with a single command line instruction.
When a user first encounters the CLI, they can find it challenging because it requires memorizing a
dizzying amount of commands and their options. However, once a user has learned the structure of
how commands are used, where the necessary files and directories are located and how to navigate
the hierarchy of a file system, they can be immensely productive. This capability provides more
precise control, greater speed and the ability to automate tasks more easily through scripting.
Furthermore, by learning the CLI, a user can easily be productive almost instantly on ANY flavor or
distribution of Linux, reducing the amount of time needed to familiarize themselves with a system
because of variations in a GUI.
30
CIS-College
31
CIS-College
5.2 Shell
Once a user has entered a command the terminal then accepts what the user has typed and passes
it to a shell. The shell is the command line interpreter that translates commands entered by a user
into actions to be performed by the operating system. If output is produced by the command, then
text is displayed in the terminal. If problems with the command are encountered, an error message is
displayed.
The Linux environment allows the use of many different shells, some of which have been around for
many years. The most commonly-used shell for Linux distributions is called the Bash shell. Bash
provides many advanced features, such as command history and inline editing, which allows a user
to easily re-execute previously executed commands or a variation of them via simple editing.
The Bash shell also has other popular features, a few of which are listed below:
• Scripting: The ability to place commands in a file and then interpret (effectively use Bash to
execute the contents of) the file, resulting in all of the commands being executed. This
feature also has some programming features, such as conditional statements and the ability
to create functions (AKA subroutines).
• Aliases: The ability to create short nicknames for longer commands.
• Variables: Used to store information for the Bash shell and for the user. These variables can
be used to modify how commands and features work as well as provide vital system
information.
Bash has an extensive feature list; this is only a sampling of its capabilities.
When a terminal application is run, and a shell appears, displaying an important part of the
interface—the prompt. Not only is the prompt there to indicate that commands can be run,
but it also conveys useful information to the user. The prompt is fully configurable and can be
as sparse or as full-featured as is practical and useful.
The structure of the prompt may vary between distributions, but typically contains information
about the user and the system. Below is a common prompt structure:
32
CIS-College
The ~ symbol is used as shorthand for the user's home directory. Typically the home directory for
the user is under the /home directory and named after the user account name; for
example, /home/sysadmin.
5.3 Commands
What is a command? The simplest answer is that a command is a software program that, when
executed on the CLI, performs an action on the computer.
To execute a command, the first step is to type the name of the command. Click in the terminal on
the right. Type ls and hit Enter. The result should resemble the example below:
sysadmin@localhost:~$ ls
Desktop Documents Downloads Music Pictures Public Templates Videos
Many commands can be used by themselves with no further input. Some commands require
additional input to run correctly. This additional input comes in two forms: options and arguments.
The typical format for a command is as follows:
Options are used to modify the core behavior of a command while arguments are used to provide
additional information (such as a filename or a username). Each option and argument is normally
separated by a space, although options can often be combined.
33
CIS-College
5.3.1 Arguments
command [options] [arguments]
An argument can be used to specify something for the command to act upon. If the ls command is
given the name of a directory as an argument, it lists the contents of that directory. In the following
example, the /etc/ppp directory is used as an argument; the resulting output is a list of files
contained in that directory:
sysadmin@localhost:~$ ls /etc/ppp
ip-down.d ip-up.d
The ls command also accepts multiple arguments. To list the contents of both
the /etc/ppp and /etc/ssh directories, pass them both as arguments:
5.3.2 Options
command [options] [arguments]
Options can be used with commands to expand or modify the way a command behaves. For
example, using the -l option of the ls command results in a long listing, providing additional
information about the files that are listed, such as the permissions, the size of the file and other
information:
sysadmin@localhost:~$ ls -l
total 0
drwxr-xr-x 1 sysadmin sysadmin 0 Jan 29 20:13 Desktop
drwxr-xr-x 1 sysadmin sysadmin 0 Jan 29 20:13 Documents
drwxr-xr-x 1 sysadmin sysadmin 0 Jan 29 20:13 Downloads
drwxr-xr-x 1 sysadmin sysadmin 0 Jan 29 20:13 Music
34
CIS-College
Note that, in the command above, -l is a lowercase letter "L". An easy way to remember this is -l is
a mnemonic (easy to memorize programming code) for long listing).
Often the character is chosen to be mnemonic for its purpose, like choosing the
letter l for long or r for reverse. By default, the ls command prints the results in alphabetical order,
and so by adding the -r option, it prints the results in reverse alphabetical order.
sysadmin@localhost:~$ ls -r
Videos Templates Public Pictures Music Downloads Documents Desktop
In most cases, options can be used in conjunction with other options. They can be given as separate
options, as in -l -r, or combined, as in -lr. The combination of these two options would result in a
long listing output in reverse alphabetical order:
sysadmin@localhost:~$ ls -lr
total 32
drwxr-xr-x 2 sysadmin sysadmin 4096 Oct 31 20:13 Videos
drwxr-xr-x 2 sysadmin sysadmin 4096 Oct 31 20:13 Templates
drwxr-xr-x 2 sysadmin sysadmin 4096 Oct 31 20:13 Public
drwxr-xr-x 2 sysadmin sysadmin 4096 Oct 31 20:13 Pictures
drwxr-xr-x 2 sysadmin sysadmin 4096 Oct 31 20:13 Music
drwxr-xr-x 2 sysadmin sysadmin 4096 Oct 31 20:13 Downloads
drwxr-xr-x 4 sysadmin sysadmin 4096 Oct 31 20:13 Documents
drwxr-xr-x 2 sysadmin sysadmin 4096 Oct 31 20:13 Desktop
The order of the combined options isn't important. The output of all of these examples would be the
same:
ls -l -r
ls -rl
ls -lr
sysadmin@localhost:~$ ls -l /usr/bin/perl
-rwxr-xr-x 2 root root 10376 Feb 4 2018 /usr/bin/perl
35
CIS-College
If the -h option is added the file sizes will be displayed in human-readable format:
Options are often single letters; however, sometimes they are words or phrases as well. Typically,
older commands use single letters while newer commands use complete words for options. Single-
letter options are preceded by a single dash - character, like the -h option. Full-word options are
preceded by two dash -- characters. The -h option also has an equivalent full-word form; the --
human-readable option.
5.3.3 History
When a command is executed in the terminal, it is stored in a history list. This is designed to make it
easy to execute the same command, later eliminating the need to retype the entire command.
Pressing the Up Arrow ↑ key displays the previous command on the prompt line. The entire history
of commands run in the current session can be displayed by pressing Up repeatedly to move back
through the history of commands that have been run. Pressing the Enter key runs the displayed
command again.
When the desired command is located, the Left Arrow ← and Right Arrow → keys can position the
cursor for editing. Other useful keys for editing include
the Home, End, Backspace and Delete keys.
To view the history list of a terminal, use the history command:
sysadmin@localhost:~$ date
Wed Dec 12 04:28:12 UTC 2018
sysadmin@localhost:~$ ls
Desktop Documents Downloads Music Pictures Public Templates Videos
sysadmin@localhost:~$ cal 5 2030
May 2030
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
36
CIS-College
sysadmin@localhost:~$ history
1 date
2 ls
3 cal 5 2030
4 history
If the desired command is in the list that the history command generates, it can be executed by
typing an exclamation point ! character and then the number next to the command, for example, to
execute the cal command again:
sysadmin@localhost:~$ history
1 date
2 ls
3 cal 5 2030
4 history
sysadmin@localhost:~$ !3
cal 5 2030
May 2030
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
If the history command is passed a number as an argument, it outputs that number of previous
commands from the history list. For example, to show the last three commands:
sysadmin@localhost:~$ history 3
6 date
7 ls /home
8 history 3
To execute the nth command from the bottom of the history list, type !-n and hit Enter. For example,
to execute the third command from the bottom of the history list execute the following:
sysadmin@localhost:~$ !-3
date
Wed Dec 12 04:31:55 UTC 2018
37
CIS-College
sysadmin@localhost:~$ date
Wed Dec 12 04:32:36 UTC 2018
sysadmin@localhost:~$ !!
date
Wed Dec 12 04:32:38 UTC 2018
To execute the most recent iteration of a specific command, type ! followed by the name of the
command and hit Enter. For example, to execute the most recent ls command:
sysadmin@localhost:~$ !ls
ls /home
sysadmin
5.4 Variables
A variable is a feature that allows the user or the shell to store data. This data can be used to
provide critical system information or to change the behavior of how the Bash shell (or other
commands) work. Variables are given names and stored temporarily in memory. There are two
types of variables used in the Bash shell: local and environment.
38
CIS-College
variable=value
The following example creates a local variable named variable1 and assigns it a value
of Something:
sysadmin@localhost:~$ variable1='Something'
The echo command is used to display output in the terminal. To display the value of the variable,
use a dollar sign $ character followed by the variable name as an argument to the echo command:
sysadmin@localhost:~$ HISTSIZE=500
sysadmin@localhost:~$ echo $HISTSIZE
500
Many variables are available for the Bash shell, as well as variables that affect different Linux
commands. A discussion of all variables is beyond the scope of this chapter; however, more shell
variables will be covered as this course progresses.
39
CIS-College
When run without arguments, the env command outputs a list of the environment variables. Because
the output of the env command can be quite long, the following examples use a text search to filter
that output.
In a previous example variable1 was created as a local variable, so the following search in the
environment variables results in no output:
The pipe | character passes the output of the env command to the grep command, which searches
the output.
This text filtering technique will be covered in detail later in the course.
The export command is used to turn a local variable into an environment variable.
export variable
After exporting variable1, it is now an environment variable. It is now found in the search through
the environment variables:
The export command can also be used to make a variable an environment variable upon its
creation by using the assignment expression as the argument:
40
CIS-College
Each directory in the list is separated by a colon : character. Based on the preceding output, the
path contains the following directories. The shell will check the directories in the order they are listed:
/home/sysadmin/bin
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
Each of these directories is represented by a path. A path is a list of directories separated by the /
character. If you think of the filesystem as a map, paths are the directory addresses, which include
step-by-step navigation directions; they can be used to indicate the location of any file within the
filesystem. For example, /home/sysadmin is a path to the home directory:
41
CIS-College
If the command is not found in any directory listed in the PATH variable, then the shell returns an
error:
sysadmin@localhost:~$ zed
-bash: zed: command not found
sysadmin@localhost:~$
If custom software is installed on the system it may be necessary to modify the PATH to make it
easier to execute these commands. For example, the following will add and verify
the /usr/bin/custom directory to the PATH variable:
sysadmin@localhost:~$ PATH=/usr/bin/custom:$PATH
sysadmin@localhost:~$ echo $PATH
/usr/bin/custom:/home/sysadmin/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/
usr/bin:/sbin:/bin:/usr/games
When updating the PATH variable, always include the current path, so as not to lose access to
commands located in those directories. This can be accomplished by appending $PATH to the value
in the assignment expression. Recall that a variable name preceded by a dollar sign represents the
value of the variable.
type command
There are several different sources of commands within the shell of your CLI including internal
commands, external commands, aliases, and functions.
42
CIS-College
sysadmin@localhost:~$ type cd
cd is a shell builtin
which command
The which command searches for the location of a command by searching the PATH variable.
sysadmin@localhost:~$ which ls
/bin/ls
sysadmin@localhost:~$ which cal
/usr/bin/cal
External commands can also be executed by typing the complete path to the command. For
example, to execute the ls command:
sysadmin@localhost:~$ /bin/ls
Desktop Documents Downloads Music Pictures Public Templates Videos
For external commands, the type command displays the location of the command:
In some cases the output of the type command may differ significantly from the output of
the which command:
43
CIS-College
Using the -a option of the type command displays all locations that contain the command named:
5.5.3 Aliases
An alias can be used to map longer commands to shorter key sequences. When the shell sees an
alias being executed, it substitutes the longer sequence before proceeding to interpret commands.
For example, the command ls -l is commonly aliased to l or ll. Because these smaller
commands are easier to type, it becomes faster to run the ls -l command line.
To determine what aliases are set on the current shell use the alias command:
sysadmin@localhost:~$ alias
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
The aliases from the previous examples were created by initialization files. These files are designed
to make the process of creating aliases automatic.
New aliases can be created using the following format, where name is the name to be given the
alias and command is the command to be executed when the alias is run.
44
CIS-College
alias name=command
For example, the cal 2019 command displays the calendar for the year 2019. Suppose you end up
running this command often. Instead of executing the full command each time, you can create an
alias called mycal and run the alias, as demonstrated in the following graphic:
Aliases created this way only persist while the shell is open. Once the shell is closed, the new
aliases are lost. Additionally, each shell has its own aliases, so aliases created in one shell won’t be
available in a new shell that’s opened.
The type command can identify aliases to other commands:
sysadmin@localhost:~$ type ll
ll is aliased to `ls -alF'
sysadmin@localhost:~$ type -a ls
ls is aliased to `ls --color=auto'
ls is /bin/ls
The output of these commands indicates that ll is an alias for ls -alF, and even ls is an alias
for ls --color=auto.
45
CIS-College
5.5.4 Functions
Functions can also be built using existing commands to either create new commands, or to override
commands built-in to the shell or commands stored in files. Aliases and functions are normally
loaded from the initialization files when the shell first starts.
Functions are more advanced than aliases and typically are used in Bash shell scripts. Typically,
functions are used to execute multiple commands. To create a function, the following syntax is used:
function_name ()
{
commands
}
In the format above, function_name can be anything that the administrator wants to call the function.
The commands that the administrator wants to execute can replace the commands placeholder.
Note the formatting, in particular, the location of the parenthesis () and braces {}, as well as the
convention of using tabs to make the function more easily readable.
Functions are useful as they allow for a set of commands to be executed one at a time instead of
typing each command repeatedly. In the example below, a function called my_report is created to
execute the ls, date, and echo commands.
sysadmin@localhost:~$ my_report () {
> ls Documents
> date
> echo "Document directory report"
> }
When creating a function, a > character will appear as a prompt to enter the commands for the
function. The curly braces {} are used to let the shell know when a function begins and ends so as
to exit the > prompt.
46
CIS-College
Once a function is created, the function name may be invoked from the BASH prompt to execute the
function:
sysadmin@localhost:~$ my_report
School alpha-third.txt hidden.txt numbers.txt spelling.txt
Work alpha.txt letters.txt os.csv words
adjectives.txt animals.txt linux.txt people.csv
alpha-first.txt food.txt longfile.txt profile.txt
alpha-second.txt hello.sh newhome.txt red.txt
Wed Oct 13 06:54:04 UTC 2021
Document directory report
sysadmin@localhost:~$
47
CIS-College
5.6 Quoting
Quotation marks are used throughout Linux administration and most computer programming
languages to let the system know that the information contained within the quotation marks should
either be ignored or treated in a way that is very different than it would normally be treated. There
are three types of quotes that have special significance to the Bash shell: double quotes ", single
quotes ', and back quotes `. Each set of quotes alerts the shell not to treat the text within the
quotes in the normal way.
Double quotes still allow for command substitution, variable substitution, and permit some
other shell metacharacters that haven't been discussed yet. The following demonstration shows that
the value of the PATH variable is still displayed:
48
CIS-College
If this sentence is placed in double quotes, $1 and $PATH are considered variables.
But what if you want to have $PATH treated as a variable and $1 not?
In this case, use a backslash \ character in front of the dollar sign $ character to prevent the shell
from interpreting it. The command below demonstrates using the \ character:
sysadmin@localhost:~$ echo The service costs \$1 and the path is $PATH
The service costs $1 and the path is /usr/bin/custom:/home/sysadmin/bin:/usr/
local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
49
CIS-College
5.6.4 Backquotes
Backquotes, or backticks, are used to specify a command within a command, a process
called command substitution. This allows for powerful and sophisticated use of commands.
While it may sound confusing, an example should make things more clear. To begin, note the output
of the date command:
sysadmin@localhost:~$ date
Mon Nov 4 03:35:50 UTC 2018
In the previous command, the word date is treated as regular text, and the shell passes date to
the echo command. To execute the date command and have the output of that command sent to
the echo command, put the date command in between two backquote characters:
50
CIS-College
5.7.1 Semicolon
command1; command2; command3
The semicolon ; character can be used to run multiple commands, one after the other. Each
command runs independently and consecutively; regardless of the result of the first command, the
second command runs once the first has completed, then the third and so on.
For example, to print the months of January, February and March of 2030, execute the following
command:
February 2030
Su Mo Tu We Th Fr Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28
March 2030
Su Mo Tu We Th Fr Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
51
CIS-College
The double ampersand && acts as a logical "and"; if the first command is successful, then the
second command will also run. If the first command fails, then the second command will not run.
To better understand how this works, consider first the concept of failure and success for
commands. Commands succeed when they work properly and fail when something goes wrong. For
example, consider the ls command. The command succeeds if the given directory is accessible and
fails if it isn't.
In the following example, the first command succeeds because the /etc/ppp directory exists and is
accessible while the second command fails because there is no /junk directory:
sysadmin@localhost:~$ ls /etc/ppp
ip-down.d ip-up.d
sysadmin@localhost:~$ ls /etc/junk
ls: cannot access /etc/junk: No such file or directory
To use the success or failure of the ls command in conjunction with && execute commands like the
following. In the first example, the echo command is executed because the ls command succeeds:
In the second example, the echo command isn't executed because the ls command fails:
52
CIS-College
The double pipe || is a logical "or". Depending on the result of the first command, the second
command will either run or be skipped.
With the double pipe, if the first command runs successfully, the second command is skipped; if the
first command fails, then the second command is run. In other words, you are essentially telling the
shell, "Either run this first command or the second one”.
In the following example, the echo command only executes if the ls command fails:
53
CIS-College
Summary
1- Bash
The most commonly used shell for Linux distributions.
2- PATH environment variable
Variable containing a list that defines which directories the shell looks in for commands.
3- echo
Command that displays output in the terminal.
4- export
Command that turns a local variable into an environment variable.
5- history
Command that outputs a list of previously executed commands.
6- type
Command that determines information about command type
7- Quotes
Quotation marks are used throughout Linux administration and most computer programming
languages to let the system know that the information contained within the quotation marks
should either be ignored or treated in a way that is very different than it would normally be
treated.
There are three types of quotes that have special significance to the Bash shell: double quotes ",
single quotes ', and back quotes `. Each set of quotes alerts the shell not to treat the text within
the quotes in the normal way.
8- Bash provides many advanced features, such as command history and inline editing, which
allows a user to easily re-execute previously executed commands or a variation of them via
simple editing.
• Scripting: The ability to place commands in a file and then interpret (effectively use Bash to
execute the contents of) the file, resulting in all of the commands being executed. This
feature also has some programming features, such as conditional statements and the ability
to create functions (AKA subroutines).
• Aliases: The ability to create short nicknames for longer commands.
• Variables: Used to store information for the Bash shell and for the user. These variables can
be used to modify how commands and features work as well as provide vital system
information.
54
CIS-College
6.1 Introduction
There are thousands of commands available with many options, making the command line a
powerful tool. However, with this power comes complexity. Complexity, in turn, can create confusion.
As a result, knowing how to find help while working in Linux is an essential skill for any user.
Referring to help provides a quick reminder of how a command works, as well as being an
information resource when learning new commands.
55
CIS-College
56
CIS-College
man command
For example, the following displays the man page for the ls command:
sysadmin@localhost:~$ man ls
NAME
ls - list directory contents
SYNOPSIS
ls [OPTION]... [FILE]...
DESCRIPTION
List information about the FILEs (the current directory by default)
.
Sort entries alphabetically if none of -cftuvSUX nor --sort is speci
-
fied.
-a, --all
do not ignore entries starting with .
57
CIS-College
Consider This
The man command uses a pager to display documents. Usually, this pager is the less command, but
on some distributions, it may be the more command. Both are very similar in how they perform.
To view the various movement commands that are available, use the H key while viewing a man
page. This displays a help page.
Pagers will be discussed in more detail later in the course.
58
CIS-College
NAME
ls - list directory contents
SYNOPSIS
Provides examples of how the command is executed.
SYNOPSIS
ls [OPTION]... [FILE]...
The SYNOPSIS section of a man page can be difficult to understand but is very important because it
provides a concise example of how to use the command. For example, consider the SYNOPSIS of
the man page for the cal command:
SYNOPSIS
cal [-31jy] [-A number] [-B number] [-d yyyy-mm] [[month] year]
The square brackets [ ] are used to indicate that this feature is not required to run the command.
For example, [-31jy] means options -3, -1, -j, or -y are available, but not required for
the cal command to function properly.
The last set of square brackets [[month] year] demonstrates another feature; it means a year
can be specified by itself, but to specify a month the year must also be specified.
Another component of the SYNOPSIS that might cause some confusion can be seen in the man
page of the date command:
SYNOPSIS
date [OPTION]... [+FORMAT]
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
In this SYNOPSIS there are two syntaxes for the date command. The first one is used to display the
date on the system while the second is used to set the date.
The ellipsis ... following [OPTION] indicates that one or more of the items before it may be used.
59
CIS-College
Additionally, the [-u|--utc|--universal] notation means that either the -u option or the --
utc option or the --universal option may be used. Typically this means that all three options really
do the same thing, but sometimes the use of the | character is used to indicate that the options can't
be used in combination, like a logical “or".
DESCRIPTION
Provides a more detailed description of the command.
DESCRIPTION
List information about the FILEs (the current directory by default)
.
Sort entries alphabetically if none of -cftuvSUX nor --sort is speci
-
fied.
OPTIONS
Lists the options for the command as well as a description of how they are used. Often this
information is found in the DESCRIPTION section and not in a separate OPTIONS section.
-a, --all
do not ignore entries starting with .
-A, --almost-all
do not list implied . and ..
--author
with -l, print the author of each file
-b, --escape
print C-style escapes for nongraphic characters
--block-size=SIZE
scale sizes by SIZE before printing them; e.g., '--block-size=M
'
prints sizes in units of 1,048,576 bytes; see SIZE format below
FILES
Lists the files that are associated with the command as well as a description of how they are used.
These files may be used to configure the command's more advanced features. Often this information
is found in the DESCRIPTION section and not in a separate FILES section.
60
CIS-College
AUTHOR
Provides the name of the person who created the man page and (sometimes) how to contact the
person.
AUTHOR
Written by Richard M. Stallman and David MacKenzie.
REPORTING BUGS
Provides details on how to report problems with the command.
REPORTING BUGS
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Report ls translation bugs to <http://translationproject.org/team/>
COPYRIGHT
Provides basic copyright information.
COPYRIGHT
Copyright (C) 2017 Free Software Foundation, Inc. License GPLv3+: GN
U
GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it
.
There is NO WARRANTY, to the extent permitted by law.
SEE ALSO
Provides you with an idea of where you can find additional information. This often includes other
commands that are related to this command.
SEE ALSO
Full documentation at: <http://www.gnu.org/software/coreutils/ls>
or available locally via: info '(coreutils) ls invocation'
61
CIS-College
62
CIS-College
1. General Commands
2. System Calls
3. Library Calls
4. Special Files
5. File Formats and Conventions
6. Games
7. Miscellaneous
8. System Administration Commands
9. Kernel Routines
The man command searches each of these sections in order until it finds the first match. For
example, if you execute the command man cal, the first section (General Commands) is searched
for a man page called cal. If not found, then the second section is searched. If no man page is
found after searching all sections, an error message is returned:
To determine which section a specific man page belongs to, look at the numeric value on the first
line of the output of the man page. For example, the cal command belongs to the first section of
man pages:
Sometimes there are man pages with the same name in different sections. In these cases, it may be
necessary to specify the section of the correct man page.
For example, there is a command called passwd that allows you to change your password. There is
also a file called passwd that stores account information. Both the command and the file have a man
page.
The passwd command is a user command, so the associated man page is in the first section.
The man command displays the man page for the passwd command by default:
So how do you display the man page for the passwd file? First, determine in which section the man
page is located. To search for man pages by name, use the -f option to the man command. It
63
CIS-College
displays man pages that match, or partially match, a specific name and provide the section number
and a brief description of each man page:
Note: On most Linux distributions, the whatis command does the same thing as man -f. On those
distributions, both will produce the same output.
To specify a different section, provide the number of the section as the first argument of the man
command. The following command displays the passwd man page located in section 5, which is
associated with the passwd file:
Unfortunately, you won't always remember the exact name of the man page that you want to view.
Fortunately, each man page has a short description associated with it. The -k option to
the man command searches both the names and descriptions of the man pages for a keyword.
For example, to find a man page that displays how to copy directories, search for the keyword copy:
Recall that there are thousands of man pages, so when searching for a keyword, be as specific as
possible. Using a generic word, such as "the", could result in hundreds or even thousands of results.
Note: On most Linux distributions, the apropos command does the same thing as man -k. On those
distributions, both produce the same output.
64
CIS-College
sysadmin@localhost:~$ whatis ls
ls (1) - list directory contents
ls (lp) - list directory contents
Note
The example above is designed to demonstrate a scenario where two commands list directory
contents. The output in the example terminal above may not match the output in the VM.
Based on this output, there are two ls commands that list directory contents. The simple reason for
this is that UNIX had two main variants, which resulted in some commands being developed "in
parallel" and therefore behaving differently on different variants of UNIX. Many modern distributions
of Linux include commands from both UNIX variants.
This does, however, pose a bit of a problem: when the ls command is typed, which command is
executed?
sysadmin@localhost:~$ whereis ls
ls: /bin/ls /usr/share/man/man1p/ls.1.gz /usr/share/man/man1/ls.1.gz
Man pages are easily distinguished from commands as they are typically compressed with a
program called gzip, resulting in a filename that ends in .gz. Notice there are two man pages listed
above, but only one command: /bin/ls. This is because the ls command can be used with the
options/features that are described by either man page. So, when learning what can be done with
the ls command, it may be interesting to explore both man pages. Fortunately, this is more of an
exception as most commands only have one man page.
65
CIS-College
Any files created today will not be searchable with the locate command. If root access is available,
it’s possible to update the locate database manually by running the updatedb command. Regular
users cannot update the database file.
Also note that when using the locate command as a regular user, the output may be limited due to
file permissions. If the user that is logged in doesn’t have access to a file or directory on the
filesystem due to permissions, the locate command won't return those names. This security feature
is designed to keep users from "exploring" the filesystem by using the locate database.
The root user can search for any file in the locate database.
The output of the locate command can be quite large. When searching for a filename, such
as passwd, the locate command produces every file that contains the string passwd, not just files
named passwd.
In many cases, it is helpful to start by finding out how many files match. Do this by using the -
c option to the locate command:
66
CIS-College
To limit the output produced by the locate command use the -b option. This option only includes
listings that have the search term in the basename of the filename. The basename is the portion of
the filename not including the directory names.
As you can see from the previous output, there will still be many results when the -b option is used.
To limit the output even further, place a \ character in front of the search term. This character limits
the output to filenames that exactly match the term:
67
CIS-College
info command
sysadmin@localhost:~$ info ls
The `ls' program lists information about files (of any type, including di
rectories). Options and file arguments can be intermixed arbitrarily, as usu
al.
68
CIS-College
This documentation is broken up into nodes, and in the example above the line highlighted in white
shows it’s currently in the ls invocation node. The first line provides index information about the
current location within the document. The next node, like the next chapter in a book, would be
the dir invocation node. Going up one level is the Directory listing node.
Scrolling through the document, notice the menu for the ls command:
* Menu:
The items under the menu are hyperlinks that link to nodes that describe more about
the ls command. For example, placing the cursor on the line * Sorting the output:: and
pressing the Enter key, leads to a node that describes sorting the output of the ls command:
Next: Details about version sort, Prev: What information is listed, Up: ls
in\
vocation
These options change the order in which 'ls' sorts the information it
69
CIS-College
'-c'
'--time=ctime'
'--time=status'
If the long listing format (e.g., '-l', '-o') is being used, print
the status change timestamp (the ctime) instead of the mtime. When
explicitly sorting by time ('--sort=time' or '-t') or when not
using a long listing format, sort according to the ctime. *Note
File timestamps::.
'-f'
Primarily, like '-U'--do not sort; list the files in whatever order
they are stored in the directory. But also enable '-a' (list all
-----Info: (coreutils)Sorting the output, 69 lines --Top---------------------
---
Note that going into the node about sorting leads into a sub-node of the original. To go back to the
previous node, use the U key. While U leads to the start of the node one level up, the L key returns
to the same location as before entering the sorting node.
70
CIS-College
Note that to close the help screen type the L key, which brings back the current document. To quit
entirely, use the Q key.
71
CIS-College
File: dir, Node: Top, This is the top of the INFO tree.
'q' quits;
'H' lists all Info commands;
'h' starts the Info tutorial;
'mTexinfo RET' visits the Texinfo manual, etc.
* Menu:
Basics
* Common options: (coreutils)Common options.
* Coreutils: (coreutils). Core GNU (file, text, shell) utilities.
* Date input formats: (coreutils)Date input formats.
* File permissions: (coreutils)File permissions.
Access modes.
* Finding files: (find). Operating on files matching certain criteria.
C++ libraries
* autosprintf: (autosprintf). Support for printf format strings in C++.
-----Info: (dir)Top, 211 lines --Top-----------------------------------------
---
Welcome to Info version 6.5. Type H for help, h for tutorial.
72
CIS-College
73
CIS-College
Examples:
cat f - g Output f's contents, then standard input, then g's contents.
cat Copy standard input to standard output.
74
CIS-College
Summary
1- /usr/share/doc/
Directory containing additional documentation files, such as readme files and support for
third-party software.
2- info
Command used to view info documentation for commands.
3- locate
Command used to find any file or directory. Relies on a database typically generated nightly.
4- man
Command used to view manual (man) pages for commands.
75
CIS-College
Exercises:
1- define ip address (192.168.10.0/25) a Var Y
------------------
python3
import ipaddress
1- y = ipaddress.ip_network('192.168.10.0/25')
2- print(y.netmask)
3- print(y.num_addresses)
4- for i in y:
print(i , y.netmask)
--------------------------------------------------------------------------------------------------\
76
CIS-College
-----------------------------------------------------------------------------------------------------
nano
read ip
openssl version
nano msg
cat msg
77
CIS-College
cat msg
cat enc
===================================
nano
cat g
openssl enc -aes-256-cbc -base64 -in g -out g1
cat g1
78
CIS-College
79
CIS-College
80
CIS-College
Contents
Chapter1: introduction to Linux. ........................................................................................................... 0
1.1 Linux is Everywhere ........................................................................................................................ 1
1.2 Linux is a Kernel .............................................................................................................................. 2
1.3 Linux is Open Source ...................................................................................................................... 3
1.4 Linux Has Distributions ................................................................................................................... 3
1.5 Linux Embraces the CLI ................................................................................................................. 3
1.1 Linux is Everywhere ................................................................................................................... 4
1.2 Linux is a Kernel ......................................................................................................................... 4
1.3 Linux is Open Source ................................................................................................................ 4
1.4 Linux Has Distributions .............................................................................................................. 4
1.5 Linux Embraces the CLI ............................................................................................................ 4
2.1 Operating Systems .......................................................................................................................... 5
2.2 Linux Distributions ........................................................................................................................... 7
Chapter 3 - Working in Linux .............................................................................................................. 14
3.1 Navigating the Linux Desktop ...................................................................................................... 14
3.1.1 Getting to the Command Line .................................................................................................. 15
3.2 Applications .................................................................................................................................... 16
3.2.1 Major Applications ...................................................................................................................... 16
3.2.2 Server Applications .................................................................................................................... 17
3.2.2.1 Web Servers ............................................................................................................................ 17
3.2.2.2 Private Cloud Servers ............................................................................................................ 17
3.2.2.3 Database Servers ................................................................................................................... 18
3.2.2.4 Email Servers .......................................................................................................................... 18
3.2.2.5 File Sharing .............................................................................................................................. 19
3.2.3 Desktop Applications ................................................................................................................. 20
3.2.3.1 Email ......................................................................................................................................... 20
3.2.3.2 Creative .................................................................................................................................... 20
3.2.3.3 Productivity............................................................................................................................... 20
3.2.3.4 Web Browsers ......................................................................................................................... 21
3.3 Console Tools ................................................................................................................................ 22
3.3.1 Shells............................................................................................................................................ 22
3.3.2 Text Editors ................................................................................................................................. 22
81
CIS-College
82
CIS-College
83