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

Unit i Linux

Unix is a robust, multiuser, multitasking operating system known for its portability, security, and modularity. It features a hierarchical file system, supports various shell types for command-line interaction, and allows efficient process management and networking capabilities. The document also details the Unix file system structure, commands for file creation and manipulation, and the concept of inodes for file access.

Uploaded by

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

Unit i Linux

Unix is a robust, multiuser, multitasking operating system known for its portability, security, and modularity. It features a hierarchical file system, supports various shell types for command-line interaction, and allows efficient process management and networking capabilities. The document also details the Unix file system structure, commands for file creation and manipulation, and the concept of inodes for file access.

Uploaded by

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

Salient features of Unix

Unix is a powerful, multiuser, multitasking operating system widely known for its robustness,
portability, and versatility. Here are the salient features of Unix:
1. Portability
 Unix is designed to be hardware-independent, meaning it can run on a wide range of
hardware platforms with minimal modifications. This is achieved by writing the
majority of the system in C, a high-level language.
2. Multitasking
 Unix supports multiple tasks running simultaneously. Each task, or process, operates
independently, making it suitable for server and high-performance computing
environments.
3. Multiuser System
 Unix allows multiple users to work on the same system at the same time. Each user
can have a separate environment and permissions to ensure security and resource
management.
4. Hierarchical File System
 Unix uses a tree-structured file system where files are organized into directories
(folders). This structure makes data management intuitive and efficient.
5. Security
 Unix provides robust security features, such as:
 File permissions (read, write, execute) for the owner, group, and others.
 Password-protected user accounts.
 Encrypted data transfer using tools like SSH.
6. Shell Interface
 Unix provides a command-line interface (CLI) through its shell. Users can interact
with the system using powerful commands and shell scripting for automation.
7. Modularity
 Unix is built on the principle of "small is beautiful," with many small, modular
utilities that perform specific tasks. These can be combined (via pipes and redirection)
to achieve complex operations.
8. Process Management
 Unix efficiently manages processes, allowing users to:
 Create and terminate processes.
 Assign priorities.
 Use features like foreground and background process execution.
9. Networking
 Unix has built-in support for networking, making it ideal for servers and systems
requiring remote communication. Features like FTP, SSH, and mail services are
integral.
10. Shell Scripting
 Unix supports scripting in its shell (e.g., Bash, C shell, Korn shell). Scripts can
automate repetitive tasks and perform complex operations.

FILE SYSTEM ORGANIZATION


The file system organization in a Unix operating system is hierarchical, meaning it is
structured as a tree-like directory structure with the root directory (/) at the top. This
organization allows efficient management, retrieval, and storage of files and directories.
Below is an overview of how the Unix file system is organized:

1. Root Directory (/)


 The root directory is the topmost directory in Unix.
 All other directories and files are organized under this directory.

2. Standard Directories
The Unix file system is organized into standard directories, each serving a specific purpose:
 /bin (Binaries):
o Contains essential command binaries (programs) needed by all users, such as
ls, cat, cp, etc.
 /sbin (System Binaries):
o Contains essential system binaries used for system administration, such as
ifconfig, reboot, etc.
 /etc (Configuration Files):
o Holds system-wide configuration files and scripts, such as passwd, hosts, and
fstab.
 /home (User Home Directories):
