SlideShare a Scribd company logo
Prepared by: Mohamed AbdAllah
Raspberry pi interfacing
Lecture 2: Linux OS
1
Linux OS Agenda
 Introduction to Linux OS.
 Linux file system hierarchy.
 Linux commands.
 Files permissions.
 Input-Output redirection.
 Environment variables.
 Process management.
 Linux shell scripting.
2
Linux OS Agenda
3
Introduction to Linux operating system
4
 What is Linux operating system ?
• In 1983, Richard Stallman, founder of the Free Software Foundation, set
forth plans of a complete Unix-like operating system, called GNU,
composed entirely of free software.
• By 1991 the lower level (kernel, device drivers, system-level utilities and
daemons) was still mostly lacking.
• In 1991, Linus Torvalds released the first version of the Linux kernel. Early
Linux developers ported GNU code, including the GNU C Compiler, to the
kernel. The free software community adopted the use of the Linux kernel
as the missing kernel for the GNU operating system.
Introduction to Linux operating system
5
 Linux OS main components
Introduction to Linux operating system
6
 Linux features
• Open Source: Linux source code is freely available and it is community
based development project. Multiple teams works in collaboration to
enhance the capability of Linux operating system and it is continuously
evolving.
• Multi-User: Linux is a multiuser system means multiple users can access
system resources like memory, ram, application programs at same time.
• Multiprogramming: Linux is a multiprogramming system means multiple
applications can run at same time.
• Hierarchical File System: Linux provides a standard file structure in which
system files, user files are arranged.
Introduction to Linux operating system
7
 Linux features
• Shell: Linux provides a special interpreter program which can be used to
execute commands of the operating system. It can be used to do various
types of operations, call application programs etc.
• Security: Linux provides user security using authentication features like
password protection, controlled access to specific files, encryption of
data.
Introduction to Linux operating system
8
Introduction to Linux operating system
9
Linux file system hierarchy
10
Linux file system hierarchy
11
 /etc
• Contains systems configurations files.
 /usr/bin
• Contains commands for all users.
 /usr/sbin
• Contains commands for root user.
 /dev
• Contains hardware devices tree.
 /home/username
• Home directory for user of name “username”.
Linux file system hierarchy
12
Linux file system hierarchy
 /etc/passwd
• Contains one line for each user account, with seven fields delimited by
colons (“:”). These fields are:
[login name : encrypted password : user ID : group ID : comment : home
dir : default shell]
 /etc/shadow
• Contains the password information for the system’s accounts and
optional aging information.
• Each line contains 9 fields, separated by colons (“:”), in the following
order:
[login name : encrypted password : last change : min pass age : max pass
age : pass warning period : pass inactivity period : account expiration date
: reserved field]
13
Linux file system hierarchy
 /etc/group
• Contains the groups on the system with one line per group..
• Each line contains 4 fields, separated by colons (“:”), in the following
order:
[group name : password : group ID : members usernames separated by
commas]
14
Linux commands
15
 Command format
Command option argument
Command: required command to execute.
Option: options given to command.
Argument: which the command is executed on.
Linux commands
16
 Commands examples
$ ls /etc : list directory content
$ ls –l /etc : long list option
$ ls –t /etc : sort with time
$ ls –l –t /etc : long list and sort with time
$ cal : calendar of current month
$ cal 2014 : calendar of 2014
$ cal 5 2014 : calendar of 5/2014
$ alias display=“ls –l” : create an alias
$ unalias display : delete an alias
Linux commands
17
 Commands examples
$ man command : get manual for any command
$ man –k : search in manual by keyword
$ man –s1 : search in section 1 (s1 for user commands, s4 for file formats)
$ pwd : print working directory
$ cd /etc : change directory to /etc
$ cd .. : change directory to parent directory
$ cd : change directory to home directory
$ cd ~ : same as previous
Linux commands
18
 Commands examples
$ mkdir dirname : make new directory with name “dirname”
$ mkdir /dir1/dir2 : make new directory and create any parent directory
$ rmdir : remove empty directory
$ touch : create new empty file
$ rm : remove file
$ rm –r : remove folder with all its content
$ find startPoint criteria itemToSearchFor
$ grep pattern files : search for a pattern in files
$ echo Text : print Text to screen
Linux commands
19
 Commands examples
$ cat : display file content
$ more : display file content according to screen size
$ less : same as more, and allows backward movement
$ head -3 : display first 3 lines of a file
$ head : display by default 10 lines
$ tail -2 : display 2 lines from the file end
$ sort –k1 –t: -r /etc/passwd : sort file according to field 1, with field
separator of : in descending order according to ASCII
$ sort –nk3 : sort in numeric order
$ sort –o output file : save result in same file
Linux commands
20
 Commands examples
$ wc : display count of lines, words and characters of a file
$ wc –l : display number of lines
$ wc –w : display number of words
$ wc –c : display number of characters
$ cp source destination : copy file from source to destination
$ cp –r : copy directory
$ mv : move file or directory
$ mv -i: ask for overwrite if exists
Linux commands
21
 Commands examples
