SlideShare a Scribd company logo
1 of 81
Download to read offline
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Linux environment
BCA – VI
Paper Code 306
Introduction: What is Unix?
• An operating system
• Developed at AT&T Bell Labs in the 1960’s
• Command Line Interpreter
• GUIs (Window systems) are now available
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Introduction: Unix vs. Linux
• Unix was the predecessor of Linux
• Linux is a variant of Unix
– So is Mac OS X, so much of this tutorial applies to
Macs as well
• Linux is open source
• Most of the machines you’ll use in the
Bioinformatics program are running the Linux
OS
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Introduction: Why Unix/Linux?
• Linux is free
• It’s fully customizable
• It’s stable (i.e. it almost never crashes)
• These characteristics make it an ideal OS for
programmers and scientists
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Connecting to a Unix/Linux system
• Open up a terminal:
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Connecting to a Unix/Linux system
• Open up a terminal:
The “prompt”
The current directory (“path”)
The host
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
What exactly is a “shell”?
• After logging in, Linux/Unix starts another program
called the shell
• The shell interprets commands the user types and
manages their execution
• The shell communicates with the internal part of the operating
system called the kernel
• The most popular shells are: tcsh, csh, korn, and bash
• The differences are most times subtle
• For this tutorial, we are using bash
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Help!
• Whenever you need help with a command
type “man” and the command name
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Help!
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Help!
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Help!
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Unix/Linux File System
/home/john/portfolio/
/home/mary/
The Path
NOTE: Unix file names
are CASE SENSITIVE!
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: pwd
• To find your current path use “pwd”
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: cd
• To change to a specific directory use “cd”
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: cd
• “~” is the location of your home directory
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: cd
• “..” is the location of the directory below
current one
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: ls
• To list the files in the current directory use “ls”
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: ls
• ls has many options
– -l long list (displays lots of info)
– -t sort by modification time
– -S sort by size
– -h list file sizes in human readable format
– -r reverse the order
• “man ls” for more options
• Options can be combined: “ls -ltr”
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: ls -ltr
• List files by time in reverse order with long listing
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
General Syntax: *
• “*” can be used as a wildcard in unix/linux
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: mkdir
• To create a new directory use “mkdir”
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: rmdir
• To remove and empty directory use “rmdir”
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: rmdir
• To remove and empty directory use “rmdir”
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Creating files in Unix/Linux
• Requires the use of an Editor
• Various Editors:
1) nano / pico
2) vi
3) emacs
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Displaying a file
• Various ways to display a file in Unix
– cat
– less
– head
– tail
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: cat
• Dumps an entire file to standard output
• Good for displaying short, simple files
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: less
• “less” displays a file, allowing
forward/backward movement within it
– return scrolls forward one line, space one page
– y scrolls back one line, b one page
• use “/” to search for a string
• Press q to quit
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: head
• “head” displays the top part of a file
• By default it shows the first 10 lines
• -n option allows you to change that
• “head -n50 file.txt” displays the first 50 lines
of file.txt
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: head
• Here’s an example of using “head”:
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: tail
• Same as head, but shows the last lines
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
File Commands
• Copying a file: cp
• Move or rename a file: mv
• Remove a file: rm
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: cp
• To copy a file use “cp”
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: mv
• To move a file to a different location use “mv”
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: mv
• mv can also be used to rename a file
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: rm
• To remove a file use “rm”
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: rm
• To remove a file “recursively”: rm –r
• Used to remove all files and directories
• Be very careful, deletions are permanent in
Unix/Linux
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
File permissions
• Each file in Unix/Linux has an associated
permission level
• This allows the user to prevent others from
reading/writing/executing their files or
directories
• Use “ls -l filename” to find the permission
level of that file
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Permission levels
• “r” means “read only” permission
• “w” means “write” permission
• “x” means “execute” permission
– In case of directory, “x” grants permission to list
directory contents
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
File Permissions
User (you)Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
File Permissions
Group
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
File Permissions
“The World”
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: chmod
• If you own the file, you can change it’s permissions with
“chmod”
– Syntax: chmod [user/group/others/all]+[permission] [file(s)]
– Below we grant execute permission to all:
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Running a program (a.k.a. a job)
• Make sure the program has executable
permissions
• Use “./” to run the program
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Running a program: an example
• Running the sample perl script “hello_world.pl”
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Ending a program
• To end a program use “ctrl-c”. To try it:
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: ps
• To view the processes that you’re running:
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: top
• To view the CPU usage of all processes:
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: kill
• To terminate a process use “kill”
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Input/Output Redirection (“piping”)
• Programs can output to other programs
• Called “piping”
• “program_a | program_b”
– program_a’s output becomes program_b’s input
• “program_a > file.txt”
– program_a’s output is written to a file called “file.txt”
• “program_a < input.txt”
– program_a gets its input from a file called “input.txt”
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
A few examples of piping
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
A few examples of piping
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: wc
• To count the characters, words, and lines in a
file use “wc”
• The first column in the output is lines, the
second is words, and the last is characters
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
A few examples of piping
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Command: grep
• To search files in a directory for a specific
string use “grep”
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
What is a Regular Expression?
• Pattern to match all or part of a line of text
– Expressed in a formal, albeit weird, language
– For example:
^.*:Mike
matches lines that start (^) with any string (.*) and contain a colon
followed by Mike
• ^, . and * are called meta characters
– They do not represent themselves, but have other special meaning.
• :, M, i, k and e are normal characters
– The do represent themselves
55
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Where are
Regular Expressions Used?
• Special commands that “know” about them
– Vi-Uses them in searching for a string: /regexp/
• Uses them in substitite command: s/regexp/replace/sed
– Edit a file (like vi) as a filter in a pipeline
… | sed editing-commands | …
– grep , fgrep (fixed grep) , egrep (extended grep)
• Print lines of a file that match a regexp
– awk
• Process input files looking for lines that match a regexp and
processing those lines
56
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Regular expression
• A regular expression is a pattern of characters
used for describing sets of strings
• A pattern or sequence of characters
– Upper and lower case
– Digits
– Space, underscore, etc
• Metacharacters
57
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Basic Regular Expressions
• Patterns that match a single character
– All regular letters match themselves
a b z T Q 0 1 9
– . (a single dot) matches any single character except
newline.
• In awk, dot can match newline also
• (like ? in filename generation)
– A set of characters that matches any single character from
the set (just like filename generation)
[aeiou]
[a-z0-9]
[A-Za-z-]
[a-m]
58
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Metacharacter
* Matches 0 or more occurrences of the
preceding char
[…] Matches any one of characters enclosed
between the brackets.
- dash indicates a range when inside sq bkts.
[^ - negates what's inside brackets]
59
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Metacharacter (con’t)
 - backslash - escape character - just like before.
– . means match a dot
– This means  is a meta character
–  means match 
Positional indicators:
• ^ anchor to beginning of line
• $ anchor to end of line
60
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• "Some people, when confronted with a Unix
problem, think ‘I know, I’ll use sed.’ Now they
have two problems.”
-
61
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Regular expression examples
• Peach
• a*c
– cxxx, acxxx, aaacxxxx
• a.c
– a+c, abc, match, a3c
• [tT]he
– The, the
• Ch[^0-9]
– Chapter, Chocolate
• ^the
– Start with the
• Friends$
– End with Friends
62
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Regular expression examples
• L..e
• $[0-9]*.[0-9]
• ^[0-9]file.dat
• [^0-9]file.dat
• MM-DD-YY or MM/DD/YY
– [0-1][0-9][-/][0-3][0-9][-/][0-9][0-9]
63
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Named classes of characters
• [0-9] ---OR --- [[:digit:]]
• [a-z] --- OR --- [[:lower:]]
• [A-Z] --- OR --- [[:upper:]]
• [a-zA-Z] --- OR --- [[:alpha:]]
• [a-zA-Z0-9] ---OR --- [[:alnum:]]
• egrep ‘^[[:lower:]]*$’
64
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Extended Metacharacter (egrep and awk)
Available in egrep and awk NOT in vi, sed, grep or fgrep
? matches zero or one occurrence of the preceding
char
+ Matches 1 or more occurrences of the preceding
char
| Specifies that either the preceding or following
regular expression can be matched
( ) Groups regular expressions
65
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Examples
• “.*” matches all characters between the quotations
• ^$ matches blank lines
• ^.*$ matches the entire line
• Big( Computer)?
• Compan(y|ies) # note: the | is a pipe symbol
• SSN: [0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]
• grep ‘.H[123]’ ch0[12]
– ch01: .H1 “Contents of Distribution Tape”
– ch02: .H2 “A Quick Tour”
66
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Repetition Examples
• Consider a file named text containing:
We're off to see the wizard.
The wonderful wizard of oz.
What a wonderful wizard he was.
The end.
• Try the following commands and explain the
output:
egrep 'f+' text
grep 'ff*' text
grep 'f{2}' text
egrep 'z?' text
67
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Some More Examples
• A price: $[0-9]*.[0-9][0-9]
• A filename, at the start of a line, that starts with a digit
^[0-9]file.dat
• A filename, anyplace in the line, that starts with a non-digit
[^0-9]file.dat
• A social security number
[0-9]{3}-[0-9]{2}-[0-9]{4}
• From 4 to 6 digits: [0-9]{4, 6}
• A date - MM-DD-YY or MM/DD/YY:
[0-1][0-9][-/][0-3][0-9][-/][0-9][0-9]
• A line containing only upper case letters:
^[A-Z]*$
68
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Replacement in sed and vi
• Applies to substitute command:
– s/regexp/replacement/
– Replacement string can contain the metacharacter
‘&’ which means the string that was matched
• Try this
STRING=“Start Again”
echo $STRING | sed 's/Again/& &/'
69
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Process and Thread
• Process
– Execution context
– Program code
– Resources
– Associated threads
• Threads: units of execution
• Process and threads are objects
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Thread Scheduling
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Linux Architecture
• Monolithic kernel
– Contains modular components, however
• UNIX-like or UNIX-based operating system
• Six primary subsystems:
– Process management
– Interprocess communication
– Memory management
– File system management
• VFS: provides a single interface to multiple file systems
– I/O management
– Networking
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Linux Kernel Architecture
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Process and Thread Organization
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Process information
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
System Calls
• Interface between user-level processes and
hardware devices.
– CPU, memory, disks etc.
• Make programming easier:
– Let kernel take care of hardware-specific issues.
• Increase system security:
– Let kernel check requested service via syscall.
• Provide portability:
– Maintain interface but change functional
implementation.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
POSIX APIs
• API = Application Programmer Interface.
– Function defn specifying how to obtain service.
– By contrast, a system call is an explicit request to kernel made via a
software interrupt.
• Standard C library (libc) contains wrapper routines that make system calls.
– e.g., malloc, free are libc routines that use the brk system call.
• POSIX-compliant = having a standard set of APIs.
• Non-UNIX systems can be POSIX-compliant if they offer the required set of
APIs.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Linux System Calls (1)
Invoked by executing int $0x80.
– Programmed exception vector number 128.
– CPU switches to kernel mode & executes a kernel function.
• Calling process passes syscall number identifying system
call in eax register (on Intel processors).
• Syscall handler responsible for:
– Saving registers on kernel mode stack.
– Invoking syscall service routine.
– Exiting by calling ret_from_sys_call().
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Linux System Calls (2)
• System call dispatch table:
– Associates syscall number with corresponding
service routine.
– Stored in sys_call_table array having up to
NR_syscall entries (usually 256 maximum).
– nth entry contains service routine address of
syscall n.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Initializing System Calls
• trap_init() called during kernel initialization
sets up the IDT (interrupt descriptor table) entry
corresponding to vector 128:
– set_system_gate(0x80, &system_call);
• A system gate descriptor is placed in the IDT,
identifying address of system_call routine.
– Does not disable maskable interrupts.
– Sets the descriptor privilege level (DPL) to 3:
• Allows User Mode processes to invoke exception handlers
(i.e. syscall routines).
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
The system_call() Function
• Saves syscall number & CPU registers used by
exception handler on the stack, except those
automatically saved by control unit.
• Checks for valid system call.
• Invokes specific service routine associated
with syscall number (contained in eax):
– call *sys_call_table(0, %eax, 4)
• Return code of system call is stored in eax.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)

