BIL 101E Introduction to Computers and Information Systems Spring 2006.

40
BIL 101E Introduction to Computers and Information Systems Spring 2006

Transcript of BIL 101E Introduction to Computers and Information Systems Spring 2006.

Page 1: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101EIntroduction to Computers and

Information Systems

Spring 2006

Page 2: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 2

Unix History The unfinished development of OS Multics at Bell

Laboratories in 1965 left them without a good OS.

Ken Thopson and Dennis Ritchie decided to sketch out an OS for BL.

Ken Thompson implemented it on PDP-7. As a pun on Multix he named the new operating system Unix.

A new programming language C was developed for implementation of Unix and 95% of this operating system was written in C - therefore Unix is a very good portable system.

Page 3: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 3

Linux History

Linux was written by Linus Torvalds and has been improoved by countless number of people around the word.

It was initially developed for small PC.

Page 4: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 4

multitasking: several programs running at once

multiusers: several users at the same machine at once

multiplatforms: it runs on many different CPU

Linux Features

Page 5: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 5

Getting Started

• You can login to an UNIX operating system after you had been assigned a username by a system administrator.

$login: • Unix/Linux is case sensitive (as the C language).

Username smith is different from Smith • After entering your username you will be faced with the

following:

$password:

Page 6: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 6

• If you have typed your password correctly a prompt will appear. For example:

$

• or a little detailed prompt

marian:~$

Getting Started

Page 7: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 7

UNIX DIRECTORY STRUCTURE

In Unix, the files are organized into a tree structure with a root named by the character '/'. The first few levels of the tree look like this:

Page 8: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 8

UNIX DIRECTORY STRUCTURE

In many systems the user files are subdirectories of a

directory named `home' in root directory ‘/’. If we had

a user tango, for example, tango’s home directory

would be /home/tango, and all his files would be

within that subtree.

Suppose tango's directory looks like this:

Page 9: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 9

UNIX DIRECTORY STRUCTURE

Page 10: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 10

FILE TYPES

There are four types of files in the Unix file system.

Ordinary Files

An ordinary file may contain text, a program, or other data.

It can be either an ASCII file, with each of its bytes being in the numerical range 0 to 127, i.e. in the 7-bit range, or a binary file, whose bytes can be of all possible values 0 to 255, in the 8-bit range.

Page 11: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 11

Directory Files

Suppose that in the directory x I have a, b and c, and that b is a directory, containing files u and v.

Then b can be viewed not only as a directory, containing further files, but also as a file itself.

The file b consists of information about the directory b; i.e. the file b has information stating that the directory b has files u and v, how large they are, when they were last modified, etc.

FILE TYPES

Page 12: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 12

FILE TYPES

Device Files

In Unix, physical devices (printers, terminals etc.) are represented as “files.”

This seems odd at first, but it really makes sense: This way, the same read() and write() functions used to read and write real files can also be used to read from and write to these devices.

Page 13: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 13

Link Files

Suppose we have a file X, and type

ln X Y

If we then run ls, it will appear that a new file, Y, has been created, as a copy of X, as if we had typed

cp X Y

However, the difference is the cp does create a new file, while ln merely gives an alternate name to an old file. If we make Y using ln, then Y is merely a new name for the same physical file X.

FILE TYPES

Page 14: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 14

Listing FilesThe `a' (``all'') and `l' (``long'') options of the ls command will give us a lot of information about files in a specified directory.

ls –al

drwx--x--x 63 tango users 4096 Sep 17 01:33 .drwxr-xr-x 7 root root 4096 Sep 3 16:53 ..drwxr-xr-x 30 tango users 4096 Sep 15 11:44 downloadsdrwxr-xr-x 4 tango users 4096 Jul 25 23:19 evrimdrwxr-xr-x 5 tango users 4096 Sep 17 00:53 foy

1st column - access permissions (see below)2nd column - number of file entries (in the case of directory files)3rd column - owner 4rd column – group5th column - size in bytes6th column - date and time of last modification 7th column - name

Page 15: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 15

File Permissions In Unix, all files are protected under some access control

mechanism, so that the owner of a file can deny access of his files to other users. The first column of the long directory list shows the access characteristics of a file, in te form of 10 flags, e.g.

drwxr-xr-x.

• Position 1 file type: d (directory) - (ordinary file)

l (symbolic link) • Position 2-4 permissions for the owner:

r (read), w (write) , x (execute)• Position 5-7 permissions for other users in the same group• Position 8-10 permissions for all other users

Page 16: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 16

BASIC UNIX COMMANDS• The command line is a place where the commands of a

