Intro to Linux

advertisement
An Intro to Linux
References:
• Slides “Iinux”, Dr. Farid Farahmand, Fall 2014
• http://en.wikipedia.org/wiki/Linux
• http://en.wikipedia.org/wiki/Unix
• http://en.wikipedia.org/wiki/GNU
• https://en.wikipedia.org/wiki/Comparison_of_text_editors
• https://en.wikipedia.org/wiki/Gedit
• http://distrowatch.com/
• http://lifehacker.com/5774997/getting-started-with-linux-how-to-install-linux-on-yourcomputer
• http://www.flexbeta.net/main/printarticle.php?id=70
• http://www.freeos.com/guides/lsst/ch01sec04.html
• http://www.freebsdsoftware.org/shells/
Ali Kujoory
6/23/2015
1
It All Started With UNIX
• Linux, an Operating System based on Unix
• Unix was developed in 1970 by AT&T Lab (Later known as Bell
Lab)
– A multi-tasking & multi-user OS
– AT&T licensed it to outside & the code of Unix was given to universities
including UC Berkeley
• UC Berkeley enhanced the existing version called it Berkeley
Software Distribution Unix
• SVR4 (System V Release 4) combines all Berkeley
enhancements & original features
• Unix was essentially for workstations
Ali Kujoory
6/30/2016
2
Then Came Linux
• Created in 1991 by Linus Torvalds , a software developer who
became the chief architect of the Linux kernel
• Small computers & PC-based operating system
• Released in 1994 as Version 1
• Initially was developed for 80 & x86 processors (8080, 8086, ..
i386) architecture processors)
• Today it supports various processor & servers
– AMD, Motorola 6800, Power PC, etc.
• Runs on embedded systems, firmware, routers, mobile phones
(Android), tablets, video game consoles
Ali Kujoory
6/30/2016
3
Linux Distros = Linux Distribution
• Each distro is a package including the OS & different
applications
• Different distros provide different applications & require
different installations steps
• The package includes
–
–
–
–
Core Linux OS (also called Kernel)
X Window System & GUI interfaces
Graphical desktop (e.g., GNOME or KDE)
Different applications
• Word Processor, Spreadsheet, etc.
– Documentations
Ubuntu 14.04.1
SUSE 10.1
Fedora Core 5
SimplyMEPIS 6.0
PCLinuxOS 0.93a
Mandriva 2006
Slackware 10.2
• Each Distro is under General Public License (GNU)
– http://en.wikipedia.org/wiki/GNU
– Anyone can copy & distribute the software in open source
form to others, e.g.
• Ubuntu “www.ubuntu.com” is an Open Source
• Obtaining a distro can be through ready made packages
over the net or buying the CD or just compiling a version
Ali Kujoory
Distribution
6/30/2016
Debian 3.1r3
Damn Small 3.0.1
Gentoo 2006.1
Puppy 2.10
Freespire 1.0
4
Linux Distros - GNU
• GNU is a free Operating System consisting of a kernel, libraries,
system utilities, compilers, & end-user applications
– "GNU's Not Unix", which was chosen because its design is Unix-like, but
differs from Unix by being free software & by not containing any UNIX
code
Ali Kujoory
6/30/2016
5
Red Hat & Fedora Core
• Fedora Project was introduced in 1993 to take over Red Hat
Linux
• Red Hat 9 was the last version
• The new Linux distro called Fedora Core
– A new version every six months!
– 2004  Fedora Core 3
– 2005  Fedora Core 4
• New applications include OpenOffice, FireFox, GIMP (GNU Image
Manipulation Program)
– 2007  Fedora Core 6
• Fedora comes installed with Firefox
Ali Kujoory
6/30/2016
6
Linux, Layered Views
User
request
SHELL
User
Applicati
on
User
Application Programs
Shell/Photo/WP/FTP/Telnet/ Web Browser
Lower Level Utilities
Application Programmer Interface (API)C/C++/Java/Fortran
LINUX KERNEL
Operating System (Kernel)
Computer Hardware
Computer Hardware, I/O devices, Memory, CPU,
Storage Devices
Ali Kujoory
6/23/2015
7
Linux Kernel
• Kernel contains the actual Operating
System (OS)
• Manages processes in terms of
creating, suspending, terminating, &
maintenance
• Schedules CPU
• Provides inter-process
communications & communicates
with devices
• Has many different versions
• Linux 2.6 Version improvements
– 1.x.y  Major. minor. patch
– 2.6 is one of the most improved
– Supports more hardware
– Higher Stability
• Supports 4 billion users & 16 TB File
System!
– Handles external devices better
(supporting Hot Plug Devices, USB)
– Supports many new devices (Wireless,
USB-based, different storage devices
using IDE, SCSI, ..)
– Sound system
– Higher security  Using SELinux
(Security Enhanced Linux)
Ali Kujoory
6/23/2015
9
Linux Platform
• Operating Systems are divided according to
– How many users can use the system (logon) at the same time
– The number of processors the system can run simultaneously
• A process executing a program
• Basic categories
–
–
–
–
Single User / Single Processor (Windows 3.1, DOS)
Single User / Multi Processor (Win NT Workstations, OS/2)
Multi User / Single Processor (Does it exist?)
Multi User / Multi Processor (Linux, Windows NT Server)
•
•
•
•
Ali Kujoory
High resource utilization using multiplexing
Uses Time Sharing
High Throughput (Number of processes finished in a unit of time)
Uses multi-programming – If the current processes is accessing I/O, the CPU
can be assigned to another task
6/30/2016
10
Linux Platform
• A Linux shell, also called "the command line“
– Provides the traditional user interface for the Linux OS
– Contains standard commands for Unix
•
Command are the instructions for the computer to do certain things
– Good learning tool to learn Unix!
• Basic Shells applications are
– BASH, Bourne Shell
•
BASH is similar to Bourne Shell in Unix
– C Shell, tcsh (TENEX C Shell), scsh (Scheme Shell)
– http://www.freebsdsoftware.org/shells/ has list of various shells & their
differences
Ali Kujoory
6/30/2016
11
Basic Security In Linux
• Without SELinux (Security Enhanced Linux)
– Domains are divided into Users & Group IDs
– The ROOT has absolute control
Logon as ROOT
• With SELinux
– Domains are divided into Subjects & Objects
• Even with Super-user privilege access to some files & devices maybe
denied
Ali Kujoory
6/30/2016
12
Linux Text Editors
• A text editor is a type of
program used for editing plain
text files
• Text editors are provided with
operating systems & software
development packages, & can
be used to change:
• There are many text editors
that were & are used for Linux.
– Wikipedia provides a good
comparison
• Come in form of Terminal
Command Line Interface (CLI)
or Graphic User Interface (GUI)
– “vi”, CLI. developed by Bill Joy in
C programing language for Unix
OS, & Linux uses keyboard
– configuration files,
documentation files &
programming language source
code
• Can put together with many
commands, lines of code, to make
a program.
• Text editor allows to find,
replace, cut & copy, filter, &
format text in a program
Ali Kujoory
– “gedit”, CLI & GUI, like Windows
Notepad uses mouse &
keyboard, friendly
6/30/2016
13
Linux Desktop
• Using the terminal commands is boring!
• X Window System or X
–
–
–
–
–
–
–
Is an open, cross-platform, client/server system &
Provides windowing system for graphic work stations
Based on a client/server model
Server handles input & output devices &
Generates graphical displays used by the clients
Was developed at MIT & some computer companies (X.org)
Uses mouse & keyboard
• How the actual interface looks or feels depends on the GUI
interface
Ali Kujoory
6/30/2016
14
GUI Examples
Choosing KDE (Kdesktop Environment)
at the Login Screen
default GNOME Desktop
The KDE Desktop (Fedora Core)
Ali Kujoory
6/23/2015
15
GEDIT Text Editor
• Gedit is Similar to Windows
Notepad & the default GUI text
editor in the Ubuntu OS
– Can be invloked also in CLI
• Designed for
– Simplicity
– Editing source code & structured
text such as markup languages
– Multi-language spell checking
– Extensive support of syntax
highlighting, &
– A large # of official & 3rd party
plugins
An Ubuntu screen shot of GEDIT page
• Freely available for Linux, Mac
& Windows, by several
developers
Ali Kujoory
6/23/2015
16
Ubuntu on Windows, Multi-OS Environment
• 3 ways to install Ubuntu/Linux OS on your PC or laptop with
Windows 7 or Mac OS. See http://lifehacker.com/5774997/gettingstarted-with-linux-how-to-install-linux-on-your-computer
1. Install Linux OS on a flash memory, then select Windows or
Ubuntu/Linux as you boot your computer, OR
2. Install two different OS in two different partitions, in which case there is
no access to each other, OR
3. Use an emulator, e.g., VMware that can install & run a copy of a second
OS (Ubuntu/Linux) on the Hard Drive
Wine - Windows apps
running without Windows
Click here.
Host
OS
Windows
Ali Kujoory
6/30/2016
VMWare
VPC/
WINE
Guest
OS
Linux
17
Shell Prompt
• Most work is done at the shell prompt which is the
Command-Line Interface
• Remember root is /
• ls – list files
– ls /mnt/floppy to see contents of floppy
• cd – change directory
– cd /home to go to folder home
• mkdir – create a directory
– Mkdir homework to make a folder homework
Exercise: How can you go to CLI in:
- Windows
- Mac
Ali Kujoory
6/30/2016
18
Shell Prompt
• rmdir – remove a directory
– rmdir /mnt/floppy/test
• mv – move or rename a file
– mv homework1 assignment1
• cp – copy a file
– cp homework1 assignment1
• locate – find a file
– locate homework1
• gedit <filename> - start editing a file
– gedit homework1
• vi <filename> - start editing a file
– vi homework1
Ali Kujoory
6/30/2016
19
Shell Types
The Linux Shell has evolved in several types,
some are used, & some are not.
Used:
• bash — Bourne Again SHell, default shell in
most Linux distributions, decent features,
most common, freeware Shell
• zsh — most feature rich, based on Bournestyle, still rarely used due to its complexity;
developed by Paul Falstad in 1990
• ksh — default shell in Solaris, AIX & other
few other unices; (Korn Shell by David Korn,
AT&T)
• tcsh — TENEX C shell, default shell in
various *BSD flavor unices, used by those
who know C programing language
Basically most Shell types work basically the
same with similar base commands
Ali Kujoory
Not Used (Historic):
• sh — original Bourne shell (released
1977), developed by Steven Bourne,
AT&T. Obsoleted by bash
• csh — original C shell (released 1978),
developed by Bill Joy, UCB. Obsoleted
by tcsh & ksh
• ash – a Bourne shell clone, lightweight (used in Android phone) by
Kenneth Almquist
• dash - a clone of ash developed by
Debian
• Can install & remove different shells
using “Software Center” on Ubuntu
• Shells can be changed by simply typing
the name of the shell at the command
prompt
chsh (change shell)
6/23/2015
20
Linux Directory Hierarchy
Ali Kujoory
6/23/2015
21
Linux Directory Hierarchy
Ali Kujoory
6/30/2016
22
Some Basic Commands
Format: Command -option argument
• pwd (print working directory)
• cd /bin
• ls (List info about file(s)
• ls –l (List detail info about file)
• ls –a (show hidden files)
• mkdir myoffice
• mkdir /root/mydocuments
• rmdir office
•
•
•
•
•
•
cat /etc/passwd
more /etc/passwd
man vi |more
cp /etc/passwd mypasswd
mv mypasswd yourpasswd
mv –i sample
Ali Kujoory
• wc (print word count)
• date
• man wc (get more information on
wc command)
• whatis man
• whereis tcsh (lists the path)
• whoami
• hostname
• uname (displays system info)
– E.g., uname –m (machine)
• who (info about current user)
• echo (display message on screen)
Make sure you
can do these!
6/23/2015
23
Finding/Displaying Files, Patterns
• grep searches file(s) for words/lines that match a given
pattern
– E.g.., grep word? filename
– grep command can display the IP address & machine name
• find searches for files that meet a desired criteria
– E.g., find xyz? (? For any xyz1, xyz2, xyz. )
• cat concatenates file & prints on the standard output
– E.g., cat xyz
• echo displays message on screen
– E.g., echo hello
Ali Kujoory
6/30/2016
24
Exercise
Command + Options + Arguments
• Open a shell terminal
• Type the following, observe, & briefly explain what each does:
–
–
–
–
–
–
–
–
–
wc
date
man wc (get more info on wc command)
whatis man
whereis csh (lists the path)
whoami
hostname
uname (linux)
who (information about current user)
Ali Kujoory
6/30/2016
25
File System Permissions in Linux
Permission
type
When used with files
When used with
directories
Read
Read a file or copy a file
List the contents of a
directory
Write
Write to the file, including
deleting the file
Create files
Execute
Execute programs & shell scripts,
which are text files containing
Linux commands
Modify the file
permissions
Ali Kujoory
6/30/2016
26
Linux Permissions
• Permissions are set for user, group, & others
• Each permission is set with a single digit from 0 to 7 (binary
000 to 111) on the combination of permissions
Operation
Decimal value
Bunary value
read
4
100
write
2
010
execute
1
001
No permission
0
000
• Examples for user, group, or others:
–
–
–
–
Read + write+ Execute = rwx = 4 + 2 + 1 = 7
- + write+ Execute = -wx = 0 + 2 + 1 = 3
Read + - + Execute = r-x = 4 + 0 + 1 = 5
Read + write + - = rw- = 4 + 2 + 0 = 6
Ali Kujoory
6/30/2016
27
Using chmod to Set Permissions
Command
Permissions
Ownership
Owner
Group
Other
chmod 755 myfile
rwx
r-x
r-x
chmod 540 myfile
r-x
r--
---
chmod 744 myfile
rwx
r--
r--
Ali Kujoory
6/30/2016
28
Linux Script Examples 1
Script is a collection of commands typed in
text, stored in a file, read by processor and
executed for result. One can use a text editor
(e.g., vi) to make the file. Note: “$” is the
Shell prompt & “#” indicates comments.
Example 1: Write a Linux script to print sum
of two numbers, let's say 6 and 3.
$ echo 6 + 3
This will print 6 + 3, not the sum 9.
To do sum or math operations in shell use
expr, syntax is as follows:
Syntax:
expr
op1
operator
op2
Where, op1 and op2 are any Integer Number
(Number without decimal point) and operator
can be
Ali Kujoory
+ Addition
- Subtraction
/ Division, to find quotient, 20 / 3 = 6
% Modular, to find remainder, 20 % 3 = 2
(Remember its integer calculation)
\* Multiplication
$ expr 6 + 3
# expr Evaluate expressions
Now It will print sum as 9 , But
$ expr 6+3
will not work because space is required
between number and operator (See Shell
Arithmetic).
6/30/2016
29
Linux Script Example 2 & 3
Notes:
• $ with a space char after is the Linux
prompt here
• $ with NO space after defines a Linux
variable
Example 2: How to define two variable x=20,
y=5 and then to print division of x and y (i.e.
x/y)
To execute a program in Linux, type:
./filename, e.g., ./xxx
$ x=20
$ y=5
$ expr $x / $y
Example 3: Modify above and store division
of x and y to variable called z
$
$
$
$
x=20
y=5
z=`expr $x / $y`
echo $z
Ali Kujoory
` (back quote) executes
the command
6/30/2016
30
Practice
• Read about chmod - Read about LINUX permissions (check the
hyperlink)
• Find install.log file
• For simple examples of scripts go to
http://www.freeos.com/guides/lsst/misc.htm#commonvi
• Write a shell script & using grep command (or anything else)
display the IP address & machine name (use uname)
• Create the following directories & files (/ is the root directory):
/
junks
my_junk_file
Ali Kujoory
primary
my_primary_file
6/30/2016
secondary
my_secondary.log
31
Practice (cont)
• Write a shell script (called myshell) to perform the following:
–
–
–
–
–
Remove all the new directories: junks, primary, secondary.
Backup HOSTS file by creating HOSTS_BACK
Display the IP address of your machine
Create a new file called YOUR_IP_ADDRESS containing the IP address of
your machine  thus, by doing a less YOUR_IP_ADDRESS we should get
your IP address
Change the permission on YOUR_IP_ADDRESS such that can only be
viewed by the user & make sure it is readable only.
Note: you should be able to run the script multiple times with no
errors! (make sure you try running your program multiple times)
Ali Kujoory
6/30/2016
32
Download