basic unix tutorial one

52
BASIC UNIX Tutorial One COMPUTER AND INFORMATION ENGINEERING LAB II ECE 3102 & ECE 4102 ماْ هَ فِ ي نْ قُ زْ زَ وً ماْ لِ عِ ي نْ د زِ ّ بَ زMy Lord! Advance me in Knowledge and true understanding .

Upload: sutton

Post on 25-Feb-2016

47 views

Category:

Documents


0 download

DESCRIPTION

BASIC UNIX Tutorial One. COMPUTER AND INFORMATION ENGINEERING LAB II ECE 3102 & ECE 4102. رَبِّ زدْنيِ عِلْماً وَ رْزُقْنيِ فَهْما My Lord! Advance me in Knowledge and true understanding . Lecturer: Dr. Nor Farahidah Za’bah Demonstrator: Br. Akhter Lab technician: Br. Shahlan. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: BASIC UNIX Tutorial One

BASIC UNIXTutorial One

COMPUTER AND INFORMATION ENGINEERING LAB II

ECE 3102 & ECE 4102

فهما رزقني و علما زدني ربMy Lord! Advance me in Knowledge and true understanding .

Page 2: BASIC UNIX Tutorial One

Lecturer: Dr. Nor Farahidah Za’bah

Demonstrator:Br. Akhter

Lab technician:Br. Shahlan

Laboratory:Mechatronics Workshop, Room# E2-2-13.12

فهما رزقني و علما زدني ربMy Lord! Advance me in Knowledge and true understanding .

Page 3: BASIC UNIX Tutorial One

3

Every computer uses an operating system.

The operating system forms a platform for other system software and application software.

The most popular operating systems in use today are:

Windows from Microsoft Mac OS from Apple UNIX / LINUX

Introduction

Page 4: BASIC UNIX Tutorial One

4

Multitasking & Multi-user OS.

Unix has user interfaces called Shells (Terminals) that is more controlled, more flexible and powerful than the standard operating system text-based interface.

Main purpose is to make it easier for the user to manipulate the functions of the operating system

General info

Page 5: BASIC UNIX Tutorial One

5

• Unix is more flexible and can be installed on many different types of machines,• main-frame computers, • Supercomputers• micro-computers.

• Unix is more stable, which means, does not go down as often as Windows, so, • Needs less administration and maintenance.

• Unix has comparably greater built-in security and permissions features.

• Unix possesses much greater processing power.

General info (Con.)

Page 6: BASIC UNIX Tutorial One

6

• Unix is the leader in serving the Web. • About 90% of the Internet relies on Unix operating

systems running Apache, most widely used Web server.

• Mostly free or inexpensive open-source operating systems.

• Unix also inspires novel approaches to software design, such as, • solving problems by interconnecting simpler tools

instead of creating large monolithic application programs.

General info (Con.)

Page 7: BASIC UNIX Tutorial One

7

Need to Remember

One single type of Operating System (OS) can not provide universal answers to all your

computing needs.

General info (Con.)

Page 8: BASIC UNIX Tutorial One

8

• Developed in 1969 by a group of AT&T employees at Bell Labs.

• The Unix operating system was first developed in Assembly Language. By 1973 had been almost entirely recoded in C.

• Today's Unix systems are split into various branches, developed over time by AT&T as well as various commercial vendors and non-profit organizations.

• As of 2007, the owner of the trademark is The Open Group, an industry standards consortium.

• Only systems fully compliant with and certified according to the Single UNIX Specification are qualified to use the trademark; others are called,

"Unix system-like" or "Unix-like“ Ex: MINIX, Linux, and BSD.

History

Page 9: BASIC UNIX Tutorial One

9

• Outlined by The Open Group, a consortium that holds the UNIX trademark.

• Only system that complies with the specification can use the trademark.

• Those that not complies are classified as UNIX-like.

• Registered UNIX products -• Digital® UNIX, Hewlett Packard HP-UX®, IBM AIX®, SCO

UnixWare®, SGI IRIX®, Sun Solaris®

• Linux is a product that mimics the form and function of a UNIX system, but is not derived from original UNIX licensed source code and is classified as UNIX-like.