$ date : display current day date
$ who : display logged in users
$ df : display all disk partitions with size in blocks of 512 bytes
$ df – k : size in Kbytes
$ df –h : size in Gbytes
$ cut –f1,7 –d: /etc/passwd : display fields 1 and 7 with separator : in file
/etc/passwd
$ cut –f3-5 –d: /etc/passwd : from field 3 to field 5
$ cut –f3- –d: /etc/passwd : from field 3 to the end
$ cut –f-3 –d: /etc/passwd : from first field to field 3
Linux commands
22
 ~ : home directory
 * : any combination (alpha-num)
 ? : one character (alpha-num)
 [ab3sc] : one character of this set
 [a-e0-4] : one character in this ranges
 $ ls *.[abc0-5] : list directory content which names contains any set of
characters followed by ‘dot .’ then followed by one character of (a, b, c, 0, 1, 2,
3, 4, 5)
File name expansion
23
Files permissions
24
$ ls –l /etc/passwd
-rw-r- -r-- 1 root root 988 ….. ….
-rw-r- -r-- : file type, owner permissions, group permissions, other
permissions
1 : number of hard links
Root : owner
Roor : group
988 : size
Creation time and file name
$ ls –d /etc/ : list directory permissions
Files permissions
25
Files permissions
Permission On file On directory
R Read file content List files
W Modify file content Modify directory
from outside
X Execute file Change to directory
or access any file
inside it
$ chmod u+x : add execute permission to owner
$ chmod u=rx,g=-,o=x : make owner read execute, group none, other
execute only
$ chmod 7 file1 : change permissions to be 007
$ umask 777 : set umask to be 111 to set default permissions to be
complement of umask
$ umask : display current default permissions
26
Input-Output redirection
27
$ ls –l /etc/passwd 1> file1
Redirect output list to file “file1”
1 > output redirection, overwrite
1 >> append output
2 > error redirection
$ Cat < file : input redirection
Input-Output redirection
28
$ command1 | command 2
Pipeline command 1 output to be as input to command 2
$ cut –d: -f1,3 /etc/passwd | sort –t: -nk2
Pipelining
29
Environment variables
30
 Built in variables:
• $ echo $PWD : display value of $PWD that saves current path
• $HOME : save home directory
• $LOGNAME : save login name
• $PS1 : shell command prompt
• $PS2 : appears when command didn’t end yet
• $PS3 : appears when user is asked to enter a choice
• $PATH : contains all paths that shell uses to search for commands
• $$ : process ID (PID) of current shell
Environment variables
31
 User defined variables:
• $ x=4 : create variable x and put 4 inside it
• $ y=abc : create variable y and put “abc” inside it
• $ z=x : create variable z and put ‘x’ inside it, not value of x
• $ z=$x : create variable z and put value of x inside it
• $ set : display all declared variables (Built-in and user defined)
• $ export x : export variable x to child process
Environment variables
32
Process management
33
 CTRL+Z : pause current process in the background
 $ bg : continue paused process, continue will be in the background
 $ fg : continue paused process, continue will be in the foreground
 $ jobs : display all processes that exist in the background
 $ ls –R / & : start the process in the background
Process management
34
 ps : display processes status in current shell
 ps –e : display processes status in all the system
 Ps –u name : display processes status for specific user name
 pstree : display process tree
 Pgrep text : display PID of any process contains “text” in its name
 Pgrep -l text : display PID and name of any process contains “text” in its name
Process management
35
 Process signals
• $ kill -l : display all available signals
• $ man –s3head signal : display manual for signals
• $ kill -2 pid1 pid2 : send signal 2 to processes with IDs pid1 and pid2
• $ kill pid : send default signal which is signal 15 (terminate)
• $ pkill pname : send signal to any process contains “pname” in its name
• Default action for some signals:
 Signal 9: kill immediately
 Signal 15: terminate (not mandatory to end process)
 Signal 2: interrupt
Process management
36
Linux shell scripting
37
 Shell scripting
• Shell scripting is an interpreted language executed line by line during
runtime so it is slower than other languages like C for example.
• To execute a shell script, it should have rw (read-write) permissions.
• To add rw permissions to script, after creating the script:
$ chmod u+rx scriptname
Linux shell scripting
38
 Arrays
