Programming in Linux: Team Emertxe
Programming in Linux: Team Emertxe
Team Emertxe
Linux Introduction
Let us ponder…
What exactly is an Operating System (OS)?
Freedom of
software
Freedom of Freedom of
use redistribute
Freedom of Freedom of
modify copy
How it all started?
With GNU (GNU is not UNIX)
Linux Kernel got licensed under GPL, which laid strong platform for the
success of Open Source
Rest is history!
How it evolved?
Multiple Linux distributions started emerging around the Kernel
Customization
Where it stands now?
OS Databases Server/Cloud Enterprise
OSS Freeware
Users have the right to access & Freeware is usually distributed in a
modify the source codes form of binary at ‘Free of Charge’,
In case original programmer but does not open source codes
disappeared, users & developer itself.
group of the S/W usually keep its Developer of freeware could
support to the S/W. abandon development at any time
OSS usually has the strong users & and then final version will be the
developers group that manage and last version of the freeware. No
maintain the project enhancements will be made by
others.
Possibility of changing its licensing
policy
GPL
Basic rights under the GPL – access to source code,
right to make derivative works
Reciprocity/Copy-left
Multi-user
Multiprocessing
Protected Memory
/
Essentilal shared libraries and kernal modules
/media/ Mount point for removable media
/mnt/ Mount point for temporarily mounted file systems
/opt/ Add-on application software package
/sbin/ User specific system binaries
/tmp/ Temporary files
/usr/ Multi-user utilities and applications
/var/ Variable file (logs)
/root/ Home directory for root user
/proc/ Virtual file system documenting kernel and process status
x86 Booting
Kernel structure
Hardware Controllers: This subsystem is comprised of all
the possible physical devices in a Linux installation
Linux Kernel: The kernel abstracts and mediates access
to the hardware resources, including the CPU. A kernel is
the core of the operating system
O/S Services: These are services that are typically
considered part of the operating system (e.g. shell)
User Applications: The set of applications in use on a
particular Linux system. (e.g. web-browser)
Kernel structure
Command Line Interface
Command Line
Interface
• CLI
• Textual mode
• Executes requested command
• GUI
• Mouse, keypad
The Shell
What is a shell?
Different types of shells
• Login-shell
• Non-login shell
• Sh
• Bash
• Ksh
• Csh
Hands-on:
• echo $0
• cat /etc/shells
How Shell Invokes
Input (ls)
Shell
Command Meaning
ls Lists all the files
pwd Gives present working directory
cd Change directory
man Gives information about command
exit Exits from the shell
which Shows full path of command
Shell: Built-in Commands
vi or vim
To open a file
$ vi <filename> or vim <filename>
VIsual editor…
vi opens a file in command mode while starting
The power of vi comes from its 3 modes
• Escape mode (Command mode)
Search mode
File mode
• Editing mode
Insert mode
Append mode
Open mode
Replace mode
• Visual mode.
Cursor Movement
You will clearly need to move the cursor around your file.
You can move the cursor in command mode.
vi has many different cursor movement commands. The four
basic keys appear below
Character Meaning
k Move up one line
h Move one character to the left
l Move one character to the right
j Move down one line
Yes! Arrow keys also do work. But these makes typing faster
Basic vi commands
How to exit
Command Meaning
:q Quit without saving
:wq Close the file with saving
:q! Quit the file forcefully without saving
Command Meaning
:%s/first/sec Replaces the first by second every where in the file
%s/old/new/gc For all lines in a file, find string “old" and replace with
string “new" for each instance on a line
:e filename Open another file without closing the current
set all Display all settings of your session
:r filename Reads file named filename in place
Editing Modes...
Command Mode name Insertion point
a Append Just after the current character
A Append End of the current line
i Insert Just before the current character
I Insert Beginning of the current line
o Open New line below the current line
O Open New line above the current line
Editing Text
Deleting Text Sometimes you will want to delete some
of the text you are editing.
To do so, first move the cursor so that it covers the first
character of the group you want to delete, then type
the desired command from the table below.
Command Meaning
dd For deleting a line
ndd For deleting a n lines
x To delete a single character
shift + d Delete contents of line after cursor
dw Delete word
ndw Delete ‘n’ words
Some Useful
Shortcuts
Command Meaning
shift-g Go to last line in file
shift-j Joining the two lines
. Repeat the previous command executed
ctrl+a Increment number under the cursor
ctrl+x Decrements numbers under the cursor
Visual Mode
Visual Mode
Visual mode helps to visually select some text, may
be seen as a sub mode of the command mode to switch
from the command mode to the visual mode type one of
• ctrl+v Go's to visual block mode.
• Only v for visual mode
• d or y Delete or Yank selected text
• I or A Insert or Append text in all lines (visual block
only)
File related commands
File redirection
•- • Plain text
•d • Directory
•c • Character driver
•b • Block driver
•l • Link file
•s • Socket file
• = or p • FIFO file
File permissions
r or 4 -r--r--r-- Read
w or 2 --w--w--w- Write
x or 1 ---x--x--x Execute
rwx rwx rwx
421 421 421
user group others
Changing the File Permissions
$ chmod – Change file permessions
$ chown – Change file owner
$ chmod [ ug+r, 746 ] file.txt
$ chown -R user:group [ filename | dir ]
Linux kernel: Subsystems
Subsystems
Logically the system call and regular interrupt follow the same flow of steps. The
source (I/O device v/s user program) is very different for both of them. Since
system call is generated by user program they are called as ‘Soft interrupts’ or
‘traps’
Stay connected
About us: Emertxe is India’s one of the top IT finishing schools & self learning kits
provider. Our primary focus is on Embedded with diversification focus on Java,
Oracle and Android areas