0% found this document useful (0 votes)
3 views

Unix Shell

The document provides an overview of the UNIX operating system, its architecture, and key components such as the kernel, shell, and file system. It covers basic file attributes, process management, simple filters, regular expressions, and shell programming essentials. Additionally, it discusses command structures, internal and external commands, and features like multitasking, security, and portability.

Uploaded by

bestyourtuber
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Unix Shell

The document provides an overview of the UNIX operating system, its architecture, and key components such as the kernel, shell, and file system. It covers basic file attributes, process management, simple filters, regular expressions, and shell programming essentials. Additionally, it discusses command structures, internal and external commands, and features like multitasking, security, and portability.

Uploaded by

bestyourtuber
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Unit 1: UNIX Architecture (08 Hours)

The UNIX Operating System


• Introduction: UNIX is a powerful, multiuser, multitasking operating system originally developed in the 1960s
and 1970s at AT&T's Bell Labs. It forms the foundation of many modern operating systems, including Linux.
• LINUX and GNU: Linux is a UNIX-like operating system kernel developed by Linus Torvalds. The GNU (GNU's
Not Unix) project provides a collection of free software, aiming to create a free UNIX-like operating system.
The UNIX Architecture
• Architecture Overview: UNIX consists of several key components:
o Kernel: The core of the operating system, managing hardware resources and system calls.
o Shell: A command-line interpreter that allows users to interact with the kernel.
o File System: Organizes and stores files and directories.
o Utilities: Standard tools and applications for performing common tasks.
Features of UNIX
• Multiuser Capability: Multiple users can access the system simultaneously.
• Multitasking: The ability to run multiple processes concurrently.
• Portability: UNIX can run on various hardware platforms.
• Security: Robust security features, including file permissions and user authentication.
POSIX and Single UNIX Specification
• POSIX (Portable Operating System Interface): A set of IEEE standards designed to maintain compatibility
between operating systems. POSIX defines APIs, command line interfaces, and utility interfaces for UNIX-like
operating systems.
• Single UNIX Specification: A standard that defines the requirements for an operating system to be
considered UNIX. It ensures interoperability and compatibility across different UNIX systems.
Internal and External Commands
• Internal Commands: Built into the shell and executed directly by it (e.g., cd, echo).
• External Commands: Separate executable programs stored in the file system (e.g., ls, grep).
Command Structure
• Syntax: UNIX commands follow a consistent syntax: command [options] [arguments]
• Examples:
o ls -l: Lists directory contents in long format.
o grep 'text' file.txt: Searches for 'text' in file.txt.
Man Browsing and Manual Pages On-line
• Man Pages: Manual pages provide documentation for UNIX commands and functions. They can be accessed
using the man command followed by the command name (e.g., man ls).
• Sections: Man pages are divided into sections like User Commands, System Calls, and Library Functions.
The File System
• Parent-Child Relationship: Directories can contain subdirectories, creating a hierarchical structure.
• The Home Variable: $HOME stores the path of the user's home directory.
• Common Commands:
o pwd: Prints the current working directory.
o cd: Changes the current directory.
o mkdir: Creates a new directory.
• Pathnames:
o Absolute Pathname: Specifies the complete path from the root directory (e.g., /home/user/docs).
o Relative Pathname: Specifies the path relative to the current directory (e.g., ../docs).
Unit 2: Basic File Attributes and The Process (10 Hours)
Basic File Attributes
• Listing Directory Contents: The ls command lists directory contents. Options like -l provide detailed
information.
• The UNIX File System: Organizes files into a hierarchical directory structure. Files and directories have
attributes like name, size, permissions, and timestamps.
• Using ls -l and -d Option:
o ls -l: Displays detailed information, including permissions, ownership, size, and modification time.
o ls -d: Lists directories themselves, rather than their contents.
• File Ownership: Each file has an owner and a group. The chown command changes file ownership.
• File Permissions: Define read, write, and execute permissions for the owner, group, and others. The chmod
command modifies file permissions.
o Syntax: chmod [permissions] file
o Examples:
▪ chmod 755 file: Sets read, write, and execute permissions for the owner, and read and
execute permissions for the group and others.
▪ chmod u+x file: Adds execute permission for the owner.
The Process
• Process Basics: A process is an instance of a running program. Each process has a unique process ID (PID).
• Process Status: The ps command displays information about running processes.
• System Processes: Options like ps -e or ps -a show all system processes.
• Mechanism of Process Creation: The fork() system call creates a new process (child) by duplicating the
existing process (parent).
• Process States: A process can be in states like running, waiting, or stopped. Zombies are processes that have
completed execution but still have an entry in the process table.
• Running Jobs in Background: The & operator runs a command in the background, allowing the user to
continue working in the shell.