• Arr[5]=hello : create array called Arr, and store at index 5 new element
and make its value equals “hello”
• Echo ${Arr[*]} : will print > hello
• Arr[3]=23 : store at index 3 new element and make its value equals 23
• Arr[100]=abc : store at index 100 new element and make its value equals
“abc”
• Echo ${Arr[*]} : will print > 23 hello abc
• Echo ${#Arr[*]} : display number of elements in Arr which is 3 now
Linux shell scripting
39
 Command substitution
• Y=`ls` : Y will be the result of executing ls command
• Y=$(ls) : same as previous example
 Arithmetic operations
• Y=5;z=10
• Echo $(($Y+$z)) : will print 15
• Echo 5+10 | bc : same as previous example
Linux shell scripting
40
 Notes
• #!/bin/shellname: written at the beginning of the script to decide which
shell will be used to run the script
• Ex. #!/bin/bash
• $# : variable contains number of arguments sent to script
• $* : variable contains values of all arguments sent to script
• $1 : variable contains value of first argument sent to script
• $2 : variable contains value of second argument sent to script
• $0 : variable contains script name
Linux shell scripting
41
 sed command
• sed command filename: reads line from file, executes command on it,
prints line after command execution, repeats for all lines.
• sed ‘p’ /etc/passwd : will print each line twice of file /etc/passwd
• sed ‘3p’ /etc/passwd : will print each line once, except line 3 will be
printed twice.
• sed ‘3p;10p’ /etc/passwd : will print each line once, except line 3 and line
10 will be printed twice.
• sed ‘3,10p’ /etc/passwd : will print each line once, except from line 3 to
line 10 will be printed twice.
• sed –n ‘3,10p’ /etc/passwd : will print only line 3 to 10 one time.
Linux shell scripting
42
 sed command
• sed –n ‘/bin/p’ /etc/passwd : will print only lines containing bin keyword.
• sed –n ‘/^bin/p’ /etc/passwd : will print only lines containing bin keyword
at the start of the line.
Linux shell scripting
43
 Flow control for integers : returns Zero if True
• test $x –eq $y : == comparator
• test $x –nq $y : != comparator
• test $x –gt $y : > comparator
• test $x –ge $y : >= comparator
• test $x –lt $y : < comparator
• test $x –le $y : <= comparator
Linux shell scripting
44
 Flow control for strings: returns Zero if True
• test $x = $y : == comparator
• test $x != $y : != comparator
• Test $x –eq $y –a $x –eq $z : x==y and x==z
Linux shell scripting
45
 If statment
if test $x –eq $y
then
echo they are equal
elif test $x –gt $y
then
echo x greater than y
else
echo x less than y
fi
Linux shell scripting
46
 While loop
while condition
do
echo newline
done
It will execute (echo newline) as long as the condition is true.
Linux shell scripting
47
 While loop
while read x
do
echo x
done < /etc/passwd
It will read each line in the file and print it.
Linux shell scripting
48
 Until loop
until condition
do
echo newline
done
It will execute (echo newline) as long as the condition is false.
Linux shell scripting
49
 Signal handling
trap “command” signalnumber
The “command” will be executed when the “signalnumber” is received.
If command is leaved empty “ “, signal will be ignored.
The only signal that can’t be ignored is signal 9 which kills the process.
Linux shell scripting
50
 Functions
Function() {
echo line
}
Function take arguments like script not like functions in c language.
Linux shell scripting
51
Mohamed AbdAllah
Embedded Systems Engineer
mohabdallah8@gmail.com
52

More Related Content

What's hot

Raspberry PI
Raspberry PIRaspberry PI
Introduction to Raspberrypi
Introduction to  RaspberrypiIntroduction to  Raspberrypi
Introduction to Raspberrypi
Iheb Ben Salem
 
Chapter 9: SCSI Drives and File Systems
Chapter 9: SCSI Drives and File SystemsChapter 9: SCSI Drives and File Systems
Chapter 9: SCSI Drives and File Systemsaskme
 
X Window System
X Window SystemX Window System
X Window System
Ron Bandes
 
Wazo Platform @ Astricon19
Wazo Platform @ Astricon19Wazo Platform @ Astricon19
Wazo Platform @ Astricon19
Frédéric Lepied
 
Embedded Software Design
Embedded Software DesignEmbedded Software Design
Embedded Software Design
Anil Kumar Pugalia
 
MPI DevCon Hsinchu City 2017: Next generation MIPI Physical Layer Design and ...
MPI DevCon Hsinchu City 2017: Next generation MIPI Physical Layer Design and ...MPI DevCon Hsinchu City 2017: Next generation MIPI Physical Layer Design and ...
MPI DevCon Hsinchu City 2017: Next generation MIPI Physical Layer Design and ...
MIPI Alliance
 
Ch05
Ch05Ch05
Regular expressions
Regular expressionsRegular expressions
Regular expressions
Ravinder Singla
 
Raspberry pi : an introduction
Raspberry pi : an introductionRaspberry pi : an introduction
Raspberry pi : an introduction
LTG Oxford
 
Lower bound
Lower boundLower bound
Lower bound
Rajendran
 
Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming
KrishnaMildain
 
Android animations
Android animationsAndroid animations
Android animations
Kumar
 
Raspberry pi
Raspberry pi Raspberry pi
Raspberry pi
ABHIJITPATRA23
 
Hdmi
HdmiHdmi
User management
User managementUser management
User management
Mufaddal Haidermota
 
Practical Malware Analysis: Ch 5: IDA Pro
Practical Malware Analysis: Ch 5: IDA ProPractical Malware Analysis: Ch 5: IDA Pro
Practical Malware Analysis: Ch 5: IDA Pro
Sam Bowne
 

What's hot (20)

Raspberry PI
Raspberry PIRaspberry PI
Raspberry PI
 
Introduction to Raspberrypi
Introduction to  RaspberrypiIntroduction to  Raspberrypi
Introduction to Raspberrypi
 
Chapter 9: SCSI Drives and File Systems
Chapter 9: SCSI Drives and File SystemsChapter 9: SCSI Drives and File Systems
Chapter 9: SCSI Drives and File Systems
 
X Window System
X Window SystemX Window System
X Window System
 
Ch03 system administration
Ch03 system administration Ch03 system administration
Ch03 system administration
 
Wazo Platform @ Astricon19
Wazo Platform @ Astricon19Wazo Platform @ Astricon19
Wazo Platform @ Astricon19
 
Linux File System
Linux File SystemLinux File System
Linux File System
 
Embedded Software Design
Embedded Software DesignEmbedded Software Design
Embedded Software Design
 
MPI DevCon Hsinchu City 2017: Next generation MIPI Physical Layer Design and ...
MPI DevCon Hsinchu City 2017: Next generation MIPI Physical Layer Design and ...MPI DevCon Hsinchu City 2017: Next generation MIPI Physical Layer Design and ...
MPI DevCon Hsinchu City 2017: Next generation MIPI Physical Layer Design and ...
 
Ch05
Ch05Ch05
Ch05
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Raspberry pi : an introduction
Raspberry pi : an introductionRaspberry pi : an introduction
Raspberry pi : an introduction
 
Lower bound
Lower boundLower bound
Lower bound
 
Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming
 
Android animations
Android animationsAndroid animations
Android animations
 
Putty
PuttyPutty
Putty
 
Raspberry pi
Raspberry pi Raspberry pi
Raspberry pi
 
Hdmi
HdmiHdmi
Hdmi
 
User management
User managementUser management
User management
 
Practical Malware Analysis: Ch 5: IDA Pro
Practical Malware Analysis: Ch 5: IDA ProPractical Malware Analysis: Ch 5: IDA Pro
Practical Malware Analysis: Ch 5: IDA Pro
 

Viewers also liked

Raspberry Pi - Lecture 4 Hardware Interfacing Special Cases
Raspberry Pi - Lecture 4 Hardware Interfacing Special CasesRaspberry Pi - Lecture 4 Hardware Interfacing Special Cases
Raspberry Pi - Lecture 4 Hardware Interfacing Special Cases
Mohamed Abdallah
 
Raspberry Pi - Lecture 3 Embedded Communication Protocols
Raspberry Pi - Lecture 3 Embedded Communication ProtocolsRaspberry Pi - Lecture 3 Embedded Communication Protocols
Raspberry Pi - Lecture 3 Embedded Communication Protocols
Mohamed Abdallah
 
Raspberry Pi - Lecture 5 Python for Raspberry Pi
Raspberry Pi - Lecture 5 Python for Raspberry PiRaspberry Pi - Lecture 5 Python for Raspberry Pi
Raspberry Pi - Lecture 5 Python for Raspberry Pi
Mohamed Abdallah
 
Raspberry Pi - Lecture 1 Introduction
Raspberry Pi - Lecture 1 IntroductionRaspberry Pi - Lecture 1 Introduction
Raspberry Pi - Lecture 1 Introduction
Mohamed Abdallah
 
Raspberry Pi - Lecture 6 Working on Raspberry Pi
Raspberry Pi - Lecture 6 Working on Raspberry PiRaspberry Pi - Lecture 6 Working on Raspberry Pi
Raspberry Pi - Lecture 6 Working on Raspberry Pi
Mohamed Abdallah
 
Embedded C - Lecture 4
Embedded C - Lecture 4Embedded C - Lecture 4
Embedded C - Lecture 4
Mohamed Abdallah
 
Hardware interfacing basics using AVR
Hardware interfacing basics using AVRHardware interfacing basics using AVR
Hardware interfacing basics using AVR
Mohamed Abdallah
 
Embedded C - Lecture 3
Embedded C - Lecture 3Embedded C - Lecture 3
Embedded C - Lecture 3
Mohamed Abdallah
 
Embedded C - Lecture 2
Embedded C - Lecture 2Embedded C - Lecture 2
Embedded C - Lecture 2
Mohamed Abdallah
 
Embedded C - Lecture 1
Embedded C - Lecture 1Embedded C - Lecture 1
Embedded C - Lecture 1
Mohamed Abdallah
 
Embedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerEmbedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontroller
Gaurav Verma
 
Plc dasar
Plc dasarPlc dasar
Plc dasar
sextrolol
 
Embedded c & working with avr studio
Embedded c & working with avr studioEmbedded c & working with avr studio
Embedded c & working with avr studioNitesh Singh
 
Emertxe : Linux training portfolio
Emertxe : Linux training portfolioEmertxe : Linux training portfolio
Emertxe : Linux training portfolio
Emertxe Information Technologies Pvt Ltd
 
Emertxe : Training portfolio
Emertxe : Training portfolioEmertxe : Training portfolio
Emertxe : Training portfolio
Emertxe Information Technologies Pvt Ltd
 
Interfacing rs232
Interfacing rs232Interfacing rs232
Interfacing rs232PRADEEP
 
Resume Preparation - Workshop
Resume Preparation - WorkshopResume Preparation - Workshop
Resume Preparation - Workshop
Emertxe Information Technologies Pvt Ltd
 
Advance Microcontroller AVR
Advance Microcontroller AVRAdvance Microcontroller AVR
Advance Microcontroller AVR
Daksh Raj Chopra
 
Raspberrypi
RaspberrypiRaspberrypi
Raspberrypi
Prasanth V
 
Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)
Dhaval Kaneria
 