Single UNIX Specification

Page 10: BASIC UNIX Tutorial One

10

o Kernel• Master control of all computer operations.• Controls access to files, • Allocates resources, • Controls input/output (I/O), • Manages memory.

o Shell• Command interpreter:• transfers information between user and the Kernel

• Common shells: “C” shell, Bourne Shell, Korn Shell.• Shell uses prompt (% or $) to indicate readiness to

accept next command.

Components

Shell

Kernel

Applications

Page 11: BASIC UNIX Tutorial One

11

commands

SHELL OR TERMINAL

Shell or Terminal

Page 12: BASIC UNIX Tutorial One

12

• Everything in UNIX is either a file or a process. • A process is an executing program identified by a unique

Process Identifier (PID). • A file is a collection of data. They are created by users using

text editors, running compilers etc. • Examples of files: • a document (report, essay etc.) • the text of a program written in some high-level programming

language • instructions comprehensible directly to the machine and

incomprehensible to a casual user, for example, a collection of binary digits (an executable or binary file);

• a directory (or folder in Windows), containing information about its contents, which may be a mixture of other directories (subdirectories) and ordinary files.

Files & processes

Page 13: BASIC UNIX Tutorial One

13

• Unix file-store is divided into a tree of directories and sub-directories.

• At the very top-level (or bottom level depending on how you look at it) is the root directory, represented by the ‘/’ character.

• Users can sub-divide their own directory into a number of sub-directories, so that they may group their files according to the different areas of their work.

• Pathname: “directions” to a file through directories and subdirectories

UNIX File system

Page 14: BASIC UNIX Tutorial One

System directoriesBelow are a number of system directories (such as /bin, /lib, /dev) together with the directories for user files.

14

Page 15: BASIC UNIX Tutorial One

15

• Main login directory (the home directory) for the user Fred who has been allocated to the u1 directory would be /u1/fred.

• The full filename or pathname for Fred's file results1 in the subdirectory plants would be /u1/Fred/plants/results1.

• If user Fred is working in the default, home directory, then only plants/results1 need be used to refer to the file.

Home / user directory

Page 16: BASIC UNIX Tutorial One

16

• Absolute:• Every file has 1 and only 1 absolute address.• Usually starts with a “/” as first character.• Starts at root directory and moves through

directories/subdirectories to file.• Can use “~” to start the path at the user level.

• Relative:• Describe path to file from current working directory.• Relative addresses are not unique.• Do not need to begin with a “/”.

Absolute & relative addressing

Page 17: BASIC UNIX Tutorial One

17

• Single dot (.) used to signify current working directory.• Double dot (..) used to describe parent (1

step up) directory.• Relative address starts at current level and

moves through subdirectories.• Each step (directory/subdirectory) is

separated by a “/”.

Relative Addressing (Con.)

Page 18: BASIC UNIX Tutorial One

18

• Up to 256 characters in length.• Can start with/be all numbers.• Can use:• period (.)• underscore (_)• dash (-) • comma (,)

• Case sensitive (PC usually not).• Do not include spaces in file name.

File Naming conventions

Page 19: BASIC UNIX Tutorial One

19

• Characters that can be used to match a number of different character combinations are called WILD CHARACTERS.

• (?) - represents 1 character• ex.: Lab?.c could describe Lab3.c, Lab8.c,

LabK.c

• (*) - represents more than 1 character• ex.: Lab*.c could describe Lab223.c,

LabA1155.c

Wild Characters

Page 20: BASIC UNIX Tutorial One

20

Relative Address: “.” = current directory“..” = dir. 1 step up“/” = separates steps

Examples

Page 21: BASIC UNIX Tutorial One

21

• Absolute Address of file ex7.c/home/lookout/a/fred/c/hmwks/ex7.c

• Using “~” shortcut to “users” level: ~/c/hmwks/ex7.c

Examples (Con.)

Page 22: BASIC UNIX Tutorial One

22

If working dir. is fred, relative address of ex7.c is

c/hmwks/ex7.c

Examples (Con.)

Page 23: BASIC UNIX Tutorial One

23

