Linux_intro

advertisement
An Intro to Linux
• 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
• Linux was created in 1991 by Linus Torvalds , a software
developer who became the chief architect of the Linux kernel
• Small computers & PC-based operating system
• Runs on embedded systems, firmware, routers, mobile phones
(Android), tablets, video game consoles
References: http://en.wikipedia.org/wiki/Linux
Ali Kujoory
6/30/2016
1
Various Linux Distributions
• Fedora Project was introduced in 1993 to take over Red Hat
Linux
• Red Hat 9 was the last version
• One of the Linux distribution called Fedora Core is used in
– OpenOffice and
– FireFox (comes with Firefox)
Ali Kujoory
6/30/2016
2
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
3
Linux Platform
• 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
5
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
6
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
7
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
8
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
9
Linux Directory Hierarchy
Ali Kujoory
6/23/2015
10
Linux Directory Hierarchy
Ali Kujoory
6/30/2016
11
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
• wc (print word count)
• date
• man wc (get more information on
wc command)
• hostname
• who (info about current user)
• echo (display message on screen)
– E.g., echo hello
• cat concatenates file & prints on
the standard output
– E.g., cat xyz
•
•
•
•
•
•
cat /etc/passwd
more /etc/passwd
man vi |more
cp /etc/passwd mypasswd
mv mypasswd yourpasswd
mv –i sample
Ali Kujoory
Make sure you
can do these!
6/23/2015
12
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
13
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
14
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
15
Practice
• Read about chmod - Read about LINUX permissions (check the
hyperlink)
• For simple examples of scripts go to
http://www.freeos.com/guides/lsst/misc.htm#commonvi
• Write a shell script (called myshell) to perform the following:
–
–
Remove all the new directories: junks, primary, secondary.
Display the IP address of your machine
• 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
16
Appendix: 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
17
Appendix: 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
18
Download