Unit 3: Simple Filters and Regular Expressions (10 Hours)


Simple Filters
• pr: The pr command formats text files for printing. It can add headers, footers, page numbers, and handle
multiple columns.
• head: Displays the first few lines of a file. By default, it shows the first 10 lines, but this can be adjusted using
the -n option.
• tail: Shows the last few lines of a file, also defaulting to 10 lines. The -f option can be used to follow the file as
it grows.
• cut: Extracts specific columns or fields from a file. The -d option specifies the delimiter, and the -f option
selects fields.
• paste: Merges lines from multiple files. It pastes the content side-by-side, separated by a tab or specified
delimiter.
• sort: Sorts lines in a file. Options like -n for numerical sorting and -r for reverse sorting are available.
• uniq: Removes duplicate lines from a sorted file. The -c option can count occurrences.
• tr: Translates or deletes characters. For example, it can be used to convert lowercase letters to uppercase.
Filters Using Regular Expressions
• grep: Searches for patterns in files using regular expressions. Variants include egrep (supports extended
regex) and fgrep (searches for fixed strings).
• Basic Regular Expressions (BRE): Supported by grep, BRE includes simple patterns and special characters like
. (any single character), * (zero or more occurrences), ^ (start of line), and $ (end of line).
• Extended Regular Expressions (ERE): Supported by egrep, ERE includes additional features like + (one or
more occurrences), ? (zero or one occurrence), and | (alternation).
• sed (Stream Editor): A powerful text processing tool. It can perform basic text transformations like
substitution (s/old/new/), deletion (d), and insertion (i).
o Line Addressing: Allows targeting specific lines for editing using line numbers or patterns.
o Multiple Instructions: Can be specified using -e for multiple commands or -f to read commands from
a file.
o Context Addressing: Applies commands to lines that match specific patterns.
Unit 4: The Shell (12 Hours)
The Shell’s Interpretive Cycle
• Overview: The shell interprets and executes user commands. It reads commands, interprets them, executes
them, and displays the results.
• Process:
1. Prompt: The shell displays a prompt and waits for input.
2. Reading: It reads the input from the user.
3. Tokenizing: The input is broken into tokens (commands, options, arguments).
4. Execution: The shell executes the command.
5. Output: The result is displayed to the user.
Shell Offerings
• Different Shells: Common shells include sh (Bourne shell), bash (Bourne Again shell), csh (C shell), ksh (Korn
shell), and zsh (Z shell). Each has unique features and scripting capabilities.
Pattern Matching
• Wildcards: Symbols like * (matches any string) and ? (matches any single character) are used for matching
filenames and strings.
• Globbing: The process of pattern matching using wildcards.
Escaping and Quoting
• Escaping: Using the backslash \ to treat special characters literally.
• Quoting:
o Single Quotes (''): Preserve the literal value of characters.
o Double Quotes (""): Preserve the literal value except for $, `, and \.
Redirection
• Standard Input/Output:
o Input (<): Redirects input from a file.
o Output (>): Redirects output to a file, overwriting it.
o Append (>>): Redirects output to a file, appending to it.
• Error Redirection (2>): Redirects standard error.
Pipes
• Definition: Used to pass the output of one command as input to another. Syntax: command1 | command2.
tee
• Function: Reads from standard input and writes to both standard output and one or more files. Useful for
logging.
Command Substitution
• Syntax:
o Backticks (` `): result=$(command).
o $(command): Executes command and substitutes its output.
Shell Variables
• Types:
o Environment Variables: Affect the environment in which processes run (e.g., PATH, HOME).
o User-Defined Variables: Custom variables created by the user.
• Syntax:
o Defining: VAR=value.
o Accessing: $VAR.
Essential Shell Programming
• Scripting: Writing scripts to automate tasks.
• Basic Constructs:
o Conditionals: if, else, elif, case.
o Loops: for, while, until.
o Functions: Defining reusable blocks of code with function name { commands }.

You might also like