Relative Address of fred to file “data”: ../../../boreas/b/eric/chm/lab1/data

Examples (Con.)

Page 24: BASIC UNIX Tutorial One

24

• Files are grouped in the directory structure.

• The file-system is arranged like hierarchical tree (inverted) structure.

• The top of the tree is called “root” which usually contains several sub-directories.

• In UNIX “/” (forward slash) is used to present the “root”.

Concept of directory

Page 25: BASIC UNIX Tutorial One

25

• Home directory might contain a public_html directory.

• public_html directory might contain an “index.html” file.

public_html

home_directory

index.html

Concept of directory (Con.)

Page 26: BASIC UNIX Tutorial One

26

A file cannot hold a directory or a file!

Concept of directory (Con.)

public_html

home_directory

index.html

New_file_or_directory

Page 27: BASIC UNIX Tutorial One

27

Directories can hold files and other directories

Concept of directory (Con.)

/

bin etc users tmpbackup

user1user2 … …

usern

public_html file1

index.html

Page 28: BASIC UNIX Tutorial One

• Absolute Pathnames• In the previous tree /users/usern/file1 is

an absolute pathname.

• Relative pathnames• If you are already in the users directory,

the relative pathname for file1 is usern/file1.

Pathnames

Page 29: BASIC UNIX Tutorial One

29

What is the absolute path to index.html?

Specifying Paths

/

bin etc users tmpbackup

user1user2 … …

usern

public_htmlfile1

index.html

Answer: /users/usern/public_html/index.html

Page 30: BASIC UNIX Tutorial One

30

What is the relative path to index.html (assuming that usern is your working directory)

Specifying Paths

/

bin etc users tmpbackup

user1user2 … …

usern

public_htmlfile1

index.htmlAnswer: public_html/index.html

Page 31: BASIC UNIX Tutorial One

31

• ls [names] – list files contained in a directory name or that match a file name. If no name is given list those files in current directory.• ls –a list all files including hidden files• ls –l list in long format (including details

like permissions, owner, size, etc.), works very much like dir• ls –al list all files (including hidden files)

in long format• ls –dl dir_name lists information about

the directory, “dir_name”.

UNIX Commands

Page 32: BASIC UNIX Tutorial One

32

• pwd –let you know the absolute pathname of your current working directory (Print Working Directory)

• cd [dir] – change directory• cd .. –go back to parent directory. • “..” is the relative pathname to the parent

directory.• “.” stands for current (working) directory.• “~” – the tilde character can refer to your

home directory.

UNIX Commands (Con.)

Page 33: BASIC UNIX Tutorial One

33

• mkdir directories – create one or more directories. You can specify them by absolute or relative pathnames.

• cp• cp file1 file2 – copy file1 to file2. If there’s

already a file2, the old one will be overwritten.• cp file(s) directory – file(s) will be copied to the

directory.

UNIX Commands (Con.)

Page 34: BASIC UNIX Tutorial One

34

• mv sourcefile targetfile – • basically mv renames sourcefile to targetfile. • If there’s a file with the same name as targetfile,

it will be overwritten. • mv works for directories in a similar fashion.

UNIX Commands (Con.)

Page 35: BASIC UNIX Tutorial One

35

• rm file(s) – delete file(s).

• rmdir directories – delete one or more empty directories.

• rm –r directories – can be used to delete non empty directories.

• WARNING!!! This will DELETE EVERYTHING in that directory!!!

• You can not recover your files after you removed them (unlike Windows OS).

UNIX Commands (Con.)

Page 36: BASIC UNIX Tutorial One

36

• There are three types of file access supported by UNIX.

• r – read, view the contents of a file or a directory• w –write, edit file/directory contents• x –execute, run executable file

Permissions (file access)

Page 37: BASIC UNIX Tutorial One

37

• User – the person who created the file.• Group – the group owns the file.• Other – the rest of the world.

• “754” is a decimal number. But you can represent each digit with a binary number.

• 4 => read permission, • 2 => write permission, • 1=> execute permission

Permissions (Con.)

Page 38: BASIC UNIX Tutorial One

38

rwx r-x r--