operating system are called and the results of the commands are seen.

• The commands are the tools that the operations needed by the user to operate the system.

• The basic commands about basic operations, disk operations, administrative or user based operations, network operations are given here.

• Please note that this is not a complete set of commands,

but most commonly used ones are documented here.

Page 17: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - Week4 17

BASIC UNIX COMMANDS

Page 18: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 18

BASIC UNIX COMMANDSls : Lists contents of directories. Directory contents are sorted alphabetically.

–l In addition to the name of each file, prints the file type, permissions, number of hard links, owner name, group name, size in bytes, and timestamp (the modification time).

–a Lists all files in directories, including all files that start with ‘.’.

--color Controls whether color is used to distinguish file types.

ls –lls –als –alls –color

Page 19: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 19

man : Formats and displays the online manual pages. To exit the manual pages ‘q’ character should be used.

man ls

cd : Change directory command allows you to change the present working directory to another one.

cd /home/user1/examples

cd ..

cd ../../

cd ../../ex/project

BASIC UNIX COMMANDS

Page 20: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 20

mkdir: Creates a new directory with each given name.

mkdir bil101

rm: Removes files or directories. By default, it does not remove directories.

-f Ignores nonexistent files, never prompt -i Prompts before any removal-r, -R Removes the contents of directories recursively.

BASIC UNIX COMMANDS

Page 21: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 21

rm ex1

rm *.c

rm *.*

rm –f *.c

rm –i example1

rm –r /home/user2/abc/

BASIC UNIX COMMANDS

rmdir : Removes empty directories. rmdir cse100

Page 22: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 22

cp : Copies files and directories. If the last argument names an existing directory, cp copies each other given file into a file with the same name in that directory. Otherwise, if only two files are given, it copies the first onto the second. It is an error if more than two files are given. By default, it does not copy directories.

–i Prompts whether to overwrite existing regular destination files.–R Copies directories recursively.

