Terms

What is Unix/Linux ? Operating System

What is Operating System ?

An operating system (OS) is software that manages the resources of a computer Like most managers, the OS aims to manage its resources in a safe and efficient way Examples of computer resources are: CPU,RAM, disk memory, printers, displays, keyboard, mouse, etc
The OS also isolates users and application programmers from the underlying computer
It sends messages to each application or interactive user (or to a system operator) about the status of operation and any errors that may have occurred.On computers that can provide parallel processing, an operating system can manage how to divide the program so that it runs on more than one processor at a time


Operating System-Unix

  • A popular multi-user, multi-tasking OS.
  • Unix provides true multi-user, multitasking, protected memory operation, while using a minimal amount of memory. Unix also provides solid user security via its account validation and authentication. In Unix, everything is a file, including the terminal and all devices, which simplifies input/output operations. Linux is very portable, which means it can run on a number of different hardware platforms, making it easy for users to install on whatever hardware they choose to use.
  • Unix makes a great platform for utility servers such as Domain Name System, or DNS, Dynamic Host Configuration Protocol, or DHCP, and Web servers. Its lean architecture preserves resources for the actual applications that you want to run, rather than consuming them just to boot the operating system itself. Unix also provides a stable and secure platform for applications that do not require direct user interaction with the operating system.
  • Has been around since the 1960s in various forms,e.g., AIX, SCO Unix, SunOS, FreeBSD, OpenBSD,NetBSD, Linux, Mac OS X.
  • Designed by programmers for programmers.



Unix Kernel

  • Includes device drivers for computer hardware devices, e.g., graphics cards, network cards, disks.
  • A device driver is a program that allows computer programs to interact with hardware devices.
  • CPU and memory management.
  • File system management.
  • Implements system calls that can be used by application programs and system utilities.
  • Kernel schedules tasks manages data/file access and storage enforces security mechanisms performs all hardware access.
  • The UNIX Operating System Consists of
    • Kernel
    • Shell
    • utilities

Unix Shells and GUIS

  • Shells are used for command line input/output to and from users
    e.g., sh(Bourne shell), bash (Bourne again shell), csh(C shell), ksh(Kornshell)
  • GUIs are used for graphical I/O
    e.g., Linux KDE, GNOME, Mac OS Leopard
  • Daemons provide remote network and administration services
    e.g.

    • ssh(remote login)
    • lpd(remote printing)
    • httpd(serves web pages)



Unix Application Programs

  • This is the software that users commonly interact with e.g.
    • vi and emacs(text editors)
    • gcc(GNU C compiler)
    • javac(Java compiler)
    • java (Java run time virtual machine system)

What is a programming language?

  • A programming language is an artificial language designed to express computations that will be executed on a computer.
  • Programming languages have a syntax (form) and semantics (meaning).
  • Java and C are example programming languages.

What is a Virtual Machine -VM ?

  • A virtual machine (VM) is a software implementation of a computer that executes programs like a physical computer.
  • A system VM implements a complete computer that can support the execution of a real OS (e.g., vmware, KVM).
  • A process VM is designed to run a single program (e.g., Java VM)
  • Improves program portability, i.e., the ability to reuse software on a different platform with little or no modification.



Unix File system

  • Ordinary Files
    • Files contain data, program code, etc
    • File names cannot have the ‘/’ character in them
  • Directories
    • Contain files and other directories
  • Links
    • A link is a pointer reference to another file (like an alias)
  • Devices
    • Allows applications to access hardware devices

Commands for Navigating the File systems

  • Unix Command Syntax
    • all commands have a similar format
    • commands are generally two to five characters long
    • commands are case sensitive
    • options always preceed filenames
    • options are prefixed using a -symbol
    • the man command can be used to display the correct syntax

UNIX Standard Devices

  • There are THREE standard devices supported by the UNIX shell
  • these devices may be redirected to another device or file
  • standard output (stdout) is associated with the users terminal display
  • standard input (stdin) is associated with the users terminal keyboard
  • standard error (stderr) is associated with the users terminal display

Device Redirection

  • The standard devices may be redirected to a device or file
  • other devices can be printers, terminals
  • devices appear as files in the /dev subdirectory
  • the symbol > changes the standard output device
  • the symbol < changes the standard input device

PIPES in UNIX

  • Allow commands to be combined in a sequential order
  • connects stdoutof one program to the stdinof the next program
  • the symbol | (vertical bar) represents a pipe
  • any number of commands can be connected in sequence, forming a pipeline
  • all programs in a pipeline execute at the same time
  • complex operations are easily performed by piping commands

