0% found this document useful (0 votes)
15 views

Training Linux - 3

The document discusses a Linux fundamentals training course. It covers topics like files and directories management, networking and services, process management, shell scripting, and variables and arithmetic in shell scripts. The course is scheduled over 5 days and includes presentations and hands-on labs.

Uploaded by

Nguyễn Tùng
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Training Linux - 3

The document discusses a Linux fundamentals training course. It covers topics like files and directories management, networking and services, process management, shell scripting, and variables and arithmetic in shell scripts. The course is scheduled over 5 days and includes presentations and hands-on labs.

Uploaded by

Nguyễn Tùng
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

Training Course

Linux Fundamentals

3/21/2022 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 1


Course Overview
▪ This course helps you to understand how Linux works from
basics. Once you learn complete this course you can able
to
✔ Fulfill your regular tasks on the Linux server
✔ Easily start learning most of the trending technologies like AWS, Azure, GCP, DevOps, Python,
BigData, DataScience, etc...

▪ Who this course is for


✔ Any IT professional who wants to learn Linux basics quickly
✔ People who don't know why to start their DevOps journey.

3/21/2022 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 2


Course Schedule

Day Presentations Lab


Day 1 Introduction X
Files and Directories
Day 2 Management (User, System, Software) X
Networking and Services, Process management & other
Day 3 Shell Script X
Day 4,5 Assignment activities, divide into group to discuss and Test X

3/21/2022 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 3


Linux Fundamentals

DAY 3

3/21/2022 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 4


Linux Fundamentals
What is shell ?

• The Shell acts as an interface to the Unix system.


It gathers input from user and execute the programs
based on the input. When the program
execution is complete, it displays the program’s
output.
• Shell is an environment in which we can run
our commands, programs and shell scripts.

3/21/2022 5
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals

Type of Shells
• In Unix and Linux, the two major types of shell scripts are:
⮚ Bourne again shells (BASH)- BASH is the default shell for Unix version 7. The character for prompting a
bourne again shell is $.
⮚ C shells- A C shell is run in a text terminal window and is able to easily read file commands. The
character for prompting a C shell is %.

3/21/2022 6
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals

How to write shell script ?

• Open terminal.
• Navigate to the place where you want to create script using ‘cd‘ command.
• cd (enter) [This will bring the prompt at Your home Directory].
• touch my_first_script.sh (Here we named the script as hello, remember the ‘.sh‘
extension is compulsory).
• vi my_first_script.sh (nano hello.sh) [You can use your favourite editor, to edit the
script].
• chmod 744 my_first_script.sh (making the script executable).
• sh my_first_script.sh or ./my_first_script.sh (running the script)

3/21/2022 7
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
Getting started with Shell Programming
Variables in Shell

• In Linux (Shell), there are two types of variable:

⮚ (1) System variables - Created and maintained by Linux itself. This type of variable defined in CAPITAL
LETTERS.
⮚ (2) User defined variables (UDV) - Created and maintained by user. This type of variable defined in
lower letters

3/21/2022 8
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
Getting started with Shell Programming
You can see system variables by giving command like $ set, some of the important System variables are:

You can print any of the above variables contain as follows:


$ echo $USERNAME
$ echo $HOME
Caution: Do not modify System variable this can some time create problems.

3/21/2022 9
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
Getting started with Shell Programming
How to define User defined variable
Syntax:
variable name=value
'value' is assigned to given 'variable name' and Value must be on right side = sign

Example:
number_one=1 # This is ok
1=number_one # Error

3/21/2022 10
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
Getting started with Shell Programming
Rules for Naming variable name (Both UDV and System Variable)
(1) Variable name must begin with Alphanumeric character or underscore character (_), followed by one or more
Alphanumeric character. For e.g. Valid shell variable are as followsSyntax:
HOME
SYSTEM_VERSION
number_one

(2) Don't put spaces on either side of the equal sign when assigning value to variable. For e.g. In following variable
declaration there will be no error:
number_one=1

But there will be problem for any of the following variable declaration:
number_one =1
number_one= 1
number_one = 1

3/21/2022 11
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
Getting started with Shell Programming
(3) Variables are case-sensitive, just like filename in Linux
Number_one=1
number_one=1

(4) You can define NULL variable as follows (NULL variable is variable which has no value at the time of definition)
str=
str=“123"
Try to print it's value by issuing following command
echo $str
Nothing will be shown because variable has no value i.e. NULL variable.

(5) Do not use ?,* etc, to name your variable names

3/21/2022 12
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
Getting started with Shell Programming
How to print or access value of UDV (User defined variables)

To print or access UDV use following syntax:


$variable_name

Define variable number_one as follows:


number_one=1

To print contains of variable ‘number_one' type:


echo $number_one

3/21/2022 13
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
Getting started with Shell Programming
echo Command
Use echo command to display text or value of variable.
Syntax:
echo [options] [string, variables...]
Displays text or variables value on screen.
Options:
-n Do not output the trailing new line.
-e Enable interpretation of the following backslash escaped characters in the strings:
\a alert (bell)
\b backspace
\c suppress trailing new line
\n new line
\r carriage return
\t horizontal tab
\\ backslash
E.g. $ echo -e "My name is \a\t\tHung\n"

3/21/2022 14
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
Getting started with Shell Programming
Shell Arithmetic
Use to perform arithmetic operations.
Syntax:
expr op1 math-operator op2

Examples:
expr 4 + 3
expr 4 - 3
expr 4 / 3
expr 4%3
echo `expr 4+3`.

3/21/2022 15
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
Getting started with Shell Programming
The read Statement
Use to get input (data from user) from keyboard and store (data) to variable. Syntax: read variable1, variable2,...variable

Example:
$ vi second_script.sh
echo "What is your last name?"
read last_name
echo "hello $last_name"
$ chmod 744 second_script
$ ./ second_script

3/21/2022 16
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
Getting started with Shell Programming
Wild cards (Filename Shorthand or meta Characters)

3/21/2022 17
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
Shells (bash) structured Language Constructs
For Mathematics, use following operator in Shell Script

3/21/2022 18
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
Shells (bash) structured Language Constructs
For string Comparisons us

3/21/2022 19
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
Shells (bash) structured Language Constructs
Shell also test for file and directory types

3/21/2022 20
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
Shells (bash) structured Language Constructs
Question?

?
Type String and Array in Shell
Script?

3/21/2022 21
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
Shells (bash) structured Language Constructs
If else condition

Syntax:
if condition
then
Statement(s) to be executed if condition is true
else
Statement(s) to be executed if condition is false
fi

3/21/2022 22
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
Shells (bash) structured Language Constructs
If-then-else condition

Syntax:
if condition1
then
Statement(s) to be executed if condition1 is true
elif condition2
then
Statement(s) to be executed if condition2 is true
else
None of the above condition1, condition 2 are true
fi

3/21/2022 23
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
Shells (bash) structured Language Constructs
The case Statement

Syntax:
case $variable in
pattern1)
command …
command;;
pattern2)
command …
command;;
patternN)
command …
command;;
esac

3/21/2022 24
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
Shells (bash) structured Language Constructs
while loop
Syntax:
While [ condition ]
do
Statement(s) to be executed if condition is true
done

Loop is executed as long as given condition is true

3/21/2022 25
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
Shells (bash) structured Language Constructs
Function
To declare a function, simply use the following syntax
Syntax:
function_name()
{
list of commands
}

Following example shows the use of function


HelloWorld()
{
echo "hello world"
}

# invoke function
HelloWorld

3/21/2022 26
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
Shells (bash) structured Language Constructs
Pass Parameters to a Function
To declare a function, simply use the following syntax
Syntax:
function_name()
{
list of commands
}

Following example shows the use of function


HelloWorld()
{
echo "hello world $1 $2"
}

# invoke function
HelloWorld Nguyen Hung

3/21/2022 27
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
Shells (bash) structured Language Constructs
Question?

?
How to de-bug the shell script?

3/21/2022 28
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals

SELF-STUDY!!!

3/21/2022 29
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
If - Else
Find max in three number
Eg: You have three number 9,5,2. You find maximum number is 9.

Switch_case
Check number is Odd or Even
Eg: You have a input number. You check number is Odd or Even.

3/21/2022 30
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
While - loop
Print Star
Eg: You have a input number. You print tringle star.

3/21/2022 31
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals

DAY 3
SUMMARY

3/21/2022 32
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals

ASSIGNMENT

3/21/2022 33
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals

REVIEW AND
RESEARCH

3/21/2022 34
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
REVIEW AND RESEARCH
Divide the class into 6 groups for research, presentation and discussion

1.User/group management in Linux


2.Task/process management, crontab in Linux
3.Software management in Linux (using softlink and hardlink)
4.File/directory management, Editor in Linux
5.Bash scripting, Crontab in Linux
6.Remote, file transfer in Linux

3/21/2022 35
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
REVIEW AND RESEARCH
Target

1. Review
2. Definition, use case
3. How to install, deploy, command
4. Expanding the scope of research
5. Present

3/21/2022 36
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Linux Fundamentals
REVIEW AND RESEARCH
How to implement

• Introduce Group
• Introduce module of Group
• Basic Summary
• Extend Summary
• Demo
• All of this

(About 10 - 15 minutes/group)

3/21/2022 37
09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use
Thank you

3/21/2022 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 38

You might also like