Viewers also liked (20)

Raspberry Pi - Lecture 4 Hardware Interfacing Special Cases
Raspberry Pi - Lecture 4 Hardware Interfacing Special CasesRaspberry Pi - Lecture 4 Hardware Interfacing Special Cases
Raspberry Pi - Lecture 4 Hardware Interfacing Special Cases
 
Raspberry Pi - Lecture 3 Embedded Communication Protocols
Raspberry Pi - Lecture 3 Embedded Communication ProtocolsRaspberry Pi - Lecture 3 Embedded Communication Protocols
Raspberry Pi - Lecture 3 Embedded Communication Protocols
 
Raspberry Pi - Lecture 5 Python for Raspberry Pi
Raspberry Pi - Lecture 5 Python for Raspberry PiRaspberry Pi - Lecture 5 Python for Raspberry Pi
Raspberry Pi - Lecture 5 Python for Raspberry Pi
 
Raspberry Pi - Lecture 1 Introduction
Raspberry Pi - Lecture 1 IntroductionRaspberry Pi - Lecture 1 Introduction
Raspberry Pi - Lecture 1 Introduction
 
Raspberry Pi - Lecture 6 Working on Raspberry Pi
Raspberry Pi - Lecture 6 Working on Raspberry PiRaspberry Pi - Lecture 6 Working on Raspberry Pi
Raspberry Pi - Lecture 6 Working on Raspberry Pi
 