cp ex1.c ex2.ccp ex1.c exs/cp ex1.c exs/ex2.ccp –i ex1.c ../exs/cp –R exs/* ../examples/

BASIC UNIX COMMANDS

Page 23: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 23

mv : Moves (renames) files. If the last argument names an existing directory, mv moves each other given file into a file with the same name in that directory. Otherwise, if only two files are given, it moves the first onto the second. It also renames directories.

mv ex1.c ex2.c

mv ex1.c ../exs/ex2.c

BASIC UNIX COMMANDS

Page 24: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 24

mdir: Displays an MSDOS directory. If your floppy disk is DOS-formatted, then you can see the content of your floppy disk by typing

mdir a:mcopy: Copies MSDOS files to/from Unix. If your floppy

disk is DOS-formatted, then you can copy your files from the floopy disk to the harddisk or from the harddisk to the floppy disk without mounting it.

mcopy ex1.c a:.mcopy a:ex2.c .mcopy ex1.c a:ex2.cmcopy a:ex2.c ex3.c

BASIC UNIX COMMANDS

Page 25: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 25

mmd : Makes an MSDOS subdirectory. If your floppy disk is DOS-formatted, then you can create directory in your floppy disk.

mmd dir1mrd : Removes an MSDOS subdirectory. If your floppy

disk is DOS-formatted, then you can remove a directory in your floppy disk.

mrd dir1mcd : Changes MSDOS directory. If your floppy disk is

DOS-formatted, then you can change directory in the floopy disk.

mcd dir2

BASIC UNIX COMMANDS

Page 26: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 26

mdel: Deletes an MSDOS file. If your floppy disk is DOS-formatted, then you can delete a file in your floppy disk.

mdel ex2.c

fdformat: fdformat does a low level format on a floppy disk. Device is usually one of the following:

fdformat /dev/fd0H1440

mformat: Adds an MSDOS filesystem to a low-level formatted floppy disk.

mformat a:

BASIC UNIX COMMANDS

Page 27: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 27

pwd: Prints name of the current working directory.pwd

find: Searches for files in a directory hierarchy. find searches the directory tree rooted at each given pathname by evaluating the given expression from left to right, according to the rules of precedence, until the outcome is known, at which point find moves on to the next pathname.

–name pattern Base of the path matches shell pattern

find / -name *.cfind ./ -name *.cfind /home/user2/ -name *.c

BASIC UNIX COMMANDS

Page 28: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 28

cat : Concatenates files and prints on the standard output.

cat ex3.

cat ex2.c ex5.c

cat ex4.c ex3.c > ex5.

more : more is a filter for paging through text one screenful

at a time.

ls | more

less : Less is a program similar to more, but which allows

backward movement in the file as well as forward movement.

ls | less

BASIC UNIX COMMANDS

Page 29: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 29

chmod : Changes the permissions of each given file according to mode, which can be either a symbolic representation of changes to make, or an octal number representing the bit pattern for the new permissions.

In the symbolic mode a combination of the letters ‘ugoa’ controls which users' access to the file will be changed: the user who owns it (u), other users in the file's group (g), other users not in the file's group (o), or all users (a). The operator ‘+’ causes the permissions selected to be added to the existing permissions of each file; ‘-‘ causes them to be removed. The letters ‘rwx’ select the new permissions for the affected users: read (r), write (w), execute(or access for directories) (x).

chmod u+w ex3.cchmod a-x ex5.c

BASIC UNIX COMMANDS

Page 30: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 30

A numeric mode is from one to four octal digits(0-7), derived by adding

up the bits with values 4, 2, and 1. Any omitted digits are assumed to

be leading zeros. The first digit selects the set user ID (4) and set

group ID (2) and save text image (1) attributes. The second digit

selects permissions for the user who owns the file: read (4), write (2),

and execute (1); the third selects permissions for other users in the

file's group, with the same values; and the fourth for other users not in

the files’s group, with the same values.

-R change files and directories recursively

chmod 755 ex2.c

BASIC UNIX COMMANDS

Page 31: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - Week4 31

BASIC UNIX COMMANDS

Page 32: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 32

chown: Changes file owner and group.

-R operate on files and directories recursively

chown user3 ex3.c

chown –R user4 examples/*

chown user3.user3 ex4.c

chgrp: Changes group ownership.

-R operate on files and directories recursively

chgrp user5 ex6.c

chgrp –R user6 examples/*a

BASIC UNIX COMMANDS

Page 33: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 33

du: Estimates file space usagedu exs/

gzip: Compresses files.-c Write output on standard output; keep original

files unchanged.gzip –c final/ > fin.gz

gunzip: Expands files. gunzip can decompress files created by gzip.

-c Write output on standard output; keep original files unchanged.

gunzip –c fin.gz

BASIC UNIX COMMANDS

Page 34: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 34

tar: It is an archiving program designed to store and extract files from an archive file.

-c create a new archive-f use archive file-z filter the archive through gzip-v verbosely list files processed-x extract files from an archive

tar cvfz str.tgz /home/user1/tar xvfz str.tgz

paswd: Updates a user's authentication tokenspasswdpasswd user5

whoami : Prints the user name associated with the current effective user id.

whoami

BASIC UNIX COMMANDS

Page 35: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 35

ps: Reports process status. Ps gives a snapshot of the current processes. It returns the process id knowledge.

-A select all processes-a select all with a tty except session leadersT select all processes on this terminala select all processes on a terminal, including those of other usersx select processes without controlling ttysu display user-oriented format

ps aux ps xps ups a

kill: Terminates a process kill sends the specified signal to the specified process. The process id can be read by the help of the ps command.

kill –9 125

BASIC UNIX COMMANDS

Page 36: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 36

ssh: (SSH client) is a program for logging into a remote machine and for executing commands on a remote machine. It is intended to replace rlogin and rsh, and provide secure encrypted communications between two untrusted hosts over an insecure network.

ssh [email protected]

scp: secure copy (remote file copy program)

scp file [email protected]:~/directory1

BASIC UNIX COMMANDS

Page 37: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - WEEK4 37

startx: The startx script is a front end to xinit that provides a somewhat nicer user interface for running a single session of the X Window System. It is typically run with no arguments.

Startxlogout: Exits from the current user.

Logoutreboot: Stops the system.

Rebootpoweroff: Stops the system.

Poweroff

BASIC UNIX COMMANDS

Page 38: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - Week4 38

Text Editing in UNIX EnvironmentsIn many UNIX environments like GNU/Linux, the system

provides more than one text editor. We will discuss vi, joe and pico here.

VI: Vi stands for visual, because it was an early text editor that actually showed you the text you were creating and what the resulting changes looked like. Vi is generally available on every UNIX system you might come across for the rest of your life.

:w writes the file to disk (if "file" is already defined):q quit vi:wq save some typing: same as :w and then :q

Page 39: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - Week4 39

Text Editing in UNIX EnvironmentsJOE

JOE is a powerful text editor with many capabilities. Above is a screen shot of the help screen of JOE.

Page 40: BIL 101E Introduction to Computers and Information Systems Spring 2006.

BIL 101E - Week4 40

Text Editing in UNIX EnvironmentsPico

This editor has all the basic functions for beginners and a quick solution to editing text files for everyone.