More Related Content

Similar to Linux environment

PROGRAMMING IN C
PROGRAMMING IN C PROGRAMMING IN C
PROGRAMMING IN C cpjcollege
 
Management Process And Organisation Behaviour
Management Process And Organisation BehaviourManagement Process And Organisation Behaviour
Management Process And Organisation Behaviourcpjcollege
 
Management Process & Organizational Behavior
Management Process & Organizational Behavior Management Process & Organizational Behavior
Management Process & Organizational Behavior cpjcollege
 
Financial Modelling With Spreadsheets
Financial Modelling With Spreadsheets Financial Modelling With Spreadsheets
Financial Modelling With Spreadsheets cpjcollege
 
Digital electronics
Digital electronicsDigital electronics
Digital electronicscpjcollege
 
Computer Applications
Computer ApplicationsComputer Applications
Computer Applicationscpjcollege
 
JAVA PROGRAMMING
JAVA PROGRAMMING JAVA PROGRAMMING
JAVA PROGRAMMING cpjcollege
 
Production Management & Total Quality Management
Production Management & Total Quality ManagementProduction Management & Total Quality Management
Production Management & Total Quality Managementcpjcollege
 
Introduction to VB Programming
Introduction to VB ProgrammingIntroduction to VB Programming
Introduction to VB Programmingcpjcollege
 