Embedded C - Lecture 4
Embedded C - Lecture 4Embedded C - Lecture 4
Embedded C - Lecture 4
 
Hardware interfacing basics using AVR
Hardware interfacing basics using AVRHardware interfacing basics using AVR
Hardware interfacing basics using AVR
 
Embedded C - Lecture 3
Embedded C - Lecture 3Embedded C - Lecture 3
Embedded C - Lecture 3
 
Embedded C - Lecture 2
Embedded C - Lecture 2Embedded C - Lecture 2
Embedded C - Lecture 2
 
Embedded C - Lecture 1
Embedded C - Lecture 1Embedded C - Lecture 1
Embedded C - Lecture 1
 
Embedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerEmbedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontroller
 
Plc dasar
Plc dasarPlc dasar
Plc dasar
 
Embedded c & working with avr studio
Embedded c & working with avr studioEmbedded c & working with avr studio
Embedded c & working with avr studio
 
Emertxe : Linux training portfolio
Emertxe : Linux training portfolioEmertxe : Linux training portfolio
Emertxe : Linux training portfolio
 
Emertxe : Training portfolio
Emertxe : Training portfolioEmertxe : Training portfolio
Emertxe : Training portfolio
 
Interfacing rs232
Interfacing rs232Interfacing rs232
Interfacing rs232
 
Resume Preparation - Workshop
Resume Preparation - WorkshopResume Preparation - Workshop
Resume Preparation - Workshop
 
Advance Microcontroller AVR
Advance Microcontroller AVRAdvance Microcontroller AVR
Advance Microcontroller AVR
 
Raspberrypi
RaspberrypiRaspberrypi
Raspberrypi
 
Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)
 

Similar to Raspberry Pi - Lecture 2 Linux OS

Basics of Unix Adminisration
Basics  of Unix AdminisrationBasics  of Unix Adminisration
Basics of Unix Adminisration
Venkateswarlu Malleboina
 
LINUX_admin_commands.pptx
LINUX_admin_commands.pptxLINUX_admin_commands.pptx
LINUX_admin_commands.pptx
GuhanSenthil2
 
8.1.intro unix
8.1.intro unix8.1.intro unix
8.1.intro unixsouthees
 
Unix fundamentals and_shell scripting
Unix fundamentals and_shell scriptingUnix fundamentals and_shell scripting
Unix fundamentals and_shell scripting
Ganesh Bhosale
 
Unix Shell Script - 2 Days Session.pptx
Unix Shell Script - 2 Days Session.pptxUnix Shell Script - 2 Days Session.pptx
Unix Shell Script - 2 Days Session.pptx
Rajesh Kumar
 
Unix
UnixUnix
Linux file commands and shell scripts
Linux file commands and shell scriptsLinux file commands and shell scripts
Linux file commands and shell scripts
PrashantTechment
 
Linux And perl
Linux And perlLinux And perl
Linux And perl
Sagar Kumar
 
An Introduction to Linux
An Introduction to LinuxAn Introduction to Linux
An Introduction to LinuxDimas Prasetyo
 
Linux powerpoint
Linux powerpointLinux powerpoint
Linux powerpoint
bijanshr
 
Unix_QT.ppsx
Unix_QT.ppsxUnix_QT.ppsx
Unix_QT.ppsx
vamsikrishna204239
 
Unix_QT.ppsx
Unix_QT.ppsxUnix_QT.ppsx
Unix_QT.ppsx
vamsikrishna204239
 
Online Training in Unix Linux Shell Scripting in Hyderabad
Online Training in Unix Linux Shell Scripting in HyderabadOnline Training in Unix Linux Shell Scripting in Hyderabad
Online Training in Unix Linux Shell Scripting in HyderabadRavikumar Nandigam
 
Introduction to Unix
Introduction to UnixIntroduction to Unix
Introduction to UnixSudharsan S
 
Directories description
Directories descriptionDirectories description
Directories description
Dr.M.Karthika parthasarathy
 
Presentation for RHCE in linux
Presentation  for  RHCE in linux Presentation  for  RHCE in linux
Presentation for RHCE in linux Kuldeep Tiwari
 
2. UNIX OS System Architecture easy.pptx
2. UNIX OS System Architecture easy.pptx2. UNIX OS System Architecture easy.pptx
2. UNIX OS System Architecture easy.pptx
Priyadarshini648418
 