WildCard Characters & Programs In The Background

  • used to match characters in filenames
  • the asterisk * matches any sequence of zero or more characters
  • the question mark ? matches exactly one character
  • Lets the user carry on with more important tasks
  • examples are printing and formatting documents
  • the ampersand symbol (&) is appended to the command
  • the shell assigns a process number (pid) to the command
  • background jobs can be deleted using the kill command

The UNIX File System

  • The file system refers to the way in which UNIX implements files and directories. In UNIX, a file system has the following features:
    • hierarchical structure (support for directories)
    • files are expandable (may grow as required)
    • files are treated as byte streams (can contain any characters)
    • security rights are associated with files and directories(read/write/execute privledgefor owner/group/others)
    • files may be shared (concurrent access)
    • hardware devices are treated just like files

What is a file ?

  • A file is a collection of information, which can be data, an application, documents; in fact, under UNIX, a file can contain anything. When a file is created, UNIX assigns the file a unique internal number (called aninode).

What is a file Link ?

  • A file link is a directory entry which points to an original file somewhere else. A link is made to an existing file using the ln command.
  • This creates a directory entry which points to the existing file (it does not make a copy of the existing file). This allows more than one reference to an existing file.

What are the security rights associated with files and directories ?

  • UNIX provides three sets of security rights for each file and directory entry. These sets are for the owner, the group to the owner belongs, and any other users on the system.
  • The security rights are
    • read (read, display, copy the file contents)
    • write (modify and append to the file contents)
    • execute (run the file as a program)
  • Files are listed using the ls command.
  • Security rights for a file or directory are modified by using the chmod utility. The owner of the file is changed using the chown command. The group to which the file belongs is changed using the chgrp command.
  • Associated with each file,UNIX keeps the following information.
    • location of the file (location of first 10 block numbers)
    • size in bytes
    • link count
    • ownership
    • security bits
    • type (directory or file)
    • creation date and time
    • modification date and time
    • last accessed date and time

UNIX commands

Basic File Commands
ls – directory listing
ls -al – formatted listing with hidden files
cd dir – change directory to dir
cd – change to home
pwd – show current directory
mkdir dir – create a directory dir rm file – delete file
rm -r dir – delete directory dir
rm -f file – force remove file
rm -rf dir – force remove directory dir *
cp file1 file2 – copy file1 to file2
cp -r dir1 dir2 – copy dir1 to dir2; create dir2 if it doesn’t exist
mv file1 file2 – rename or move file1 to file2 if file2 is an existing directory, moves file1 into directory file2
ln -s file link – create symbolic link link to file
touch file – create or update file
cat > file – places standard input into file
more file – output the contents of file
head file – output the first 10 lines of file
tail file – output the last 10 lines of file
tail -f file – output the contents of file as it
grows, starting with the last 10 lines
For more command : Important Unix Commands

The vi text editor

  • To run vi type the following on the command line:
    $ vi filename
    vi has three modes:
  • command mode:
    to navigate through the document
  • insert mode:
    to add text to the document
  • command line mode:
    to perform manipulations on the files (e.g., search, save)
  • You can use your arrow keys Or you can use the h, j, k, l keys
    • h move left one space
    • j move down one space
    • k move up one space
    • l move right one space
    • You can move faster by typing 5 h to move left 5 spaces, etc
    • ^F go forward in the document by 1 screen
    • ^B go backward in the document by 1 screen
    • ^D go down in the document by half a screen
    • ^U go up in the document by half a screen
    • Note that ^ means hold the control key down e.g.,
    • ^F means hold the control key down and press F.
    • The F,B,D,U characters are non case sensitive
    • G go to the last line in the file
    • n G go to the nth line in the file
    • $ go to the end of the current line
    • ^ go to the beginning of current line
    • (use carat key not control key)
    • 0 same as ^, go to beginning of current line
    • w forward one word, use n w to go forward n words
    • b backward one word, use n b to go backward n words
    • e go to end of the word

The vi text editor Manipulating files

  • w write file to disk (save)

  • :wq write file to disk (save), then exit vi (quit)

  • :w! force overwrite of file

  • :q quit vi if no changes have been made

  • :q! quit vi without saving any of the changes

  • :! command escape to shell and run command

  • :r! command insert the result of command at current cursor position

