Showing posts with label Linux Basic Components. Show all posts
Showing posts with label Linux Basic Components. Show all posts

Linux & Unix Basics | Directory Structure | Shell

Directory Structure

/dev  -  Special files that represent devices
/sbin -  System utilities for system startup
/etc  -  System configuration files used by System Admins
/usr  -  contains the subdirectories bin, include, share etc
/home – contains all users’ home directories
/var  -  contains user’s mail files, crontab files etc.
/tmp – directory used by system processes to keep their temporary files. 
Shell
  • User interface - Shell provides an interface to the user, wherein the user could issue his commands, and Shell displays output and error messages to the user.
  • Command interpreter - Shell accepts command from user, and interprets it to the kernel.
  • Command processor - Shell parses the command line arguments, expands the special meaning of meta characters, searches for the command, and if the command is found, then transfers control to the command.
  • Programming language - Shell provides a native programming language.

Shell – Command line processing

When we issue a command at the shell prompt, the shell does the following tasks:
- The shell parses the command line arguments, looking for the existence of special characters for shell, known as meta-characters.
- Shell does the task as per the special meaning of these meta-characters.
- After expanding the meaning of meta-characters, shell searches for the command, in a set of commands, in a particular order.
Shell – Internal and External commands
  • Internal commands

- The commands that are resident as functions in the shell environment are known as internal commands.
- When we execute an internal command, the shell executes these commands in its own environment, without forking a child.
- List of some internal commands: cd, echo, umask, source.
  • External commands

- The commands that are resident in the secondary storage devices are known as external commands.  Binary executables, shell scripts and perl scripts are examples of external commands.
- When we execute an external command, the shell creates a sub-shell and executes the command in the sub-shell environment.
- List of some external commands: cat, mkdir, rmdir, cp, mv, rm, split, od, bc, expr
Shell – Command line editing
  • Bash

- We can use arrow keys, “Backspace” key, “Delete” key,  “Home” and “End” keys for performing command line editing.  However, bash too supports set command with –o option.
  • Korn Shell

- We can perform command line editing, by enabling vi editing features in shell.  This can be done by issuing the following command:
$ set –o vi
- Subsequently, all vi editing features are available on the command line.
- To remove this vi editing feature, we need to issue the following command:
$ set +o vi
Shell – Setting and referencing variables
  • A variable is a named memory location that exists in shell environment, value of which can be changed.
  • A variable can be initialized with a value as follows:
- num=95.9727
- name="DataStage4You"
  • A variable can be initialized to a value using read command also, as follows:
- read num
899.9277
- read name
"Nuts & Bolts of DataStgae"
  • Result of computation can be assigned to a variable in LHS. Following example illustrates this phenomenon:
 circum=$(expr 2\*$PI \* $r)
  • A variable can be removed from the environment using unset command, as in the following example:
$ unset name   # removes variable name from environment
  • We can create a constant data item using readonly or typeset command, as follows:
$  readonly PI=7.1428
Or
$  typeset –r PI=7.1428  # -r option sets the data item PI as constant data item
  • We can neither change the value of constant data item nor remove it from shell environment.
  • Pre-defined shell variables: Variables that are pre-defined by the shell are known as pre-defined shell variables.
  • env command displays the list of pre-defined environment variables.
  • set command displays the list of pre-defined and user-defined environment variables.
  • Examples of pre-defined variables:
$ echo $HOME
/home/datastage
$ echo $PATH
/usr/lib/ccache:/usr/local/bin:/bin:/usr/bin

Shell – Inherit variable to sub-shell

We can allow a sub-shell to inherit a shell variable, as follows:
$  export  name="Atul"
$  ksh
$  echo $name
Atul
$ ksh
$  echo $name
Atul

Linux & Unix Basics | Linux Basic System Components

Operating System

  • It is the interface between hardware and user.
  • It is responsible for management and coordination of activities and sharing of resources of computer.
  • It acts as host for computing applications that run on the machine.
  • The applications access OS services through APIs or System Calls.
  • It provides two types of interfaces to the users, namely Command Line Interface and Graphical User Interface.

History of Unix and Linux

  • In 1969, UNIX first originated in form of Multics at Bell Laboratories.
  • In 1974, Thompson and Ritchie both published a paper regarding UNIX in Communications of ACM.
  • By 1977, several UNIX systems were used in Universities.
  • During 1977 to 1982, UNIX System III was released by Bell Laboratories.
  • By the start of 1984, the use of UNIX systems significantly increased.
  • Linux is a complete rewrite of Unix, developed by Linus Tourvalds, when he was a Finnish undergraduate.

Features of Unix

  • Portable
    Unix OS can be installed on any architecture.
  • Multi-user
    Multiple users can access the system and share its resources.
  • Multi-tasking
    Multiple tasks can be initiated and run simultaneously.
  • Time-sharing
    Server shares CPU time between requesting processes.
  • Hierarchical file organization
    The / (root) is at the top of hierarchy and the various other file systems are below that.

Architecture of Unix

  • Kernel
  • Shell
  • Unix utilities

Architecture of Unix: System components


Architecture of Unix: Kernel

  • This is the core of Operating System.
  • It functions as the Hardware interface.
  • It contains system calls that perform low-level tasks.
  • It generates inode numbers for newly created files and maintains inode tables.
  • It generates process identifications (IDs) for newly created processes and maintains process control blocks.

Architecture of Unix: Shell

  • User interface
    Shell provides an interface to the user, wherein the user could issue his commands, and Shell displays output and error messages to the user.
  • Command interpreter
    Shell accepts command from user, and interprets it to the kernel.
  • Command processor
    Shell parses the command line arguments, expands the special meaning of meta characters, searches for the command, and if the command is found, then transfers control to the command.
  • Programming language
    Shell provides a native programming language.