Ug Oss U2
Ug Oss U2
Kernel Mode: The kernel is the core program on which all the other operating system
components rely, it is used to access the hardware components and schedule which processes
should run on a computer system and when, and it also manages the application software and
hardware interaction. Hence it is the most privileged program, unlike other programs, it can
directly interact with the hardware. When programs running under user mode need hardware
access for example webcam, then first it has to go through the kernel by using a syscall, and to
carry out these requests the CPU switches from user mode to kernel mode at the time of
execution. After finally completing the execution of the process the CPU again switches back to
the user mode.
Vi Editor
The default editor that comes with the UNIX operating system is called vi (visual editor).
Using vi editor, we can edit an existing file or create a new file from scratch. we can also use this
editor to just read a text file. The advanced version of the vi editor is the vim editor.
The vi editor has two modes:
Command Mode: In command mode, actions are taken on the file. The vi editor starts in
command mode. Here, the typed words will act as commands in vi editor. To pass a
command, you need to be in command mode.
Insert Mode: In insert mode, entered text will be inserted into the file. The Esc key will
take you to the command mode from insert mode.
By default, the vi editor starts in command mode. To enter text, you have to be in insert mode,
just type 'i' and you'll be in insert mode. Although, after typing i nothing will appear on the
screen but you'll be in insert mode. Now you can type anything.
To exit from insert mode press Esc key, you'll be directed to command mode.
If you are not sure which mode you are in, press Esc key twice and you'll be in command mode.
Using vi
The vi editor tool is an interactive tool as it displays changes made in the file on the screen
while you edit the file.
In vi editor you can insert, edit or remove a word as cursor moves throughout the file.
Commands are specified for each function like to delete it's x or dd.
The vi editor is case-sensitive. For example, p allows you to paste after the current line
while P allows you to paste before the current line.
vi syntax:
vi <fileName>
In the terminal when you'll type vi command with a file name, the terminal will get clear
and content of the file will be displayed. If there is no such file, then a new file will be created and
once completed file will be saved with the mentioned file name.
Linux vi example
Let's understand vi through an example:
To start vi open your terminal and type vi command followed by file name. If your file is in some
other directory, you can specify the file path. And if in case, your file doesn't exist, it will create a
new file with the specified name at the given location.
Example:
vi /home/sssit/Downloads/file.txt
Look at the above snapshot, we are creating a new file file.txt (as this file doesn't exist) and have
entered the full path for the directory Downloads.
Command mode
This is what you'll see when you'll press enter after the above command. If you'll start typing,
nothing will appear as you are in command mode. By default vi opens in command mode.
Look at the above snapshot, it is blank as it is a new file. To start typing, you have to move to the
insert mode. At the end of the terminal window, directory name and file name are displayed.
Insert mode
To move to the insert mode press i. Although, there are other commands also to move to insert
mode which we'll study in next page.
Look at the above snapshot, after pressing i we have entered into insert mode. Now we can write
anything. To move to the next line press enter.
Once you have done with your typing, press esc key to return to the command mode.
To exit from vi, first ensure that you are in command mode. Now, type :wq and press enter. It will
save and quit vi.
Look at the above snapshot, command :wq will save and quit the vi editor. When you'll type it in
command mode, it will automatically come at bottom left corner.
If you want to quit without saving the file, use :q. This command will only work when you have
not made any changes in the file.
Look at the above snapshot, this file is modified and hence on typing :q it displays this message
at bottom left corner.
The above file can be saved with the command :!q. It discards the changes made in the file and
save it.
Look at the above snapshot, we have typed :!q, it will save our file by discarding the changes
made.
Vi Commands
Linux vi editor is different from other editors. You have to use different keys to use different
functions. Although, it's quite easy and interesting to use vi editor.
The vi editor commands are case sensitive.
Have a look at the vi commands in the following table.
Partitions Creation
Disk Partitioning is the process of dividing a disk into one or more logical areas, often
known as partitions, on which the user can work separately. It is one step of disk formatting. If a
partition is created, the disk will store the information about the location and size of partitions in
the partition table. With the partition table, each partition can appear to the operating system as
a logical disk, and users can read and write data on those disks. The main advantage of disk
partitioning is that each partition can be managed separately.
Attaching Disk:
This step points to physically connecting the disk to the system. The below screenshot specifies
the system configuration of my CentOS 7.
It is clearly specified that the system has only 20 GB of Hard Disk. After installing the necessary
software and downloading some movies, I found that the system Hard Disk is almost completely
used up. Now I will have two options in front of me, either buy a new system with a higher Hard
Disk capacity or upgrade the existing one. Most of you will go for the second option, just like me,
unless the system is very old. Let us upgrade the system with an additional 20 GB of Hard Disk.
In order to attach the new virtual Hard Disk in VMware, click on the “Edit virtual machine
settings” link and choose the Add option on the next window.
Complete the attachment of the disk by specifying the required size of Hard Disk needed and
choosing the recommended selections.
The final configuration shows that our system has a new Hard Disk of 20 GB size. The newly
added Hard disk is of no use to our system unless we complete the remaining steps.
Shell Introduction
Linux Shell
The shell can be defined as a command interpreter within an operating system like
Linux/GNU or Unix. It is a program that runs other programs. The shell facilitates every user of
the computer as an interface to the Unix/GNU Linux system. Hence, the user can execute
different tools/utilities or commands with a few input data.
The shell sends the result to the user over the screen when it has completed running a
program which is the common output device. That's why it is known as "command
interpreter".
The shell is not just a command interpreter. Also, the shell is a programming language
with complete constructs of a programming language such as functions, variables, loops,
conditional execution, and many others.
For this reason, GNU/Unix Linux Shell is stronger than the Windows shell.
Broadly, the shell is categorized into two main categories which are explained below:
Graphical Shells
These shells specifies the manipulation of programs that are based on the graphical user
interface (GUI) by permitting for operations like moving, closing, resizing, and opening
windows and switching focus among windows as well. Ubuntu OS or Windows OS could be
examined as a good example that offers a graphical user interface to the user to interact with the
program. Various users don't need for typing in any command for all the actions.
Command-line Shell
Various shells could be accessed with the help of a command-line interface by users. A
unique program known as Command prompt in Windows or Terminal in macOS/Linux is
offered for typing in the human-understandable commands like "ls", "cat", etc and after that, it is
being run. The result is further shown to the user on the terminal.
Working on a command-line shell is a complicated for many beginners due to it is hard to
remember several commands. Command-line shell is very dominant and it permits users for
storing commands in a file and run them together. In this way, a repetitive action could be
automated easily. Usually, these files are known as Shell scripts in macOS/Linux systems and
batch files in Windows.
There are various types of shells which are discussed as follows:
Bash Shell
In the bash shell, bash means Bourne Again Shell. It is a default shell over several distributions of
Linux today. It is a sh-compatible shell. It could be installed over Windows OS. It facilitates
practical improvements on sh for interactive and programming use which contains:
Job Control
Command-line editing
Shell Aliases and Functions
Unlimited size command history
Integer arithmetic in a base from 2-64
Csh/Tcsh Shell
Tcsh is an upgraded C shell. This shell can be used as a shell script command processor and
interactive login shell.
Tcsh shell includes the following characteristics:
C like syntax
Filename completion and programmable word
Command-line editor
Job control
Spelling correction
Ksh Shell
Ksh means for Korn shell. It was developed and designed by David G. Korn. Ksh shell is a high-
level, powerful, and complete programming language and it is a reciprocal command language as
well just like various other GNU/Unix Linux shells. The usage and syntax of the C shell are very
same as the C programming language.
Zsh Shell
Zsh shell is developed to be reciprocal and it combines various aspects of other GNU/Unix Linux
shells like ksh, tcsh, and bash. Also, the POSIX shell standard specifications were based on the
Korn shell.
Also, it is a strong scripting language like other available shells. Some of its unique features are
listed as follows:
Startup files
Filename generation
Login/Logout watching
Concept index
Closing comments
Variable index
Key index
Function index and various others that we could find out within the man pages.
All these shells do a similar job but take different commands and facilitate distinct built-in
functions.
Fish
Fish stands for "friendly interactive shell". It was produced in 2005. Fish shell was developed
to be fully user-friendly and interactive just like other shells. It contains some good features
which are mentioned below:
Web-based configuration
Man page completions
Auto-suggestions
Support for term256 terminal automation
Completely scripted with clean scripts
Shell Prompt
It is known as a command prompt and it is issued via the shell. We can type any command while
the prompt is shown.
Shell reads our input after we click Enter. It illustrates the command we want to be run by seeing
at the initial word of our input. A word can be defined as the character's unbroken set. Tabs and
spaces separate words.
The below is a common data command example that shows the current time and date:
We can also customize our command prompt with the help of PS1 (environment variable).
Shell Scripting
The common concept of the shell script is the command list. A good shell script will contain
comments which are preceded via # simbol.
Shell functions and scripts are interpreted. It means they aren't compiled.
There are also conditional tests like value Y is greater than value Z, loops permitting us to
proceed by massive data amounts, files to store and read data, and variables to store and read
data, and these scripts may contain functions.
The shells are usually interactive which means they receive commands as input through the
users and run them. Although sometimes we routinely wish to run a set of commands, hence, we
have to type within the commands all-time inside the terminal.
A shell script includes syntax similarly to other programming languages. When we have prior
experience along with a programming language such as C/C++, Python, etc. It will be very easy to
begin with it. The shell script combines the below components:
Functions
Control flow: if, else, then, shell loops, case, etc.
Shell commands: touch, pwd, echo, ls, cd, etc.
Shell keywords: break, if, else, etc.
String Processing
The shell allows some common string operations which can be very useful for script writing.
String Length
# 1234567890123456
STRING="this is a string"
echo ${#STRING} # 16
Index
Find the numerical position in $STRING of any single character in $SUBSTRING that matches.
Note that the 'expr' command is used in this case.
STRING="this is a string"
SUBSTRING="hat"
expr index "$STRING" "$SUBSTRING" # 1 is the position of the first 't' in $STRING
Substring Extraction
Extract substring of length $LEN from $STRING starting after position $POS. Note that first
position is 0.
STRING="this is a string"
POS=1
LEN=3
echo ${STRING:$POS:$LEN} # his
If :$LEN is omitted, extract substring from $POS to end of line
STRING="this is a string"
echo ${STRING:1} # $STRING contents without leading character
echo ${STRING:12} # ring
Substring Replacement
STRING="to be or not to be"
Replace first occurrence of substring with replacement
STRING="to be or not to be"
echo ${STRING[@]/be/eat} # to eat or not to be
Replace all occurrences of substring
STRING="to be or not to be"
echo ${STRING[@]//be/eat} # to eat or not to eat
Delete all occurrences of substring (replace with empty string)
STRING="to be or not to be"
echo ${STRING[@]// not/} # to be or to be
Replace occurrence of substring if at the beginning of $STRING
STRING="to be or not to be"
echo ${STRING[@]/#to be/eat now} # eat now or not to be
Replace occurrence of substring if at the end of $STRING
STRING="to be or not to be"
echo ${STRING[@]/%be/eat} # to be or not to eat
replace occurrence of substring with shell command output
STRING="to be or not to be"
echo ${STRING[@]/%be/be on $(date +%Y-%m-%d)} # to be or not to be on 2012-06-14
Options
a: Shows processes from all the terminals.
x: Shows all the processes owned by you, or shows all the processes when used together
with the a option (such as: ps ax) Including processes that are not controlled by a terminal
Such as Daemon processes, This shows up as ? in the tty column of the output
u: Shows process owner information.
f: Shows process parentage
o: Shows custom information Such as pid, tty, stat, nice, %cpu, %mem, time, comm,
command, euser, ruser
Examples:
[mitesh@Matrix ~]$ ps
[mitesh@Matrix ~]$ ps a
[mitesh@Matrix ~]$ ps x
[mitesh@Matrix ~]$ ps u
[mitesh@Matrix ~]$ ps f
[mitesh@Matrix ~]$ ps xo pid,tty,stat,%cpu,%mem,time,command,euser,ruser
[mitesh@Matrix ~]$ ps axo pid,tty,stat,%cpu,%mem,time,command,euser,ruser
Process Status
Every process has a state property, which describes whether the process is actively using
the cpu (Running), in memory but not doing anything (Sleeping), waiting for a resource to
become available (Uninterruptable Sleep) or terminated but not flushed from the process
list (Zombie).
Running and Sleeping are normal, but the presence of Uninterruptable Sleep or Zombie
processes may indicate problems lurking on your system.
Uninterruptable Sleep
Process is sleeping and can not be woken up until an event occurs.
It can not be woken up by a signal.
Typically, the result of I/O operations, such as a failed network connections (For NFS
Hard Mounts).
Zombie
Just before a process dies, it sends a signal to its parent and waits for an acknowledgment
before terminating.
Even if the parent process does not immediately acknowledge this signal, all resources
except for the process identity number (PID) are released.
Zombie processes are cleared from the system during the next system reboot And do not
adversely affect system performance.
Finding Process
# Most Flexible
[mitesh@Matrix ~]$ ps axo pid,tty,comm | grep 'cups'
1516 ? cupsd
3066 pts/1 eggcups
Signals
Signals are simple messages that can be communicated to processes with commands like
kill.
Sent directly to processes, no user interface required.
Programs associate actions with each signal.
Signals are specified by name or number when sent man 7 signals shows complete list
Signal 1 HUP (SIGHUP) Re-read Configuration Files
Signal 9 KILL (SIGKILL) Terminate Immediately
Signal 15 TERM (SIGTERM) Terminate Cleanly
Signal 18 CONT (SIGCONT) Continue If Stopped
Signal 19 STOP (SIGSTOP) Stop Process
# The following are all identical and will send default TERM(15) signal to the process with PID
number 3705
[mitesh@Matrix ~]$ kill 3705
[mitesh@Matrix ~]$ kill -15 3705
[mitesh@Matrix ~]$ kill -TERM 3705
[mitesh@Matrix ~]$ kill -SIGTERM 3705
Scheduling Priority
Every running process has a scheduling priority: A ranking among running processes
determining which should get the attention of the processor.
Priority is affected by a process’ nice value.
The nice value range from -20 to 19 ( Default is 0 )
o -20: Highest CPU
o 19: Lowest CPU
Examples:
[mitesh@Matrix ~]$ ping 127.0.0.1 &> /dev/null
^Z
[1]+ Stopped ping 127.0.0.1 &>/dev/null
[mitesh@Matrix ~]$ bg
[1]+ ping 127.0.0.1 &>/dev/null &
NOTE!: The number next to [2] after backgrounding firefox is the PID
NOTE!: The + or -`` signs next to the job numbers tells which job is the default
+ sign is the default job
Scheduling Process
One time jobs use at, Recurring jobs use crontab
/-----------------------------------------------------------------------\
| |
| Create | at time | crontab -e |
| List | at -l | crontab -l |
| Details | at -c jobnum | |
| Remove | at -d jobnum | crontab -r |
| Edit | | crontab -e |
| |
\-----------------------------------------------------------------------/
Non-redirected output is mailed to the user
The root can modify jobs for other users
at command
Scheduling One Time Job with at command
One Command Per Line
Terminated With Ctrl+d
Options
/-----------------------------------------------------------------------\
| at 8:00am December 7 at 7 am Thursday |
| at midnight + 23 minutes at now + 5 minutes |
\-----------------------------------------------------------------------/
/-------------------------------------------------------------------------------------------------------\
| Command Alias Meanning
|
|--------------------------------------------------------------------------------------------------------
|
|
| atq | at -l | Lists the jobs currently pending.
|
| atrm | at -d jobnum | Deletes the job.
|
| | at -c jobnum | Cats the full environment for the specified
job. |
|
|
\-------------------------------------------------------------------------------------------------------/
Example:
[mitesh@Matrix ~]$ at 0200
at> date
at> cal
at> <EOT>
job 1 at 2011-08-26 02:00
[mitesh@Matrix ~]$ atq
[mitesh@Matrix ~]$ at -l
1 2011-08-26 02:00 a mitesh
crontab command
Scheduling Recurring Jobs with crontab command
The cron mechanism is controlled by a process named crond.
This process runs every minute and determines if an entry in user’s cron tables need to be
executed.
The crontabs are stored in /var/spool/cron/
The root can modify the jobs for other users with crontab -u username and any of the
other options, such as -e.
Crontab File Format
Comment lines begin with #.
One entry per line, no limit to line length.
Entry consist of five space-delimited fields followed by a command name.
Fields are Minute, Hour, Day Of Month, Month, Day Of week.
An asterisk (*) in a field represent all valid values.
Multiple values are separated by commas.
See man 5 crontab for more details
/-----------------------------------------------------------------------\
| |
| Minute | 0-59 |
| Hour | 0-23 |
| Day Of Month | 1-31 |
| Month | 1-12 (Or Jan, Feb, Mar, Etc) |
| Day Of Week | 0-7 (Or Sun, Mon, Tue, Etc) |
| (0 or 7 = Sunday, 1 = Monday) |
| |
\-----------------------------------------------------------------------/
# * * * * * command to execute
#│││││
#│││││
# │ │ │ │ └───── day of week (0 - 6) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday,
the same as 0)
# │ │ │ └────────── month (1 - 12)
# │ │ └─────────────── day of month (1 - 31)
# │ └──────────────────── hour (0 - 23)
# └───────────────────────── min (0 - 59)
Example:
[mitesh@Matrix ~]$ crontab -e
#Min Hour DOM Month DOW Command
0 0 31 10 * mail -s "boo" $LOGNAME < boo.txt
0 2 * * * netstat -tulpn | diff - /media/cdrom/baseline
0 4 * * 1,3,5 find ~ -name core | xargs rm -f {}
crontab in details
The cron mechanism is controlled by a process named crond.
This process runs every minute and determines if an entry in user’s cron tables need to be
executed.
The crontabs are stored in /var/spool/cron/`
The root can modify the jobs for other users with crontab -u username and any of the
other options, such as -e.
Crontab File Format
Comment lines begin with #.
One entry per line, no limit to line length.
Entry consist of five space-delimited fields followed by a command name.
Fields are Minute, Hour, Day Of Month, Month, Day Of week.
An asterisk (*) in a field represent all valid values.
Multiple values are separated by commas.
Special Time Specification Nicknames: @reboot, @yearly, @annually, @monthly,
@weekly, @daily, @hourly
See man 5 crontab for more details
Examples:
[mitesh@Matrix ~]$ crontab -e
#Min Hour DOM Month DOW Command
0 0 31 10 * mail -s "boo" $LOGNAME < boo.txt
0 2 * * * netstat -tulpn | diff - /media/cdrom/baseline
0 4 * * 1,3,5 find ~ -name core | xargs rm -f {}
Example:
According To The /etc/crontab File
At 4:02 Every Morning, All Of The Executables In The /etc/cron.daily/ Directory Will Be
Run As root User.
Now Suppose Your Laptop Is Almost Always Off At The 4:02 AM, Then The mlocate &
whatis Database Is Never Be Updated.
Configuration File
/etc/anacrontab
Field1: If The Cron Jobs Not Been Run For The Specified No Of Days
Field2: Wait For The Specified No Of Minutes Before Runs
Field3: Job Identifier
Field4: The Cron Job To Run
Examples:
[mitesh@Matrix ~]$ cat /etc/anacrontab
# /etc/anacrontab: configuration file for anacron
# See anacron(8) and anacrontab(5) for details.
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22
# Period In Days Delay In Minutes Job-Identifier Command
1 5 cron.daily nice run-parts /etc/cron.daily
7 25 cron.weekly nice run-parts /etc/cron.weekly
@monthly 45 cron.monthly nice run-parts /etc/cron.monthly
How Anacron Works
According To The /etc/crontab File
The 1st Command To Run Is 0anacron.
The 0anacron Command Sets The Last Run Timestamp In A /var/spool/anacron/cron.
{daily,weekly,monthly} Files.
On The System Boot Up, The Anacron Commands Runs.
The /etc/anacrontab File Specify How Often The Commands In cron.daily/ cron.weekly/
and cron.monthly/ Should Be Runs.
If These Commands Are Not Runs In This Time Then
The Anacron Command Waits For The Specified No Of Minutes In The /etc/anacrontab
File & Then Runs The Commands
Grouping Commands
Two ways to group commands
Compound
Example: date; who | wc -l
Commands run back to back
Subshell
Commands inside parentheses are run in their own instance of bash, called subshell.
Example: (date; who | wc -l)
All output is sent to a single STDOUT and STDERR
Suppose you want to maintain a count of the number of users logged on, Along with a
time/date stamp, in a log file.
Examples:
[mitesh@Matrix ~]$ date >> logfile
[mitesh@Matrix ~]$ who | wc -l >> logfile
[mitesh@Matrix ~]$ date; who | wc -l
Tue Aug 30 14:04:31 IST 2011
3
[mitesh@Matrix ~]$ date; who | wc -l >> logfile
Tue Aug 30 14:05:08 IST 2011
[mitesh@Matrix ~]$ (date; who | wc -l) >> logfile
Exit Status
Processes report success or failure with an exit status.
0 for success
1-255 for failure
$? stores the exit status of the most recent command
exit [num] terminates and set status to num
Examples:
[mitesh@Matrix ~]$ ping -c1 -w1 localhost &> /dev/null
[mitesh@Matrix ~]$ echo $?
0
[mitesh@Matrix ~]$ ping -c1 -w1 station999 &> /dev/null
[mitesh@Matrix ~]$ echo $?
2
Examples:
[mitesh@Matrix ~]$ grep -q 'no_such_user' /etc/passwd || echo "No such user"
No such user
[mitesh@Matrix ~]$ ping -c1 -w2 localhost &> /dev/null \
> && echo "Localhost is up" \
> || (echo "Localhost is unreachable"; exit 1)
Localhost is up
[mitesh@Matrix ~]$ echo $?
0
[mitesh@Matrix ~]$ ping -c1 -w2 station999 &> /dev/null \
> && echo "Station999 is up" \
> || (echo "station999 is unreachable"; exit 1)
station999 is unreachable
[mitesh@Matrix ~]$ echo $?
1
#!/bin/bash
for x in $(seq 1 10)
do
echo adding test$x
(
echo -ne "test$x\t"
useradd test$x 2>&1 > /dev/null && mkpasswd test$x
) >> /tmp/userlog
done
echo 'cat /tmp/userlog to see new passwords'
test command
The test command evaluates true or false scenarios to simplify conditional execution.
Returns 0 for true
Returns 1 for false
NOTE!: Strings should be compared using a Mathematical Operator, While Numbers are
compared using an Abbreviation (-eq).
Examples:
# Long Form
$ test "$A" = "$B" && echo "Strings are equal"
$ test "$A" -eq "$B" && echo "Integers are equal"
# Shorthand
$ [ "$A" = "$B" ] && echo "Strings are equal"
$ [ "$A" -eq "$B" ] && echo "Integers are equal"
File Tests
Use the following command for complete list man test
/-----------------------------------------------------------------------------------------------\
|
|
| -d FILE | FILE exists and is a directory
|
| -e FILE | FILE exists
|
| -f FILE | FILE exists and is a regular file |
| -h FILE | FILE exists and is a symbolic link (same as -L)
|
| -L FILE | FILE exists and is a symbolic link (same as -h)
|
| -r FILE | FILE exists and read permission is granted |
| -s FILE | FILE exists and has a size greater than zero |
| -w FILE | FILE exists and write permission is granted |
| -x FILE | FILE exists and execute (or search) permission is granted |
| -O FILE | FILE exists and is owned by the effective user ID |
| -G FILE | FILE exists and is owned by the effective group ID |
|
|
\-----------------------------------------------------------------------------------------------/
Example:
$ [ -f ~/lib/functions ] && source ~/lib/functions
Scripting If Statements
Every process reports an exit status.
0 for success
1-255 for failure
Execute instructions based on a exit status of the command.
#!/bin/bash
if ping -c1 -w2 station1 &> /dev/null
then
echo "Station1 is up"
elif grep "station1" ~/maintenance.txt &> /dev/null
then
echo "Station1 is undergoing maintenance"
else
echo "Station1 is unexpectedly DOWN!"
exit 1
fi
The exit status can be checked within the body of the if as shown in the example, Or you
can assign the exit status to a variable using a subshell, as in:
o STATUS=$(test -x /bin/ping6)
The if structure can be combined with conditional operator
#!/bin/bash
if test -x /bin/ping6; then
ping6 -c1 ::1 &> /dev/null && echo "IPv6 stack is up"
elif test -x /bin/ping; then
ping -c1 127.0.0.1 &> /dev/null && echo "No IPv6, but IPv4 stack is up"
else
echo "Oops! This should not happen."
exit 255
fi
NOTE!: This script checks for the IPv6 version of the ping command (ping6) exists.
If it does, it uses ping6 to send a test packet to the system’s IPv6 Loopback Interface.
Else The script checks for the IPv4 version of the ping command (ping) exists.
If it does, it uses ping to send a test packet to the system’s IPv4 Loopback Interface.
If neither IPv6 nor IPv4 exists,
Something is probably wrong and a non-zero return code is issued along with a warning
message.
FOR GOOD EXAMPLE OF REAL WORLD SCRIPTS, LOOK AT THE SCRIPTS IN /etc/init.d/*
Network Clients
Web Clients
Links
Links is a Text Based (Non GUI) Web Broser.
Provided by the elinks package.
Full support for Frames and SSL.
Examples:
[mitesh@Matrix ~]$ links http://www.redhat.com
[mitesh@Matrix ~]$ links -dump http://www.redhat.com
[mitesh@Matrix ~]$ links -source http://www.redhat.com
Wget
The wget is a non-interactive network downloader.
Retrieves files via HTTP and FTP.
Options:
/-----------------------------------------------------------------------------------------------\
|
|
| --continue (-c) | Continue Partially Downloaded File |
|
|
| --tries=number | Retry the specified number of times to download the files |
| --wait=seconds | Wait the specified number of seconds between the retrievals
|
|
|
| --recursive | Turn on recursive retrieving
|
| --level=depth | Specify recursion maximum depth level
|
| | (The default maximum depth is 5) |
| --convert-links | After download is complete convert all links, |
| | To make them suitable for local viewing
|
|
|
\-----------------------------------------------------------------------------------------------/
Examples:
[mitesh@Matrix ~]$ wget http://www.redhat.com/training/index.html
[mitesh@Matrix ~]$ wget -c ftp://ftp.site.com/selinux.tar.gz
[mitesh@Matrix ~]$ wget --tries=50 --wait=30 ftp://ftp.site.com/files
[mitesh@Matrix ~]$ wget --recursive --level=1 --convert-links http://www.site.com
Google Chrome/Firefox
Tabbed Browsing
Popup Blocking
Cookie Manageent
Themes and Extensions
Multi-Engine Search Bar
Supports For Many Popular Plug-ins
Email and Messaging
Graphical Mail Clients
Evolution
Flexible Email & Groupware Tool
Used For
o Email Access
o Maintain a Calendar, Tasklist and Contacts Database
Thunderbird
Standalone Mozilla Email Client
Used For
o Email Access
o Usenet and RSS Supports
Examples:
You Can Read One Mailbox (POP Account, IMAP Account or Local Mailbox) At A Time.
# Start The Local Mailbox
[mitesh@Matrix ~]$ mutt
# The mutt -f Starts The Specified Mailbox
[mitesh@Matrix ~]$ mutt -f imaps://user@server
Note!: You Can Change Which Mailbox Mutt Viewed By Default, By Altering Its Configuration File
~/.muttrc.
Syntax:
ssh [user@]hostname
ssh [user@]hostname command
Examples:
[mitesh@Matrix ~]$ ssh localhost
[mitesh@Matrix ~]$ ssh [email protected]
[mitesh@Matrix ~]$ ssh neo@localhost 'df -h'
neo@localhost's password:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_Matrix-lv_root 50G 2.4G 45G 6% /
tmpfs 495M 472K 494M 1% /dev/shm
/dev/sda1 485M 30M 430M 7% /boot
/dev/mapper/vg_Matrix-lv_home 59G 3.2G 53G 6% /home
Syntax:
scp [OPTIONS] [[user@]host1:]file1... [[user@]host2:]file2
* Options:
-r(recursive): Recursively copy an entire directory tree
-p(preserve): Preserve the permissions, ownership, and time stamps
Examples:
# Download the process.log file
[mitesh@Matrix ~]$ scp neo@localhost:process.log .
neo@localhost's password:
process.log 100% 8843 8.6KB/s 00:00
Examples:
[mitesh@Matrix ~]$ rsync --progress neo@localhost:file1 .
neo@localhost's password:
file1
55 100% 53.71kB/s 0:00:00 (xfer#1, to-check=0/1)
sent 36 bytes received 129 bytes 36.67 bytes/sec
total size is 55 speedup is 0.33
[mitesh@Matrix ~]$ cat file1
Hello Linux!
Welcome to the OSS!
Syntax:
ssh-copy-id [user@]hostname
Examples:
ssh-copy-id -i ~/.ssh/identity.pub [user@]hostname
ssh-copy-id -i ~/.ssh/id_rsa.pub [user@]hostname
ssh-copy-id -i ~/.ssh/id_dsa.pub [user@]hostname
Structure Of ssh-keygen
/---------------------------------------------------------------\
| |
| identity Private 600 |
| RSA1 |
| identity.pub Public 644 |
| |
| ssh-keygen |
| |
| id_rsa Private 600 |
| RSA |
| id_rsa.pub Public 644 |
| |
| id_dsa Private 600 |
| DSA |
| id_dsa.pub Public 644 |
| |
\---------------------------------------------------------------/
Examples:
# Generate Protocol2 RSA Key Pairs
[mitesh@Matrix ~]$ ssh-keygen
# Generate Protocol2 DSA Key Pairs
[mitesh@Matrix ~]$ ssh-keygen -t dsa
# Generate Protocol1 Key Pairs
[mitesh@Matrix ~]$ ssh-keygen -t rsa1
ssh-agent
If you created your private key with a passphrase, which is highly recommended for the
security reasons, Then whenever the key is used to connect to the other machines, you
must type your passphrase.
An Authentication Agent Stores The Decrypted Private Keys
Thus, Passphrase only need to be entered once.
In GNOME Authentication Agent is provided automatically.
Otherwise, You will need to create a Agent-Managed Shell with ssh-agent command
[mitesh@Matrix ~]$ ssh-agent bash
[mitesh@Matrix ~]$
The Keys are added to the Agent with ssh-add command
If no filename is specified, The Keys stored in ~/.ssh/id_rsa and ~/.ssh/id_dsa will be
used
You can view the list of stored keys by running
[mitesh@Matrix ~]$ ssh-add -l
NOTE!: When you are finished, Just type exit to return your original shell.
When the Agent is terminated, All your keys are forgotten.
FTP Clients
Several FTP Clients are availables such as sftp, lftp, lftpget, gftp and many more.
sftp
Interactive Secure File Transfer Program.
The sftp uses a secure ssh connections for transport the files.
lftp:
More Featureful File Transfer Program.
Examples:
[mitesh@Matrix ~]$ lftp ftp.example.com
[mitesh@Matrix ~]$ lftp -u joe ftp.example.com
lftpget
Non-interactive File Transfer Program.
Examples:
[mitesh@Matrix ~]$ lftpget ftp://ftp.example.com/pub/file.txt
gftp
Graphical File Transfer Program.
Applications -> Internet -> gFTP
Allows Drag and Drop Transfer
Anonymous or Authenticated Access
Optional Secure Transfer vis SSH (sftp)
SMB Clients
FTP Like Client To Access SMB/CIFS Resources On Server
SMB Clients are used to access the shared resources on the MS Windows Network
Options:
-W: Workgroup or Domain
-U: Username
-N: Suppress password prompt (Useful when accessing a service that does not require a
password)
File Transfer with Nautilus
Nautilus are also used to access the remote file shares.
Places -> Connect to Server
Allows Drag and Drop File Transfer
Graphically Browse With Multiple Protocols
Suported Connection Types:
SSH
FTP
SFTP
WebDAV (HTTP)
Secure WebDAV (HTTPS)
Microsoft Windows Shares
Nautilus URL
ftp://ftp.example.com | Connects via ftp to ftp.example.com
sftp://[email protected] | Same as above, but connecting securely via ssh as
user
Xorg Clients
One Of The Most Important Features Of Xorg Is Its Client/Server Architecture, That Makes
Any Graphical Application On Linux System Completely Network Transparent.
That Means You Can Start Any Graphical Application On The Remote System & That
Application Displayed On The Local System.
The Graphical Application Running In This Way
Affects Files On The Remote System
Take Up Resources (Cpu Cycles, Memory, Etc) On The Remote System
And That Graphical Application Only Displayed On The Local System
Note!: All Graphical Applications Are X Clients & Connects To The Remote X Server Via TCP/IP
By Default, The Data Transfer Is Not Encrypted But Can Be Tunneled Securely Over An SSH
Connection
ssh -X [user@]hostname xterm &
Installing Application
In Windows operating systems every application comes with a setup file along with a .exe
extension that becomes much easier to install. but on the other hand in Linux-based operating
systems, it becomes different to install.
In Linux distros, there are three different methods to install the application.
1. Using Terminal.
2. Using Software center.
3. Using snapcraft & other package managers.
Step 1. Go to terminal
For installing an application through the terminal, first of all, we need to open the terminal by
using the shortcut key Ctrl+Alt+T or going into your Dashboard and searching for Terminal.
Step 2. Get a specific command name to install.
Linux has a huge list of commands. run apt update && apt list | wc to get exactly the available
commands in your apt repository (mine has 74909 commands). So it is really hard to remember
these commands. There are some cool ways to find the desired command or tool to install.
apropos the command helps when you know a few keywords related to the command that
define its uses or functionality. It searches the Linux man pages with the help of the keyword
provided by the user to find the command and its functions.
If you don't have one, you can make it. Get information about the tool with apt show tool_name |
grep Description . Now you can use some basic BASH skills to get more info about programs.
Use apt list | cut -d '\' -f1 | xargs apt show | grep Description 2>/dev/null and then grep any
keyword for more results.
and enter your sudo password (your password isn't visible and no hidden sign *)
after a few moments later a question appears in your terminal
Do you want to continue?
press Y follow with the enter key as shown in the above image.
Now your application is visible in your dashboard.
How to Install programs in Linux using the Software center
In Ubuntu Linux, there is a utility application Ubuntu software that is used for software
installation. This is the easiest way to install applications.
Step 1. Go to the application/software store.
Search Ubuntu software on the dashboard as shown in the picture.
Step 2. Search and install programs with ease.
Select your desired application you can also choose by categories either search application
entering the name in the search bar. Once you have found the application you are looking for,
simply click on it.
This will open a page inside the Ubuntu software center with a description of the application.
Click install to install the application on your computer. You can also submit your valuable
feedback and rate the applications.
Note - Authentication is also required for installing an application so you have to enter your
password to install the application.
Then after we can install the application using the snaps command from the software website.
(make sure that snapd daemon is running)
$ sudo snap install <package>
for making the concept clear we are installing VLC using snap
Open terminal and Enter this command.
$ sudo snap install vlc
A few moments later, the VLC media player will be installed.
Now VLC media player is installed in your Ubuntu operating system you can find it in your
dashboard.
Conclusion
Now you have learned three different ways to install all popular tools in Linux easily using
command-line package managers and software stores.