Introduction to operating system
Introduction to operating systemIntroduction to operating system
Introduction to operating systemcpjcollege
 
Principles of Management
Principles of ManagementPrinciples of Management
Principles of Managementcpjcollege
 
Principles of Management
Principles of ManagementPrinciples of Management
Principles of Managementcpjcollege
 
Introduction To Database Management System
Introduction To Database Management SystemIntroduction To Database Management System
Introduction To Database Management Systemcpjcollege
 
Organizational behavior
Organizational behavior Organizational behavior
Organizational behavior cpjcollege
 
Organisational Behaviour
Organisational BehaviourOrganisational Behaviour
Organisational Behaviourcpjcollege
 
Value & Ethics in Business
Value & Ethics in BusinessValue & Ethics in Business
Value & Ethics in Businesscpjcollege
 
Constitutional Law-I (LLB -203)
 Constitutional Law-I (LLB -203) Constitutional Law-I (LLB -203)
Constitutional Law-I (LLB -203)cpjcollege
 
Organization Behavior
Organization BehaviorOrganization Behavior
Organization Behaviorcpjcollege
 

Similar to Linux environment (20)

PROGRAMMING IN C
PROGRAMMING IN C PROGRAMMING IN C
PROGRAMMING IN C
 
Management Process And Organisation Behaviour
Management Process And Organisation BehaviourManagement Process And Organisation Behaviour
Management Process And Organisation Behaviour
 
