WEEK 2: BASIC UNIX

Download Report

Transcript WEEK 2: BASIC UNIX

COMPUTER AND INFORMATION ENGINEERING LAB II
ECE 3102 & ECE 4102
‫ني فَ ْهما‬
ِ ‫ْني ِع ْلما ً َو ْر ُز ْق‬
ِ ‫َر ِّب زد‬
My Lord! Advance me in Knowledge and true understanding .
Laboratory:
Mechatronics Workshop, Room# E2-2-13.12
‫ني فَ ْهما‬
ِ ‫ْني ِع ْلما ً َو ْر ُز ْق‬
ِ ‫َر ِّب زد‬
My Lord! Advance me in Knowledge and true understanding .



Every
computer
operating system.
uses
an
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
3

Multitasking & Multi-user OS.

Unix has user interfaces called
(Terminals)
Shells
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
4
•
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.
5
•
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
operating systems.
•
Unix also inspires novel
software design, such as,
open-source
approaches
to
• solving problems by interconnecting simpler tools
instead of creating large monolithic application
programs.
6
Need to Remember
One single type of Operating
System (OS) can not provide
universal answers to all your
computing needs.
7
• 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.
8
• 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 UNIXlike.
9
o
Kernel
Master control of all computer operations.
•
•
•
•
•
o
Controls access to files,
Allocates resources,
Controls input/output (I/O),
Manages memory.
Applications
Shell
Kernel
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.
10
Shell or Terminal
commands
SHELL OR TERMINAL
11
• 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.
12
• 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
13
Below are a number of system directories (such as
/bin, /lib, /dev) together with the directories for
user files.
14
• 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.
15
• 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 “/”.
16
• 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 “/”.
17
• 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.
18
• 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
19
Examples
Relative Address:
“.” = current directory
“..” = dir. 1 step up
“/” = separates steps
20
Examples (Con.)
• Absolute Address of file ex7.c
/home/lookout/a/fred/c/hmwks/ex7.c
• Using “~” shortcut to “users” level: ~/c/hmwks/ex7.c
21
Examples (Con.)
If working dir. is fred, relative address of ex7.c is
c/hmwks/ex7.c
22
Examples (Con.)
Relative Address of fred to file “data”:
../../../boreas/b/eric/chm/lab1/data
23
• 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”.
24
• Home directory
directory.
might
contain
• public_html
directory
“index.html” file.
might
a
public_html
contain
an
home_directory
public_html
index.html
25
A file cannot hold a directory or a file!
home_directory
public_html
index.html
New_file_or_directory
26
Directories can hold files and other directories
/
bin
users
etc
tmp
backup
usern
user1
user2
……
public_html
file1
index.html
27
• 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.
What is the absolute path to index.html?
/
bin
users
etc
tmp
backup
usern
user1
user2
……
public_html
file1
index.html
Answer: /users/usern/public_html/index.html
29
What is the relative path to index.html
(assuming that usern is your working directory)
/
bin
users
etc
tmp
backup
usern
user1
user2
……
public_html
file1
index.html
Answer: public_html/index.html
30
• 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”.
31
• 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.
32
• 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.
33
• 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.
34
• 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).
35
• 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
36
• 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
37
read=4; write= 2; execute=1, ‘-’ = 0
rwx
4
+
2
r-x
+
1
4
+
0
r--
+
1
4
+
0
+
0
7
5
4
USER ACCESS
GROUP ACCESS
OTHER’S ACCESS
38
• {rwx r-x r--} is a symbolic way to specify file
modes, while {754} is a numeric way.
• 7  111, 5 101, 4100 .
• How to represent file mode numerically?
--x --x –wx
113
• How to represent bit string symbolically?
614
Change it to binary numbers
110 001 100
rw- --x r-39
• 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
Set Permisson as:
Owner to have ‘rwx’
Group to have ‘r’
Other to have ‘rw ‘
Answer: chmod 746 my_file
40
• 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
This is an html file.
^D <Ctrl. D>
-- create a file
-- content of the file
-- closing the file
41
• 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.
42
OR
• Use pico to create a new file named index.htm
Note: Pico is a simple, display-oriented text editor for
UNIX.
43
• 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?)
-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
44
• 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
45
• Some short cuts for the pico editor
•
•
•
•
•
•
•
•
•
•
•
•
^G
^O
^R
^Y
^K
^C
^X
^J
^W
^V
^U
^T
Get Help
WriteOut
Read File
Prev Pg
Cut Text
Cur Pos
Exit
Justify
Where is
Next Pg
UnCut Text
To Spell
46
• http://www.cygwin.com
•
•
•
•
Clear screen:
For Help:
To exit/close:
Help on command:
$
$
$
$
^L <Ctrl + L>
help
exit
command_name --help
47
•
•
•
•
•
•
Listing files and directories
Making Directories
Changing to a different directory
The directories . and ..
Pathnames
home directories
48
Copying Files
Moving Files
Removing Files and directories
Displaying the contents of a file on the
screen
• Searching the contents of a file
•
•
•
•
49
• Wildcards
• Filename Conventions
• Getting Help
50
•
•
•
•
•
File system security (access rights)
Changing access rights
Processes and Jobs
Listing suspended and background processes
Killing a process
51
52