Permissions (Con.)

4 + 2 + 1

7 5 44 + 0 + 1 4 + 0 + 0

USER ACCESS GROUP ACCESS

OTHER’S ACCESS

read=4; write= 2; execute=1, ‘-’ = 0

Page 39: BASIC UNIX Tutorial One

39

• {rwx r-x r--} is a symbolic way to specify file modes, while {754} is a numeric way.• 7 111, 5 101, 4100 . • How to represent file mode numerically?

--x --x –wx

Permissions (Con.)

• How to represent bit string symbolically? 6 1 4

1 1 3

Change it to binary numbers

110 001 100rw- --x r--

Page 40: BASIC UNIX Tutorial One

40

• chmod mode file(s) – another UNIX command! Change the access mode of one or more files. Examples: • chmod 751 my_file – the owner of my_file has

rwx(7) permission, the group has r-x(5) permission, others have --x permission.

• What the following command will do?• chmod u=rwx,g=r,o=wr my_file

Permissions (Con.)

Set Permisson as:Owner to have ‘rwx’Group to have ‘r’Other to have ‘rw ‘

Answer: chmod 746 my_file

Page 41: BASIC UNIX Tutorial One

41

• Create a new directory in your grove account named public_html by using the following command,• $ mkdir public_html

• Go to this directory• $ cd public_html

• Create a new file named • $ cat >index.html -- create a file

This is an html file. -- content of the file^D <Ctrl. D> -- closing the file

Practice

Page 42: BASIC UNIX Tutorial One

42

• Viewing the content of the file• $ cat index.html

This is an html file.

• Adding content of the file• $ cat >>index.html

Adding second line to the html file.^D

• Viewing the content of the file• $ cat index.html

This is an html file.Adding second line to the html file.

Practice (Con.)

Page 43: BASIC UNIX Tutorial One

43

OR• Use pico to create a new file named

index.htm

Note: Pico is a simple, display-oriented text editor for UNIX.

Practice (Con.)

Page 44: BASIC UNIX Tutorial One

44

• After you save the file index.html, change the mode of this file by using the following command, • chmod 644 index.html• (u=rw-, g=r--, o=r--)

• Check whether you did it right• ls –l or dir• (What result should be displayed?)

Practice (Con.)

-rwx r-x r-- 1 hans doc 858 Aug 22 22:28 index

Unix file types, permissions, number of hard links, owner, group, size, date, filename

Page 45: BASIC UNIX Tutorial One

45

• Then go back to parent directory• cd ..

• Change the mode of public_html directory• chmod 755 public_html • ( What’s the meaning of this command?)• Ans: u=rwx, g= r-x, o=r-x

• Check if you got the mode set right • ls –dl public_html

Practice (Con.)

Page 46: BASIC UNIX Tutorial One

46

• Some short cuts for the pico editor• ^G Get Help • ^O WriteOut • ^R Read File • ^Y Prev Pg • ^K Cut Text • ^C Cur Pos• ^X Exit • ^J Justify • ^W Where is • ^V Next Pg • ^U UnCut Text • ^T To Spell

Pico Editor

Page 47: BASIC UNIX Tutorial One

47

CygWin Emulator• http://www.cygwin.com

• Clear screen: $ ^L <Ctrl + L>• For Help: $ help• To exit/close: $ exit• Help on command: $ command_name --help

Page 48: BASIC UNIX Tutorial One

48

• Listing files and directories • Making Directories• Changing to a different directory • The directories . and .. • Pathnames • home directories

Basics UNIX command 1

Page 49: BASIC UNIX Tutorial One

49

• Copying Files• Moving Files• Removing Files and directories• Displaying the contents of a file on the

screen• Searching the contents of a file

Basics UNIX command 2

Page 50: BASIC UNIX Tutorial One

50

• Wildcards• Filename Conventions• Getting Help

Basics UNIX command 3

Page 51: BASIC UNIX Tutorial One

51

• File system security (access rights)• Changing access rights• Processes and Jobs• Listing suspended and background

processes• Killing a process

Basics UNIX command 4

Page 52: BASIC UNIX Tutorial One

52

Thank You