Management Process & Organizational Behavior
Management Process & Organizational Behavior Management Process & Organizational Behavior
Management Process & Organizational Behavior
 
Financial Modelling With Spreadsheets
Financial Modelling With Spreadsheets Financial Modelling With Spreadsheets
Financial Modelling With Spreadsheets
 
Normalization
NormalizationNormalization
Normalization
 
Digital electronics
Digital electronicsDigital electronics
Digital electronics
 
Computer Applications
Computer ApplicationsComputer Applications
Computer Applications
 
JAVA PROGRAMMING
JAVA PROGRAMMING JAVA PROGRAMMING
JAVA PROGRAMMING
 
Production Management & Total Quality Management
Production Management & Total Quality ManagementProduction Management & Total Quality Management
Production Management & Total Quality Management
 
Introduction to VB Programming
Introduction to VB ProgrammingIntroduction to VB Programming
Introduction to VB Programming
 
Introduction to operating system
Introduction to operating systemIntroduction to operating system
Introduction to operating system
 
Principles of Management
Principles of ManagementPrinciples of Management
Principles of Management
 
Principles of Management
Principles of ManagementPrinciples of Management
Principles of Management
 
PDCS II
PDCS IIPDCS II
PDCS II
 
Introduction To Database Management System
Introduction To Database Management SystemIntroduction To Database Management System
Introduction To Database Management System
 
Organizational behavior
Organizational behavior Organizational behavior
Organizational behavior
 
Organisational Behaviour
Organisational BehaviourOrganisational Behaviour
Organisational Behaviour
 
Value & Ethics in Business
Value & Ethics in BusinessValue & Ethics in Business
Value & Ethics in Business
 
Constitutional Law-I (LLB -203)
 Constitutional Law-I (LLB -203) Constitutional Law-I (LLB -203)
Constitutional Law-I (LLB -203)
 
Organization Behavior
Organization BehaviorOrganization Behavior
Organization Behavior
 

More from cpjcollege

Tax Law (LLB-403)
Tax Law (LLB-403)Tax Law (LLB-403)
Tax Law (LLB-403)cpjcollege
 
Law and Emerging Technology (LLB -405)
 Law and Emerging Technology (LLB -405) Law and Emerging Technology (LLB -405)
Law and Emerging Technology (LLB -405)cpjcollege
 
Law of Crimes-I ( LLB -205)
 Law of Crimes-I  ( LLB -205)  Law of Crimes-I  ( LLB -205)
Law of Crimes-I ( LLB -205) cpjcollege
 
Socio-Legal Dimensions of Gender (LLB-507 & 509 )
Socio-Legal Dimensions of Gender (LLB-507 & 509 )Socio-Legal Dimensions of Gender (LLB-507 & 509 )
Socio-Legal Dimensions of Gender (LLB-507 & 509 )cpjcollege
 
Family Law-I ( LLB -201)
Family Law-I  ( LLB -201) Family Law-I  ( LLB -201)
Family Law-I ( LLB -201) cpjcollege
 
Alternative Dispute Resolution (ADR) [LLB -309]
Alternative Dispute Resolution (ADR) [LLB -309] Alternative Dispute Resolution (ADR) [LLB -309]
Alternative Dispute Resolution (ADR) [LLB -309] cpjcollege
 
Law of Evidence (LLB-303)
Law of Evidence  (LLB-303) Law of Evidence  (LLB-303)
Law of Evidence (LLB-303) cpjcollege
 
Environmental Studies and Environmental Laws (: LLB -301)
Environmental Studies and Environmental Laws (: LLB -301)Environmental Studies and Environmental Laws (: LLB -301)
Environmental Studies and Environmental Laws (: LLB -301)cpjcollege
 
Code of Civil Procedure (LLB -307)
 Code of Civil Procedure (LLB -307) Code of Civil Procedure (LLB -307)