Linux commands and file structure
Linux commands and file structureLinux commands and file structure
Linux commands and file structure
Sreenatha Reddy K R
 
Introduction to the linux command line.pdf
Introduction to the linux command line.pdfIntroduction to the linux command line.pdf
Introduction to the linux command line.pdf
CesleySCruz
 

Similar to Raspberry Pi - Lecture 2 Linux OS (20)

Basics of Unix Adminisration
Basics  of Unix AdminisrationBasics  of Unix Adminisration
Basics of Unix Adminisration
 
LINUX_admin_commands.pptx
LINUX_admin_commands.pptxLINUX_admin_commands.pptx
LINUX_admin_commands.pptx
 
8.1.intro unix
8.1.intro unix8.1.intro unix
8.1.intro unix
 
Unix fundamentals and_shell scripting
Unix fundamentals and_shell scriptingUnix fundamentals and_shell scripting
Unix fundamentals and_shell scripting
 
Unix Shell Script - 2 Days Session.pptx
Unix Shell Script - 2 Days Session.pptxUnix Shell Script - 2 Days Session.pptx
Unix Shell Script - 2 Days Session.pptx
 
Unix
UnixUnix
Unix
 
Linux file commands and shell scripts
Linux file commands and shell scriptsLinux file commands and shell scripts
Linux file commands and shell scripts
 
Linux And perl
Linux And perlLinux And perl
Linux And perl
 
An Introduction to Linux
An Introduction to LinuxAn Introduction to Linux
An Introduction to Linux
 
Linux basic commands
Linux basic commandsLinux basic commands
Linux basic commands
 
Linux powerpoint
Linux powerpointLinux powerpoint
Linux powerpoint
 
Unix_QT.ppsx
Unix_QT.ppsxUnix_QT.ppsx
Unix_QT.ppsx
 
Unix_QT.ppsx
Unix_QT.ppsxUnix_QT.ppsx
Unix_QT.ppsx
 
Online Training in Unix Linux Shell Scripting in Hyderabad
Online Training in Unix Linux Shell Scripting in HyderabadOnline Training in Unix Linux Shell Scripting in Hyderabad
Online Training in Unix Linux Shell Scripting in Hyderabad
 
Introduction to Unix
Introduction to UnixIntroduction to Unix
Introduction to Unix
 
Directories description
Directories descriptionDirectories description
Directories description
 
Presentation for RHCE in linux
Presentation  for  RHCE in linux Presentation  for  RHCE in linux
Presentation for RHCE in linux
 
2. UNIX OS System Architecture easy.pptx
2. UNIX OS System Architecture easy.pptx2. UNIX OS System Architecture easy.pptx
2. UNIX OS System Architecture easy.pptx
 
Linux commands and file structure
Linux commands and file structureLinux commands and file structure
Linux commands and file structure
 
Introduction to the linux command line.pdf
Introduction to the linux command line.pdfIntroduction to the linux command line.pdf
Introduction to the linux command line.pdf
 

Recently uploaded

一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
ssuser36d3051
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
zwunae
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
ChristineTorrepenida1
 
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
obonagu
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 
Fundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptxFundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptx
manasideore6
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
Kamal Acharya
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 

Recently uploaded (20)

一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
 
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 
Fundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptxFundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptx
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 

