SlideShare a Scribd company logo
1 of 52
Download to read offline
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

What's hot (20)

Commandes usuelle linux
Commandes usuelle   linuxCommandes usuelle   linux
Commandes usuelle linux
 
Basic commands of linux
Basic commands of linuxBasic commands of linux
Basic commands of linux
 
Course 102: Lecture 22: Package Management
Course 102: Lecture 22: Package Management Course 102: Lecture 22: Package Management
Course 102: Lecture 22: Package Management
 
File permission in linux
File permission in linuxFile permission in linux
File permission in linux
 
Linux Programming
Linux ProgrammingLinux Programming
Linux Programming
 
Linux Directory Structure
Linux Directory StructureLinux Directory Structure
Linux Directory Structure
 
Linux User Management
Linux User ManagementLinux User Management
Linux User Management
 
Rh124 red-hat-system-administration-i
Rh124 red-hat-system-administration-iRh124 red-hat-system-administration-i
Rh124 red-hat-system-administration-i
 
Linux operating system ppt
Linux operating system pptLinux operating system ppt
Linux operating system ppt
 
Porting a new architecture (NDS32) to open wrt project
Porting a new architecture (NDS32) to open wrt projectPorting a new architecture (NDS32) to open wrt project
Porting a new architecture (NDS32) to open wrt project
 
Linux systems - Linux Commands and Shell Scripting
Linux systems - Linux Commands and Shell ScriptingLinux systems - Linux Commands and Shell Scripting
Linux systems - Linux Commands and Shell Scripting
 
Shell programming
Shell programmingShell programming
Shell programming
 
Linux Run Level
Linux Run LevelLinux Run Level
Linux Run Level
 
Samba server
Samba serverSamba server
Samba server
 
Yum (Linux)
Yum (Linux) Yum (Linux)
Yum (Linux)
 
Report on car racing game for android
Report on car racing game for androidReport on car racing game for android
Report on car racing game for android
 
Linux File System
Linux File SystemLinux File System
Linux File System
 
Linux kernel modules
Linux kernel modulesLinux kernel modules
Linux kernel modules
 
Introduction to Shell script
Introduction to Shell scriptIntroduction to Shell script
Introduction to Shell script
 
Linux file system
Linux file systemLinux file system
Linux file system
 

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 CasesMohamed 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 ProtocolsMohamed 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 PiMohamed Abdallah
 
Raspberry Pi - Lecture 1 Introduction
Raspberry Pi - Lecture 1 IntroductionRaspberry Pi - Lecture 1 Introduction
Raspberry Pi - Lecture 1 IntroductionMohamed 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 PiMohamed Abdallah
 
Hardware interfacing basics using AVR
Hardware interfacing basics using AVRHardware interfacing basics using AVR
Hardware interfacing basics using AVRMohamed 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 microcontrollerGaurav Verma
 
Embedded c & working with avr studio
Embedded c & working with avr studioEmbedded c & working with avr studio
Embedded c & working with avr studioNitesh Singh
 
Interfacing rs232
Interfacing rs232Interfacing rs232
Interfacing rs232PRADEEP
 
Advance Microcontroller AVR
Advance Microcontroller AVRAdvance Microcontroller AVR
Advance Microcontroller AVRDaksh Raj Chopra
 
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

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

Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoordharasingh5698
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfRagavanV2
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptNANDHAKUMARA10
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 

Recently uploaded (20)

Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 

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