Code of Civil Procedure (LLB -307)cpjcollege
 
Women and Law [LLB 409 (c)]
Women and Law [LLB 409 (c)]Women and Law [LLB 409 (c)]
Women and Law [LLB 409 (c)]cpjcollege
 
Corporate Law ( LLB- 305)
Corporate Law ( LLB- 305)Corporate Law ( LLB- 305)
Corporate Law ( LLB- 305)cpjcollege
 
Human Rights Law ( LLB -407)
 Human Rights Law ( LLB -407) Human Rights Law ( LLB -407)
Human Rights Law ( LLB -407)cpjcollege
 
Labour Law-I (LLB 401)
 Labour Law-I (LLB 401) Labour Law-I (LLB 401)
Labour Law-I (LLB 401)cpjcollege
 
Legal Ethics and Court Craft (LLB 501)
 Legal Ethics and Court Craft (LLB 501) Legal Ethics and Court Craft (LLB 501)
Legal Ethics and Court Craft (LLB 501)cpjcollege
 
Political Science-II (BALLB- 209)
Political Science-II (BALLB- 209)Political Science-II (BALLB- 209)
Political Science-II (BALLB- 209)cpjcollege
 
Health Care Law ( LLB 507 & LLB 509 )
Health Care Law ( LLB 507 & LLB 509 )Health Care Law ( LLB 507 & LLB 509 )
Health Care Law ( LLB 507 & LLB 509 )cpjcollege
 
Land and Real Estate Laws (LLB-505)
Land and Real Estate Laws (LLB-505)Land and Real Estate Laws (LLB-505)
Land and Real Estate Laws (LLB-505)cpjcollege
 
Business Environment and Ethical Practices (BBA LLB 213 )
Business Environment and Ethical Practices (BBA LLB 213 )Business Environment and Ethical Practices (BBA LLB 213 )
Business Environment and Ethical Practices (BBA LLB 213 )cpjcollege
 
HUMAN RESOURCE MANAGEMENT (BBA LLB215 )
HUMAN RESOURCE MANAGEMENT (BBA LLB215 )HUMAN RESOURCE MANAGEMENT (BBA LLB215 )
HUMAN RESOURCE MANAGEMENT (BBA LLB215 )cpjcollege
 
PRIVATE INTERNATIONAL LAW ( LLB 507 &LLB 509 )
 PRIVATE  INTERNATIONAL  LAW ( LLB 507 &LLB 509 ) PRIVATE  INTERNATIONAL  LAW ( LLB 507 &LLB 509 )
PRIVATE INTERNATIONAL LAW ( LLB 507 &LLB 509 )cpjcollege
 

More from cpjcollege (20)

Tax Law (LLB-403)
Tax Law (LLB-403)Tax Law (LLB-403)
Tax Law (LLB-403)
 
Law and Emerging Technology (LLB -405)
 Law and Emerging Technology (LLB -405) Law and Emerging Technology (LLB -405)
Law and Emerging Technology (LLB -405)
 
Law of Crimes-I ( LLB -205)
 Law of Crimes-I  ( LLB -205)  Law of Crimes-I  ( LLB -205)
Law of Crimes-I ( LLB -205)
 
Socio-Legal Dimensions of Gender (LLB-507 & 509 )
Socio-Legal Dimensions of Gender (LLB-507 & 509 )Socio-Legal Dimensions of Gender (LLB-507 & 509 )
Socio-Legal Dimensions of Gender (LLB-507 & 509 )
 
Family Law-I ( LLB -201)
Family Law-I  ( LLB -201) Family Law-I  ( LLB -201)
Family Law-I ( LLB -201)
 
Alternative Dispute Resolution (ADR) [LLB -309]
Alternative Dispute Resolution (ADR) [LLB -309] Alternative Dispute Resolution (ADR) [LLB -309]
Alternative Dispute Resolution (ADR) [LLB -309]
 
Law of Evidence (LLB-303)
Law of Evidence  (LLB-303) Law of Evidence  (LLB-303)
Law of Evidence (LLB-303)
 
Environmental Studies and Environmental Laws (: LLB -301)
Environmental Studies and Environmental Laws (: LLB -301)Environmental Studies and Environmental Laws (: LLB -301)
Environmental Studies and Environmental Laws (: LLB -301)
 
Code of Civil Procedure (LLB -307)
 Code of Civil Procedure (LLB -307) Code of Civil Procedure (LLB -307)
Code of Civil Procedure (LLB -307)
 
Women and Law [LLB 409 (c)]
Women and Law [LLB 409 (c)]Women and Law [LLB 409 (c)]
Women and Law [LLB 409 (c)]
 
Corporate Law ( LLB- 305)
Corporate Law ( LLB- 305)Corporate Law ( LLB- 305)
Corporate Law ( LLB- 305)
 