o Contains personal directories for each user, e.g., /home/user1 and /home/user2.
 /root (Root User's Home Directory):
o The home directory for the superuser (administrator).
 /var (Variable Files):
o Contains files that are expected to change frequently, such as logs (/var/log),
mail (/var/mail), and temporary data.
 /tmp (Temporary Files):
o Used to store temporary files that may be cleared after a reboot.
 /usr (User System Resources):
o Holds user utilities and applications. Subdirectories include:
 /usr/bin: Non-essential binaries for users.
 /usr/lib: Libraries for applications in /usr/bin.
 /usr/share: Shared files like documentation and icons.
 /lib (Libraries):
o Contains shared library files essential for binaries in /bin and /sbin.
 /dev (Device Files):
o Contains device files that represent hardware components like disks
(/dev/sda), terminals (/dev/tty), and printers.
 /proc (Process Information):
o A virtual directory that provides information about system processes and
kernel in real-time.
 /sys (System Information):
o Contains information about the system's hardware and kernel modules.
 /opt (Optional Software):
o Used to install third-party or optional software packages.

TYPES OF SHELL
In Unix and Linux, a shell is a command-line interface that allows users to interact with the
operating system by executing commands, running scripts, and managing system tasks.
1. Bourne Shell (sh)
 Developer: Stephen Bourne at AT&T Bell Labs.
 Description:
o One of the earliest Unix shells and the foundation for many modern shells.
o Focused on scripting with powerful programming constructs.
 Path: /bin/sh
 Features:
o Simple syntax for scripting.
o Limited interactivity compared to modern shells.
 Uses: Writing shell scripts for portability.
2. C Shell (csh)
 Developer: Bill Joy at the University of California, Berkeley.
 Description:
o A shell with C-like syntax for scripting.
 Path: /bin/csh
 Features:
o Built-in support for aliases.
o Job control features.
o History substitution.
 Limitations: Poor error handling in scripts compared to Bourne-based shells.
3. Korn Shell (ksh)
 Developer: David Korn at AT&T Bell Labs.
 Description:
o Combines features of Bourne Shell and C Shell.
 Path: /bin/ksh
 Features:
o Command-line editing.
o Advanced scripting features (arrays, floating-point arithmetic).
o Job control.
 Uses: Preferred for scripting in enterprise environments.

UNIX FILE SYSTEM


The Unix file system is a hierarchical structure that organizes and stores data in files and
directories. It provides an efficient, flexible, and standardized way to manage files and
resources in the Unix operating system. Below are the key features, components, and
structure of the Unix file system:
Key Features of the Unix File System
1. Hierarchical Structure:
o Organized as a tree-like structure with the root directory (/) at the top.
o All files and directories are part of a single unified directory tree.
2. Everything is a File:
o Files, directories, devices (e.g., disks, printers), and even network sockets are
represented as files.
3. File Types:
o Regular files (e.g., text, binary).
o Directories (contain other files and directories).
o Special files:
 Character device files (e.g., /dev/tty).
 Block device files (e.g., /dev/sda).
o Symbolic links (shortcuts to other files).
o Named pipes and sockets.
4. Mounting File Systems:
o External file systems (e.g., USB drives, network file systems) are mounted at
specific directories within the file tree.
5. File Permissions:
o Each file has permissions for the owner, group, and others (read, write,
execute).
6. Inodes:
o Metadata (file size, permissions, timestamps) is stored in inodes, separate from
file data.
Structure of the Unix File System
1. Root Directory (/)
o The top-level directory in the Unix file system. All other files and directories
branch from here.
2. Standard Directories The Unix file system is organized into standard directories for
specific purposes:
Directory Purpose

/bin Essential binaries (e.g., ls, cp, mv) for basic system operation.

/sbin System binaries (e.g., fsck, reboot) for administrative tasks.

/etc Configuration files (e.g., passwd, hosts).

/home Home directories for users (e.g., /home/user1).

/root Home directory for the root (superuser).

/lib Shared libraries required by binaries in /bin and /sbin.

/var Variable files like logs (/var/log), mail (/var/mail), and caches.

/tmp Temporary files, cleared on reboot.

User programs, libraries, and documentation. Subdirectories include:


/usr
/usr/bin, /usr/lib, /usr/share.

/opt Optional software and add-on packages.

/boot Boot loader files and the kernel.

/dev Device files for hardware devices (e.g., /dev/sda for hard drives).

File System Operations


1. File Manipulation:
o Create: touch, mkdir.
o Delete: rm, rmdir.
o Move/Rename: mv.
o Copy: cp.
2. File Navigation:
o List: ls.
o Change directory: cd.
o Current directory: pwd.
3. File Permissions and Ownership:
o View permissions: ls -l.
o Change permissions: chmod.
o Change ownership: chown.
4. Disk and File System Management:
o Check disk usage: df, du.
o Mount a file system: mount.
o Unmount a file system: umount.

File System Hierarchy Standard (FHS)


 Defines the directory structure and directory contents.
 Ensures consistency across Unix-like systems.

Advantages of the Unix File System


1. Simplicity: The hierarchical structure is intuitive and easy to use.
2. Flexibility: Supports various file systems (e.g., ext4, xfs, ntfs) through mounting.
3. Security: File permissions ensure controlled access to resources.
4. Scalability: Suitable for systems ranging from small devices to large servers.
5. Portability: Scripts and programs written for Unix are portable across systems.

CREATING FILES
Creating files in the Unix operating system can be done using several commands and tools.
1. Using the touch Command
 The touch command creates an empty file if it does not already exist.
 If the file exists, it updates the file's timestamp.

2. Using the cat Command


 The cat command is typically used to display or concatenate files but can also create
files interactively.

 This creates a file named myfile.txt and lets you enter its content directly.
 Use Ctrl+D to signal the end of input.

3. Using the echo Command


 The echo command writes text to a file.

This creates a file named myfile.txt with the text "Hello, Unix!" inside it.
4. Using the vi or vim Editor
 Interactive text editors like vi or vim can be used to create and edit files.

This opens the vi editor. You can start typing after entering insert mode by pressing i.
Save the file by pressing Esc, typing :wq, and hitting Enter.

Listing Files and Directories


In Unix, you can list files and directories using various commands. The most commonly used
command for this purpose is ls. Below is a detailed explanation of how to list files and
directories:
1. Basic ls Command
 The ls command lists the files and directories in the current working directory.

Common Options:
 ls -l: Displays detailed information (permissions, ownership, size, modification date).
 ls -a: Shows all files, including hidden files (those starting with a dot .).
 ls -lh: Displays file sizes in a human-readable format (e.g., KB, MB).
 ls -R: Recursively lists files in subdirectories.
 ls -t: Sorts files by modification time.
 ls -r: Reverses the sort order.

Directory Permissions
In Unix, directory permissions define who can read, write, and execute (access) a directory.
Each file and directory has three levels of permissions for three types of users. Here’s a
breakdown:
Structure of Permissions
Permissions are displayed as a string when using ls -l (e.g., drwxr-xr--):
Example Breakdown: drwxr-xr--
 First character (d): Indicates the type:
o d: Directory
o -: Regular file
o l: Symbolic link
 Next nine characters: Indicate permissions, divided into three groups:
1. Owner (user): rwx (read, write, execute)
2. Group: r-x (read, no write, execute)
3. Others: r-- (read, no write, no execute)

Permission Types
 Read (r):
o View the contents of the directory (list files).
 Write (w):
o Create, delete, or rename files in the directory.
o Requires execute (x) permission to take effect.
 Execute (x):
o Access (cd into) the directory.
o Without execute permission, you cannot enter the directory even if you can list
its contents.

Bit of Mathematics
Unix provides several command-line tools for performing basic mathematical operations
directly in the shell.
1. expr
The expr command is used for simple arithmetic and string operations in Unix.
Example
2. factor
The factor command is used to find the prime factors of a number.
Example

3. bc (Basic Calculator)
The bc command is a powerful calculator that supports floating-point arithmetic and more
advanced mathematical operations.
Example
4. Square Root (sqrt)
The sqrt function is available through bc for square root operations. Ensure you use the scale
variable for precision.
Example:

Directory related commands


In Unix, there are several commands specifically for working with directories. Here's a list of
commonly used directory-related commands:

1. Navigating Directories
 pwd (Print Working Directory): Displays the current directory.
Blocks
In Unix operating systems, "blocks" refer to fixed-size chunks of data that are used to manage
and store information on disk. The size of a block is typically 512 bytes, 4 KB, or larger,
depending on the file system.Understanding blocks is essential when dealing with file
systems, storage, and performance.
Boot Blocks
 Purpose: Contain boot-related information for the file system or operating system.
 Typically located at the beginning of the disk.
 Store the boot loader, which is responsible for loading the operating system into
memory.
Superblock
 Purpose: Stores critical information about the file system itself.
 Contains:
o File system size
o Block size
o Number of inodes and data blocks
o File system state (e.g., clean, needs repair)
o Location of free blocks and inodes
 The superblock is crucial for file system integrity and recovery.
 Typically, multiple copies of the superblock are stored for redundancy.

Inode Blocks
 Purpose: Store metadata about files and directories.
 Each file or directory is represented by an inode, which contains:
o File type (regular file, directory, symbolic link, etc.)
o File size
o File ownership (user and group IDs)
o Permissions
o Timestamps (creation, modification, access)
o Pointers to data blocks
 Inode blocks do not store the actual file content—only metadata and pointers.
Data Blocks
 Purpose: Store the actual content of files.
 Files in the file system are split into fixed-size chunks (blocks) and stored here.
 For small files, a single data block may suffice; larger files require multiple blocks.

How does Unix access files


In Unix, files are accessed using inodes (Index Nodes), which are data structures containing
metadata and pointers to the data blocks of a file. Each file or directory has a unique inode,
and the file system uses this inode to locate and manage files.
Each inode contains:
 File Metadata:
o File type (regular file, directory, symbolic link, etc.)
o File size
o File permissions (read, write, execute)
o Ownership (user ID and group ID)
o Timestamps (creation, modification, and last access times)
 Pointers to Data Blocks:
o Addresses of the blocks where the actual file data is stored.
o If the file is large, the inode uses indirect blocks for additional pointers.
Commands

Key Advantages of Using Inodes


1. Separation of File Name and Metadata:
o File names are stored in directory entries, while file information is in inodes.
This allows features like hard links.
2. Efficient File Access:
o The inode structure allows direct mapping to data blocks, minimizing disk
operations.
3. Support for Large Files:
o The indirect block mechanism enables handling files larger than the inode's
direct pointer capacity.

Disk related commands


disk-related commands in Unix/Linux for managing and monitoring disk usage, partitions,
and file systems:
1. Disk Space Usage
df (Disk Free)
 Displays disk space usage of file systems.
 Common Usage:
du (Disk Usage)
 Displays the space used by files and directories.
 Common Usage:

You might also like