Unix Networking

  • Most UNIX machines are on the internet. UNIX comes with plenty of utilities that allow you to take advantage of the network.
  • UNIX systems are usually interconnected using TCP/IP (transmission control protocol, internet protocol). This is a protocol mechanism which is widely used by large networks world-wide to interconnect computers of different types.
  • A protocol is a set of rules which govern how computers talk to each other. TCP/IP is a widely used and very popular protocol. With TCP/IP, different computer systems can reliably exchange data on an interconnected network. It also provides a consistent set of application programming interfaces (API’s) to support application development.

Processes in Unix

  • Since UNIX is multi-user multi-tasking it has to keep track of all the programs that it is running for each user. UNIX keeps a process table of all the current processes and their state.
  • The state of a process can be:
    • running -current process that the CPU is processing
    • runnable -is in the queue to be run
    • sleep -waiting for some I/O
    • uninterruptible sleep -the kernel won’t allow you to kill this process
    • stopped or traced process -a stop signal was sent to this process
    • zombie -process is over but did not finish properly
    • As a user you have several ways that you can monitor and manipulate your processes. As a user you only have the right to modify your own processes. You can’t modify others.
    • A process that you are interactive with is in the foreground, while a process that you are not interacting with is in the background. An editor would be in the foreground when you are typing in it, while a backup of your computer is running in the background.
  • Jobs listed all the processes you are running under that shell, however you might have more than one shell open in which case it wouldn’t show you all the processes you are running. TO see all the processes you use the command ps. Different verions of unixhave different options depending on if they are decedents of the system V unix flavors or BSD. The most common options are ps-ef or psaux. This will show every single process running on the machine, including processes owned by other users.



UNIX Shells

  • The UNIX Shell is the users interface to the UNIX operating system.
  • It enables users to run application programs
  • It is run when a user logs into a UNIX host

Features of the UNIX shell

  • interactive
  • The shell presents a prompt and waits for the user to enter a command. After the return key is pressed, the shell processes the command and when the command is finished, the shell re-displays the prompt. This process continues until the user exits the shell, by typing exit or by pessingctrl-d, at which time the user is logged out of the UNIX host.
  • runs programs in the background
  • Non-interactive tasks which do not require keyboard input or display output can be run in the background as a separate task. Theuser continues working with other inter-active programs. Examples of this are printing or sorting files.
  • input/output redirection
  • Programs designed to use the standard input device (keyboard) and standard output device (display) can have their input and output devices redirected to other devices. For example, a program which generally reads from the keyboard can be redirected to readfrom a file instead. A program which writes its output to the display can be instructed to redirect its output to the printer or afile.
  • programs can be chained or connected together via pipes
  • The output of one program can be fed directly into another program by connecting the two programs via a pipe. This allows a userto create powerful new commands by chaining existing commands together.
  • wild-card characters are supported in filenames
  • The handling of files is simplified by using wild-card characters to match files which match particular patterns. Common operations can thus be performed on a group of common files using a single command.
  • script files
  • A number of commonly used commands can be stored in a file, which when executed, runs each command as though it has been typed from the command line. A sequence of commands can be executed by executing the file which contains the command. This simplifies repititiouscommands.
  • environment variables
  • The user can customize and control the behavior of the shell by using special variables that the shell supports. The variables can also be used by application programs and shell script files to control their behavior. An example of a shell variable is the prompt string used to display the shell prompt sign ($).
  • macro language
  • The shell supports a simple language definition for creating shell script files. These can be used to generate very complex command sequences.

UNIX File system

  • All UNIX file system are very similar.
  • All file system have this concept of file tree.
    • Transparent to user even mount point is mapped to a remote file system.
  • To communicate with devices, special device files are used.
  • Sticky Bit
    • Not very popular in today’s system
    • If a directory has sticky bit set, then only the owner can remove file from the directory.
    • /tmp is a good example
  • INODES
    • Kernel maintains file information in a structure called inode.
      • Creation, modification time stamps
      • Ownership, file size etc.
    • Commonly used INODE information can be found by using ls command
    • Group information and be modified by using chgrp command.



Types of Users

  • user(owner): he is the user who create the file.
  • Group: They are the users who belong to the same group that the owner of the file belongs.
  • Others : they are any other users in the system.
  • And there is a super user (the root)is the administrator of the computer system which have access privileges to all files.
  • The login name for the super user is root and user id is 0.

Access Types

The types of access permission are read, write and execute.