Human Rights Law ( LLB -407)
 Human Rights Law ( LLB -407) Human Rights Law ( LLB -407)
Human Rights Law ( LLB -407)
 
Labour Law-I (LLB 401)
 Labour Law-I (LLB 401) Labour Law-I (LLB 401)
Labour Law-I (LLB 401)
 
Legal Ethics and Court Craft (LLB 501)
 Legal Ethics and Court Craft (LLB 501) Legal Ethics and Court Craft (LLB 501)
Legal Ethics and Court Craft (LLB 501)
 
Political Science-II (BALLB- 209)
Political Science-II (BALLB- 209)Political Science-II (BALLB- 209)
Political Science-II (BALLB- 209)
 
Health Care Law ( LLB 507 & LLB 509 )
Health Care Law ( LLB 507 & LLB 509 )Health Care Law ( LLB 507 & LLB 509 )
Health Care Law ( LLB 507 & LLB 509 )
 
Land and Real Estate Laws (LLB-505)
Land and Real Estate Laws (LLB-505)Land and Real Estate Laws (LLB-505)
Land and Real Estate Laws (LLB-505)
 
Business Environment and Ethical Practices (BBA LLB 213 )
Business Environment and Ethical Practices (BBA LLB 213 )Business Environment and Ethical Practices (BBA LLB 213 )
Business Environment and Ethical Practices (BBA LLB 213 )
 
HUMAN RESOURCE MANAGEMENT (BBA LLB215 )
HUMAN RESOURCE MANAGEMENT (BBA LLB215 )HUMAN RESOURCE MANAGEMENT (BBA LLB215 )
HUMAN RESOURCE MANAGEMENT (BBA LLB215 )
 
PRIVATE INTERNATIONAL LAW ( LLB 507 &LLB 509 )
 PRIVATE  INTERNATIONAL  LAW ( LLB 507 &LLB 509 ) PRIVATE  INTERNATIONAL  LAW ( LLB 507 &LLB 509 )
PRIVATE INTERNATIONAL LAW ( LLB 507 &LLB 509 )
 

Recently uploaded

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 

Recently uploaded (20)

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 