Raspberry Pi - Lecture 2 Linux OS

  • 1. Prepared by: Mohamed AbdAllah Raspberry pi interfacing Lecture 2: Linux OS 1
  • 2. Linux OS Agenda  Introduction to Linux OS.  Linux file system hierarchy.  Linux commands.  Files permissions.  Input-Output redirection.  Environment variables.  Process management.  Linux shell scripting. 2
  • 4. Introduction to Linux operating system 4
  • 5.  What is Linux operating system ? • In 1983, Richard Stallman, founder of the Free Software Foundation, set forth plans of a complete Unix-like operating system, called GNU, composed entirely of free software. • By 1991 the lower level (kernel, device drivers, system-level utilities and daemons) was still mostly lacking. • In 1991, Linus Torvalds released the first version of the Linux kernel. Early Linux developers ported GNU code, including the GNU C Compiler, to the kernel. The free software community adopted the use of the Linux kernel as the missing kernel for the GNU operating system. Introduction to Linux operating system 5
  • 6.  Linux OS main components Introduction to Linux operating system 6
  • 7.  Linux features • Open Source: Linux source code is freely available and it is community based development project. Multiple teams works in collaboration to enhance the capability of Linux operating system and it is continuously evolving. • Multi-User: Linux is a multiuser system means multiple users can access system resources like memory, ram, application programs at same time. • Multiprogramming: Linux is a multiprogramming system means multiple applications can run at same time. • Hierarchical File System: Linux provides a standard file structure in which system files, user files are arranged. Introduction to Linux operating system 7
  • 8.  Linux features • Shell: Linux provides a special interpreter program which can be used to execute commands of the operating system. It can be used to do various types of operations, call application programs etc. • Security: Linux provides user security using authentication features like password protection, controlled access to specific files, encryption of data. Introduction to Linux operating system 8
  • 9. Introduction to Linux operating system 9
  • 10. Linux file system hierarchy 10
  • 11. Linux file system hierarchy 11
  • 12.  /etc • Contains systems configurations files.  /usr/bin • Contains commands for all users.  /usr/sbin • Contains commands for root user.  /dev • Contains hardware devices tree.  /home/username • Home directory for user of name “username”. Linux file system hierarchy 12
  • 13. Linux file system hierarchy  /etc/passwd • Contains one line for each user account, with seven fields delimited by colons (“:”). These fields are: [login name : encrypted password : user ID : group ID : comment : home dir : default shell]  /etc/shadow • Contains the password information for the system’s accounts and optional aging information. • Each line contains 9 fields, separated by colons (“:”), in the following order: [login name : encrypted password : last change : min pass age : max pass age : pass warning period : pass inactivity period : account expiration date : reserved field] 13
  • 14. Linux file system hierarchy  /etc/group • Contains the groups on the system with one line per group.. • Each line contains 4 fields, separated by colons (“:”), in the following order: [group name : password : group ID : members usernames separated by commas] 14
  • 16.  Command format Command option argument Command: required command to execute. Option: options given to command. Argument: which the command is executed on. Linux commands 16
  • 17.  Commands examples $ ls /etc : list directory content $ ls –l /etc : long list option $ ls –t /etc : sort with time $ ls –l –t /etc : long list and sort with time $ cal : calendar of current month $ cal 2014 : calendar of 2014 $ cal 5 2014 : calendar of 5/2014 $ alias display=“ls –l” : create an alias $ unalias display : delete an alias Linux commands 17
  • 18.  Commands examples $ man command : get manual for any command $ man –k : search in manual by keyword $ man –s1 : search in section 1 (s1 for user commands, s4 for file formats) $ pwd : print working directory $ cd /etc : change directory to /etc $ cd .. : change directory to parent directory $ cd : change directory to home directory $ cd ~ : same as previous Linux commands 18
  • 19.  Commands examples $ mkdir dirname : make new directory with name “dirname” $ mkdir /dir1/dir2 : make new directory and create any parent directory $ rmdir : remove empty directory $ touch : create new empty file $ rm : remove file $ rm –r : remove folder with all its content $ find startPoint criteria itemToSearchFor $ grep pattern files : search for a pattern in files $ echo Text : print Text to screen Linux commands 19
  • 20.  Commands examples $ cat : display file content $ more : display file content according to screen size $ less : same as more, and allows backward movement $ head -3 : display first 3 lines of a file $ head : display by default 10 lines $ tail -2 : display 2 lines from the file end $ sort –k1 –t: -r /etc/passwd : sort file according to field 1, with field separator of : in descending order according to ASCII $ sort –nk3 : sort in numeric order $ sort –o output file : save result in same file Linux commands 20
  • 21.  Commands examples $ wc : display count of lines, words and characters of a file $ wc –l : display number of lines $ wc –w : display number of words $ wc –c : display number of characters $ cp source destination : copy file from source to destination $ cp –r : copy directory $ mv : move file or directory $ mv -i: ask for overwrite if exists Linux commands 21
  • 22.  Commands examples $ date : display current day date $ who : display logged in users $ df : display all disk partitions with size in blocks of 512 bytes $ df – k : size in Kbytes $ df –h : size in Gbytes $ cut –f1,7 –d: /etc/passwd : display fields 1 and 7 with separator : in file /etc/passwd $ cut –f3-5 –d: /etc/passwd : from field 3 to field 5 $ cut –f3- –d: /etc/passwd : from field 3 to the end $ cut –f-3 –d: /etc/passwd : from first field to field 3 Linux commands 22
  • 23.  ~ : home directory  * : any combination (alpha-num)  ? : one character (alpha-num)  [ab3sc] : one character of this set  [a-e0-4] : one character in this ranges  $ ls *.[abc0-5] : list directory content which names contains any set of characters followed by ‘dot .’ then followed by one character of (a, b, c, 0, 1, 2, 3, 4, 5) File name expansion 23
  • 25. $ ls –l /etc/passwd -rw-r- -r-- 1 root root 988 ….. …. -rw-r- -r-- : file type, owner permissions, group permissions, other permissions 1 : number of hard links Root : owner Roor : group 988 : size Creation time and file name $ ls –d /etc/ : list directory permissions Files permissions 25
  • 26. Files permissions Permission On file On directory R Read file content List files W Modify file content Modify directory from outside X Execute file Change to directory or access any file inside it $ chmod u+x : add execute permission to owner $ chmod u=rx,g=-,o=x : make owner read execute, group none, other execute only $ chmod 7 file1 : change permissions to be 007 $ umask 777 : set umask to be 111 to set default permissions to be complement of umask $ umask : display current default permissions 26
  • 28. $ ls –l /etc/passwd 1> file1 Redirect output list to file “file1” 1 > output redirection, overwrite 1 >> append output 2 > error redirection $ Cat < file : input redirection Input-Output redirection 28
  • 29. $ command1 | command 2 Pipeline command 1 output to be as input to command 2 $ cut –d: -f1,3 /etc/passwd | sort –t: -nk2 Pipelining 29
  • 31.  Built in variables: • $ echo $PWD : display value of $PWD that saves current path • $HOME : save home directory • $LOGNAME : save login name • $PS1 : shell command prompt • $PS2 : appears when command didn’t end yet • $PS3 : appears when user is asked to enter a choice • $PATH : contains all paths that shell uses to search for commands • $$ : process ID (PID) of current shell Environment variables 31
  • 32.  User defined variables: • $ x=4 : create variable x and put 4 inside it • $ y=abc : create variable y and put “abc” inside it • $ z=x : create variable z and put ‘x’ inside it, not value of x • $ z=$x : create variable z and put value of x inside it • $ set : display all declared variables (Built-in and user defined) • $ export x : export variable x to child process Environment variables 32
  • 34.  CTRL+Z : pause current process in the background  $ bg : continue paused process, continue will be in the background  $ fg : continue paused process, continue will be in the foreground  $ jobs : display all processes that exist in the background  $ ls –R / & : start the process in the background Process management 34
  • 35.  ps : display processes status in current shell  ps –e : display processes status in all the system  Ps –u name : display processes status for specific user name  pstree : display process tree  Pgrep text : display PID of any process contains “text” in its name  Pgrep -l text : display PID and name of any process contains “text” in its name Process management 35
  • 36.  Process signals • $ kill -l : display all available signals • $ man –s3head signal : display manual for signals • $ kill -2 pid1 pid2 : send signal 2 to processes with IDs pid1 and pid2 • $ kill pid : send default signal which is signal 15 (terminate) • $ pkill pname : send signal to any process contains “pname” in its name • Default action for some signals:  Signal 9: kill immediately  Signal 15: terminate (not mandatory to end process)  Signal 2: interrupt Process management 36
  • 38.  Shell scripting • Shell scripting is an interpreted language executed line by line during runtime so it is slower than other languages like C for example. • To execute a shell script, it should have rw (read-write) permissions. • To add rw permissions to script, after creating the script: $ chmod u+rx scriptname Linux shell scripting 38
  • 39.  Arrays • Arr[5]=hello : create array called Arr, and store at index 5 new element and make its value equals “hello” • Echo ${Arr[*]} : will print > hello • Arr[3]=23 : store at index 3 new element and make its value equals 23 • Arr[100]=abc : store at index 100 new element and make its value equals “abc” • Echo ${Arr[*]} : will print > 23 hello abc • Echo ${#Arr[*]} : display number of elements in Arr which is 3 now Linux shell scripting 39
  • 40.  Command substitution • Y=`ls` : Y will be the result of executing ls command • Y=$(ls) : same as previous example  Arithmetic operations • Y=5;z=10 • Echo $(($Y+$z)) : will print 15 • Echo 5+10 | bc : same as previous example Linux shell scripting 40
  • 41.  Notes • #!/bin/shellname: written at the beginning of the script to decide which shell will be used to run the script • Ex. #!/bin/bash • $# : variable contains number of arguments sent to script • $* : variable contains values of all arguments sent to script • $1 : variable contains value of first argument sent to script • $2 : variable contains value of second argument sent to script • $0 : variable contains script name Linux shell scripting 41
  • 42.  sed command • sed command filename: reads line from file, executes command on it, prints line after command execution, repeats for all lines. • sed ‘p’ /etc/passwd : will print each line twice of file /etc/passwd • sed ‘3p’ /etc/passwd : will print each line once, except line 3 will be printed twice. • sed ‘3p;10p’ /etc/passwd : will print each line once, except line 3 and line 10 will be printed twice. • sed ‘3,10p’ /etc/passwd : will print each line once, except from line 3 to line 10 will be printed twice. • sed –n ‘3,10p’ /etc/passwd : will print only line 3 to 10 one time. Linux shell scripting 42
  • 43.  sed command • sed –n ‘/bin/p’ /etc/passwd : will print only lines containing bin keyword. • sed –n ‘/^bin/p’ /etc/passwd : will print only lines containing bin keyword at the start of the line. Linux shell scripting 43
  • 44.  Flow control for integers : returns Zero if True • test $x –eq $y : == comparator • test $x –nq $y : != comparator • test $x –gt $y : > comparator • test $x –ge $y : >= comparator • test $x –lt $y : < comparator • test $x –le $y : <= comparator Linux shell scripting 44
  • 45.  Flow control for strings: returns Zero if True • test $x = $y : == comparator • test $x != $y : != comparator • Test $x –eq $y –a $x –eq $z : x==y and x==z Linux shell scripting 45
  • 46.  If statment if test $x –eq $y then echo they are equal elif test $x –gt $y then echo x greater than y else echo x less than y fi Linux shell scripting 46
  • 47.  While loop while condition do echo newline done It will execute (echo newline) as long as the condition is true. Linux shell scripting 47
  • 48.  While loop while read x do echo x done < /etc/passwd It will read each line in the file and print it. Linux shell scripting 48
  • 49.  Until loop until condition do echo newline done It will execute (echo newline) as long as the condition is false. Linux shell scripting 49
  • 50.  Signal handling trap “command” signalnumber The “command” will be executed when the “signalnumber” is received. If command is leaved empty “ “, signal will be ignored. The only signal that can’t be ignored is signal 9 which kills the process. Linux shell scripting 50
  • 51.  Functions Function() { echo line } Function take arguments like script not like functions in c language. Linux shell scripting 51
  • 52. Mohamed AbdAllah Embedded Systems Engineer mohabdallah8@gmail.com 52