Linux environment

  • 1. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Linux environment BCA – VI Paper Code 306
  • 2. Introduction: What is Unix? • An operating system • Developed at AT&T Bell Labs in the 1960’s • Command Line Interpreter • GUIs (Window systems) are now available Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 3. Introduction: Unix vs. Linux • Unix was the predecessor of Linux • Linux is a variant of Unix – So is Mac OS X, so much of this tutorial applies to Macs as well • Linux is open source • Most of the machines you’ll use in the Bioinformatics program are running the Linux OS Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 4. Introduction: Why Unix/Linux? • Linux is free • It’s fully customizable • It’s stable (i.e. it almost never crashes) • These characteristics make it an ideal OS for programmers and scientists Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 5. Connecting to a Unix/Linux system • Open up a terminal: Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 6. Connecting to a Unix/Linux system • Open up a terminal: The “prompt” The current directory (“path”) The host Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 7. What exactly is a “shell”? • After logging in, Linux/Unix starts another program called the shell • The shell interprets commands the user types and manages their execution • The shell communicates with the internal part of the operating system called the kernel • The most popular shells are: tcsh, csh, korn, and bash • The differences are most times subtle • For this tutorial, we are using bash Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 8. Help! • Whenever you need help with a command type “man” and the command name Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 9. Help! Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 10. Help! Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 11. Help! Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 12. Unix/Linux File System /home/john/portfolio/ /home/mary/ The Path NOTE: Unix file names are CASE SENSITIVE! Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 13. Command: pwd • To find your current path use “pwd” Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 14. Command: cd • To change to a specific directory use “cd” Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 15. Command: cd • “~” is the location of your home directory Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 16. Command: cd • “..” is the location of the directory below current one Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 17. Command: ls • To list the files in the current directory use “ls” Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 18. Command: ls • ls has many options – -l long list (displays lots of info) – -t sort by modification time – -S sort by size – -h list file sizes in human readable format – -r reverse the order • “man ls” for more options • Options can be combined: “ls -ltr” Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 19. Command: ls -ltr • List files by time in reverse order with long listing Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 20. General Syntax: * • “*” can be used as a wildcard in unix/linux Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 21. Command: mkdir • To create a new directory use “mkdir” Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 22. Command: rmdir • To remove and empty directory use “rmdir” Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 23. Command: rmdir • To remove and empty directory use “rmdir” Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 24. Creating files in Unix/Linux • Requires the use of an Editor • Various Editors: 1) nano / pico 2) vi 3) emacs Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 25. Displaying a file • Various ways to display a file in Unix – cat – less – head – tail Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 26. Command: cat • Dumps an entire file to standard output • Good for displaying short, simple files Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 27. Command: less • “less” displays a file, allowing forward/backward movement within it – return scrolls forward one line, space one page – y scrolls back one line, b one page • use “/” to search for a string • Press q to quit Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 28. Command: head • “head” displays the top part of a file • By default it shows the first 10 lines • -n option allows you to change that • “head -n50 file.txt” displays the first 50 lines of file.txt Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 29. Command: head • Here’s an example of using “head”: Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 30. Command: tail • Same as head, but shows the last lines Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 31. File Commands • Copying a file: cp • Move or rename a file: mv • Remove a file: rm Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 32. Command: cp • To copy a file use “cp” Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 33. Command: mv • To move a file to a different location use “mv” Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 34. Command: mv • mv can also be used to rename a file Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 35. Command: rm • To remove a file use “rm” Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 36. Command: rm • To remove a file “recursively”: rm –r • Used to remove all files and directories • Be very careful, deletions are permanent in Unix/Linux Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 37. File permissions • Each file in Unix/Linux has an associated permission level • This allows the user to prevent others from reading/writing/executing their files or directories • Use “ls -l filename” to find the permission level of that file Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 38. Permission levels • “r” means “read only” permission • “w” means “write” permission • “x” means “execute” permission – In case of directory, “x” grants permission to list directory contents Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 39. File Permissions User (you)Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 40. File Permissions Group Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 41. File Permissions “The World” Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 42. Command: chmod • If you own the file, you can change it’s permissions with “chmod” – Syntax: chmod [user/group/others/all]+[permission] [file(s)] – Below we grant execute permission to all: Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 43. Running a program (a.k.a. a job) • Make sure the program has executable permissions • Use “./” to run the program Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 44. Running a program: an example • Running the sample perl script “hello_world.pl” Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 45. Ending a program • To end a program use “ctrl-c”. To try it: Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 46. Command: ps • To view the processes that you’re running: Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 47. Command: top • To view the CPU usage of all processes: Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 48. Command: kill • To terminate a process use “kill” Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 49. Input/Output Redirection (“piping”) • Programs can output to other programs • Called “piping” • “program_a | program_b” – program_a’s output becomes program_b’s input • “program_a > file.txt” – program_a’s output is written to a file called “file.txt” • “program_a < input.txt” – program_a gets its input from a file called “input.txt” Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 50. A few examples of piping Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 51. A few examples of piping Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 52. Command: wc • To count the characters, words, and lines in a file use “wc” • The first column in the output is lines, the second is words, and the last is characters Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 53. A few examples of piping Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 54. Command: grep • To search files in a directory for a specific string use “grep” Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 55. What is a Regular Expression? • Pattern to match all or part of a line of text – Expressed in a formal, albeit weird, language – For example: ^.*:Mike matches lines that start (^) with any string (.*) and contain a colon followed by Mike • ^, . and * are called meta characters – They do not represent themselves, but have other special meaning. • :, M, i, k and e are normal characters – The do represent themselves 55 Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 56. Where are Regular Expressions Used? • Special commands that “know” about them – Vi-Uses them in searching for a string: /regexp/ • Uses them in substitite command: s/regexp/replace/sed – Edit a file (like vi) as a filter in a pipeline … | sed editing-commands | … – grep , fgrep (fixed grep) , egrep (extended grep) • Print lines of a file that match a regexp – awk • Process input files looking for lines that match a regexp and processing those lines 56 Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 57. Regular expression • A regular expression is a pattern of characters used for describing sets of strings • A pattern or sequence of characters – Upper and lower case – Digits – Space, underscore, etc • Metacharacters 57 Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 58. Basic Regular Expressions • Patterns that match a single character – All regular letters match themselves a b z T Q 0 1 9 – . (a single dot) matches any single character except newline. • In awk, dot can match newline also • (like ? in filename generation) – A set of characters that matches any single character from the set (just like filename generation) [aeiou] [a-z0-9] [A-Za-z-] [a-m] 58 Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 59. Metacharacter * Matches 0 or more occurrences of the preceding char […] Matches any one of characters enclosed between the brackets. - dash indicates a range when inside sq bkts. [^ - negates what's inside brackets] 59 Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 60. Metacharacter (con’t) - backslash - escape character - just like before. – . means match a dot – This means is a meta character – means match Positional indicators: • ^ anchor to beginning of line • $ anchor to end of line 60 Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 61. • "Some people, when confronted with a Unix problem, think ‘I know, I’ll use sed.’ Now they have two problems.” - 61 Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 62. Regular expression examples • Peach • a*c – cxxx, acxxx, aaacxxxx • a.c – a+c, abc, match, a3c • [tT]he – The, the • Ch[^0-9] – Chapter, Chocolate • ^the – Start with the • Friends$ – End with Friends 62 Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 63. Regular expression examples • L..e • $[0-9]*.[0-9] • ^[0-9]file.dat • [^0-9]file.dat • MM-DD-YY or MM/DD/YY – [0-1][0-9][-/][0-3][0-9][-/][0-9][0-9] 63 Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 64. Named classes of characters • [0-9] ---OR --- [[:digit:]] • [a-z] --- OR --- [[:lower:]] • [A-Z] --- OR --- [[:upper:]] • [a-zA-Z] --- OR --- [[:alpha:]] • [a-zA-Z0-9] ---OR --- [[:alnum:]] • egrep ‘^[[:lower:]]*$’ 64 Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 65. Extended Metacharacter (egrep and awk) Available in egrep and awk NOT in vi, sed, grep or fgrep ? matches zero or one occurrence of the preceding char + Matches 1 or more occurrences of the preceding char | Specifies that either the preceding or following regular expression can be matched ( ) Groups regular expressions 65 Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 66. Examples • “.*” matches all characters between the quotations • ^$ matches blank lines • ^.*$ matches the entire line • Big( Computer)? • Compan(y|ies) # note: the | is a pipe symbol • SSN: [0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9] • grep ‘.H[123]’ ch0[12] – ch01: .H1 “Contents of Distribution Tape” – ch02: .H2 “A Quick Tour” 66 Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 67. Repetition Examples • Consider a file named text containing: We're off to see the wizard. The wonderful wizard of oz. What a wonderful wizard he was. The end. • Try the following commands and explain the output: egrep 'f+' text grep 'ff*' text grep 'f{2}' text egrep 'z?' text 67 Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 68. Some More Examples • A price: $[0-9]*.[0-9][0-9] • A filename, at the start of a line, that starts with a digit ^[0-9]file.dat • A filename, anyplace in the line, that starts with a non-digit [^0-9]file.dat • A social security number [0-9]{3}-[0-9]{2}-[0-9]{4} • From 4 to 6 digits: [0-9]{4, 6} • A date - MM-DD-YY or MM/DD/YY: [0-1][0-9][-/][0-3][0-9][-/][0-9][0-9] • A line containing only upper case letters: ^[A-Z]*$ 68 Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 69. Replacement in sed and vi • Applies to substitute command: – s/regexp/replacement/ – Replacement string can contain the metacharacter ‘&’ which means the string that was matched • Try this STRING=“Start Again” echo $STRING | sed 's/Again/& &/' 69 Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 70. Process and Thread • Process – Execution context – Program code – Resources – Associated threads • Threads: units of execution • Process and threads are objects Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 71. Thread Scheduling Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 72. Linux Architecture • Monolithic kernel – Contains modular components, however • UNIX-like or UNIX-based operating system • Six primary subsystems: – Process management – Interprocess communication – Memory management – File system management • VFS: provides a single interface to multiple file systems – I/O management – Networking Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 73. Linux Kernel Architecture Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 74. Process and Thread Organization Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 75. Process information Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 76. System Calls • Interface between user-level processes and hardware devices. – CPU, memory, disks etc. • Make programming easier: – Let kernel take care of hardware-specific issues. • Increase system security: – Let kernel check requested service via syscall. • Provide portability: – Maintain interface but change functional implementation. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 77. POSIX APIs • API = Application Programmer Interface. – Function defn specifying how to obtain service. – By contrast, a system call is an explicit request to kernel made via a software interrupt. • Standard C library (libc) contains wrapper routines that make system calls. – e.g., malloc, free are libc routines that use the brk system call. • POSIX-compliant = having a standard set of APIs. • Non-UNIX systems can be POSIX-compliant if they offer the required set of APIs. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 78. Linux System Calls (1) Invoked by executing int $0x80. – Programmed exception vector number 128. – CPU switches to kernel mode & executes a kernel function. • Calling process passes syscall number identifying system call in eax register (on Intel processors). • Syscall handler responsible for: – Saving registers on kernel mode stack. – Invoking syscall service routine. – Exiting by calling ret_from_sys_call(). Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 79. Linux System Calls (2) • System call dispatch table: – Associates syscall number with corresponding service routine. – Stored in sys_call_table array having up to NR_syscall entries (usually 256 maximum). – nth entry contains service routine address of syscall n. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 80. Initializing System Calls • trap_init() called during kernel initialization sets up the IDT (interrupt descriptor table) entry corresponding to vector 128: – set_system_gate(0x80, &system_call); • A system gate descriptor is placed in the IDT, identifying address of system_call routine. – Does not disable maskable interrupts. – Sets the descriptor privilege level (DPL) to 3: • Allows User Mode processes to invoke exception handlers (i.e. syscall routines). Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 81. The system_call() Function • Saves syscall number & CPU registers used by exception handler on the stack, except those automatically saved by control unit. • Checks for valid system call. • Invokes specific service routine associated with syscall number (contained in eax): – call *sys_call_table(0, %eax, 4) • Return code of system call is stored in eax. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)