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

Linux Module 1

Uploaded by

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

Linux Module 1

Uploaded by

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

Linux Module 1 (Revision Series)

Sem 4 BCA/B.Sc. Computer Science MGU

For Notes download BCA Resources App


Module 1 Overview
• What is Linux?
• Linux’s root in Unix
• Common Linux Features
• advantage of Linux
• Overview of Unix and Linux architectures,
• Linux files system,
• hardware requirements for Linux,
• Linux standard directories.
• Commands for files and directories cd, ls, cp, rm, mkdir, rmdir, pwd, file,
more, less, Creating and viewing files using cat, file comparisons.
For Notes download BCA Resources App
What is Linux?
• Linux is an OS or a kernel which provides an environment such that
the user can execute programs in efficient and convenient manner.
• Linux is a free Open Source Operating System.
• Created by Linux Torvalds in 1991.
• Based on UNIX.

For Notes download BCA Resources App


Linux’s root in Unix
• Unix is the operating system which laid foundation to Linux
• Unix is designed for mainframes, enterprises & universities.
• Commands used in both Linux and Unix is same.

For Notes download BCA Resources App


Features of Linux
• Portable – can work on different types of hardware in same way.
• Open Source – Source code of Linux is freely available.
• Multi User Support – Multiple users can access the system resources
at same time.
• Multi Programming - Multiple programs can be run at same time.
• Shell – Special Interpreter program - used to execute commands.
• Application Support – Has it’s own software repository and also
allows user to run Windows Applications.

For Notes download BCA Resources App


Features of Linux (Cont.)
• Hierarchical File System: Provides a standard file structure where the
system/user files are arranged.
• Security – provides user security using authentication such as
passwords, encryption & access control to specific files.
• GUI – Supports GUI by installing GUI Packages.
• Live Boot – All Linux distributions allows user to run OS without
installing it on the system.
• Custom Keyboard Support – Supports different languages keyboards.

For Notes download BCA Resources App


Features of Linux (Cont.)
• Hierarchical File System: Provides a standard file structure where the
system/user files are arranged.
• Security – provides user security using authentication such as
passwords, encryption & access control to specific files.
• GUI – Supports GUI by installing GUI Packages.
• Live Boot – All Linux distributions allows user to run OS without
installing it on the system.
• Custom Keyboard Support – Supports different languages keyboards.

For Notes download BCA Resources App


Features of Linux (Cont.)
• Hierarchical File System: Provides a standard file structure where the
system/user files are arranged.
• Security – provides user security using authentication such as
passwords, encryption & access control to specific files.
• GUI – Supports GUI by installing GUI Packages.
• Live Boot – All Linux distributions allows user to run OS without
installing it on the system.
• Custom Keyboard Support – Supports different languages keyboards.

For Notes download BCA Resources App


Advantages of Linux
• Open Source – Redistribute, free to use
• Low cost – no need to spend time & huge amount to obtain License.
• Stability – More stable compared to other OS.
• Performance – Ability to handle large number of users simultaneously.
• Flexibility – Used for server applications, desktop applications
• Compatibility – Supports all common Unix Software & able to process all
common file formats
• Security – Provides encryption, file ownership and permission.
• Better usage of hard disk – Linux uses its resources well even when hard
disk is almost full.

For Notes download BCA Resources App


Architecture of Linux
• Hardware: Actual parts of computer
• Kernel:
• Responsible for all major activities.
• Interacts directly with hardware
• There is only one Kernel for each system
• Core component of OS
• Has various functionalities such as, file system, memory
management, interrupt handling
• Shell: Acts as mediator between kernel & user. Shell reads
command prompt & send request to execute a program,
Hence known as command interpreter. Shell program stored
at file having extension as sh.
• Tools & Applications: this layer includes user written
application using shell programming, C, C++ applications etc.

For Notes download BCA Resources App


Linux File System
• File System – logic collection of files on a partition / disk
• Defines the way how the files are organized on the disk
• When a disk is formatted, the sectors in the hard disk are first divided into small
groups.
• Group of these sectors is known as blocks.
• Size of each block is 512 bytes.
• All blocks are logically divided into 4 parts.
• Boot Block
• Super Block
• Inode Table
• Data Block

For Notes download BCA Resources App


Linux File System ( Cont. )
• Boot Block
• Located in the first few sectors of a file system.
• Contains the initial bootstrap program – used to load the operating system
• Super Block
• Describes the state of the filesystem
• To access a file in a file system requires access to the super block to get information about the file..
• Contains information about:
• Total size of the partition
• Block size of the file system
• No. of files it can store.
• Inode Table
• Information related to a file (not the contents) is stored in an inode table.
• For each file there is an inode entry in the table.
• Inode is a data structure containing metadata about the files.
• Information stored in inode are: Size of the file, User ID of the owner who owns the fie, Group ID of the file, file
access permission, location

For Notes download BCA Resources App


Linux File System ( Cont. )
• Data Block
• Starts at the send of the inode table
• Contains actual file contents.
• Contains several types of files.
• Contains user files, directory files, symbolic link, block files etc.

For Notes download BCA Resources App


Linux Supported File System
• Ext
• Stands for “Extended file system”
• Created specifically for Linux
• Had 4 major revisions.
• Ext 2,Ext3,Ext4
• Ext2 was default filesystem under 2.2 Kernel
• Ext3 is the default filesystem for RHEL 3 & 4
• Ext3 offers best performance combined with data security of file system, due to it’s journaling
feature
• Ext4 was developed as the successor of ext3.
• Ext4 provides features for large filesystems, performance, reliability.
• XFS
• XFS is designed for high scalability
• provides almost native I/O performance even when the file system spans multiple storage device.

For Notes download BCA Resources App


Linux Supported File System
• OCFS
• Oracle Cluster File System (OCFS)
• It’s a shared file system designed for Oracle Application Cluster (RAC)
• OCFS volumes can span one shared disk or multiple shared disks for redundancy and performance.
• OCFS2
• Next Generation of OCFS
• OCFS2 is a general purpose file system
• Makes management of RAC installations even easier.
• JFS
• Developed by IBM for IBM AIX OS, but later ported to Linux
• enhance low CPU usage & good performance for both large & small files
• Able to dynamically resized, but wont support shrunk
• NFS
• Network filesystem used to access remote disks

For Notes download BCA Resources App


Types of Files in Linux
• Ordinary file – files created by user. User can modify
• Directories
• directory file is automatically created by Linux when you create a directory in Linux.
• User can’t modify it. However Linux will modify it automatically when a file or sub directory is added
• Special files
• Most of the system files in Linux are special files.
• Usually associated with I/O devices.
• Stored in standard Linux directories such as /dev or /etc.
• User can’t modify
• Pipe file
• Pipe act as temporary file which only exist to hold data from one command until it’s read by another.
• Socket File
• Used to pass information between applications for communication purpose
• Symbolic link file
• Used for referencing some other file of the file system
• Two types of link file available in Linux: Soft link & Hard Link
• Soft Link : Actual link to the original file ; Hard Link: acts as a mirror copy of the original file

For Notes download BCA Resources App


Linux standard directories
• Linux filesystem resembles an upside down tree.
• Hierarchy starts from root (Represented by “/”)
• Properties of a file system in Linux:
• Has a root directory that contains other files and directories
• Each file & directory is identified by unique identifier called inode
• By default, root directory has an inode number of 2
• 0 & 1 inode numbers are not used.
• No dependencies between filesystems

For Notes download BCA Resources App


Linux standard directories

For Notes download BCA Resources App


Linux standard directories
• / (root)
• Top level directory in the filesystem
• Contains all other directories & their directories
• Contains all files required to boot the Linux system
• Also contains a file called as Linux which is Linux Kernel itself.
• /bin
• Contains binary files, such as commands that are required by system Admin & normal user.
• Usually contains shells.
• /boot
• Contains boot loader, kernel executable & configuration files required to Boot Linux system
• /dev
• Contains device files for each hardware devices attached to the system.
• Files are those which represents each device in the computer & helps in access to those devices
• Users can access these devices directly though these device files; But some applications hide the actual device names to end
users.
• /etc
• Contains admin configuration files and directories.

For Notes download BCA Resources App


Linux standard directories
• /home
• Home directory storage for user files
• Each user has subdirectory in /home
• /lib
• Contains shared library files & sometimes other kernel-related files that are required to boot the system.
• /media
• Mount points for removable media
• /mnt
• Temporary mount point for regular file systems that can be used while administrator is repairing or working on
a file system
• /opt
• Optional files such as vendor supplied application programs are stored here
• /root
• Home directory for the root user. Home directory for root does not stored in /home due to security issues.
• /sbin
• Contains system binary files.
• Similar to /bin but /sbin contains applications required by super user.
For Notes download BCA Resources App
Linux standard directories
• /tmp
• Used by OS and programs to store temporary files.
• /usr
• Contains user documentation, games and other commands, files that are not required during boot time.
• /var
• Stores variable data files
• Includes files like, log files, MySQL & other database files, server files etc.
• /proc
• Contains information about system resources.
• Contains info about your computer
• /srv
• Contains data for servers. Eg: HTML files etc.
• /sys
• It’s a virtual directory like /proc & /dev. Also contains information from devices connected to the system

For Notes download BCA Resources App


Linux Commands
• man
• Provides detailed description and usage of the commands.
• Syntax: man <commandname>
• cd
• To change directory
• Syntax cd options directory
• cd ~ - Change to home directory
• cd / - Change to root directory
• cd .. - Change to previous directory
• ls
• Used to list the content of specified directory
• Syntax: ls option directory
• ls –a : List all files including hidden files
• ls –d : Lists directory
• ls –r : List in reverse order

For Notes download BCA Resources App


Linux Commands
• cp
• Used to copy content of one file to another
• Syntax: cp options source_file destination_file
• Eg: cp animal.txt birds.txt
• If destination file is an existing one. Then it’s overwritten. If destination is an directory then the file is copied to that directory.
• cp –r : Recursive copy (includes hidden file)
• cp –v : Print information message
• cp –i : Prevents from overwriting existing files. Prompt before overwriting destination file.
• rm
• To remove files or directory.
• Syntax rm options filename
• Options same as cp mentioned above, rm –d : removes empty directories.
• mkdir
• Creates a new directory
• Syntax: mkdir option directory_name
• Can also create multiple directories at once & also able set permissions while creating directory.
• Options
• -m – Set permission mode
• -p – Create parent directories as necessary

For Notes download BCA Resources App


Linux Commands
• rmdir
• Used to remove directory
• Directory should be empty before removing it
• Options,syntax same as mkdir
• pwd
• Displays the current working directory
• Syntax: pwd option
• Options
• -L – Display the content as absolute name
• -P – Displays actual path
• File
• Used to determine the type of a file
• Reports file type in human readable form or MIME type
• Useful to determine how to work or view the file.
• Syntax: file options filename
• -b – brief mode – displays the file type
• -s – used for special files
• -i – to view mime type of a file
• -z – to view compressed files without decompressing

For Notes download BCA Resources App


Linux Commands
• rmdir
• Used to remove directory
• Directory should be empty before removing it
• Options,syntax same as mkdir
• pwd
• Displays the current working directory
• Syntax: pwd option
• Options
• -L – Display the content as absolute name
• -P – Displays actual path
• File
• Used to determine the type of a file
• Reports file type in human readable form or MIME type
• Useful to determine how to work or view the file.
• Syntax: file options filename
• -b – brief mode – displays the file type
• -s – used for special files
• -i – to view mime type of a file
• -z – to view compressed files without decompressing

For Notes download BCA Resources App


Linux Commands
• more
• Used to display output page by page
• Syntax: more filename
• Option: -s – Squeeze multiple blanks lines into one. –num limits line displayed per page
• Controls used while viewing file:
• Enter Key: To scroll down line by line
• Space bar or f key: To go to next page
• B key: to go back one page
• Q key: to quit
• Less
• Used to read contents of text file one page per time
• Faster Access because if the file is large it don’t access complete file but access page by page.
• Option: -s – Squeeze multiple blank lines into one. –u – omits the underlines
• Syntax: less filename

For Notes download BCA Resources App


Creating & viewing files using cat
• Used to create, display the content of text file and combine several files to one.
• Cat command can read & write data from standard input & output devices.
• Used to copy text files into a new document.
• Syntax: cat option filename
• To view content of file: cat filename
• To create a new file: cat > filename
• Once you’re done, just press ctrl + d to save file.
• To copy contents of one file to another: cat filename_source > filename_destination
• To copy contents of multiple files: cat filename1 filename2 file3
• To append the contents of one file to another: cat file1 >> file2

For Notes download BCA Resources App


File Comparisons Commands
1. cmp
• Used to compare two files byte by byte.
• Syntax: cmp options filename1 filename2
• Reports the location of the first mismatch to the screen if difference found & displays no message if files are identical.
• Options:
• -b – Displays the differing bytes in the output
• -i [bytes to skip] – Skip particular number of intial bytes from both the files and then after skipping it compares files
• -i skip1:skip2 – Skip the skip1 bytes of file1 & skip2 bytes of file2
2. Diff
• Used to display the differences in the files by comparing the files line by line.
• Outputs a set of instruction on how to make changes in one file to make it identical to other file.
• Syntax: diff options file1 file2
• Offers two different ways to view the diff command ouput: 1. Context mode (-c) 2. unified mode (-u)
• Diff uses some special symbols and instructions on how to make changes to a file.
• a: Add
• c: Change
• d: Delete
• Options:
• -i – Ignore case differences in file content.
• -b – Ignore changes in amount of white spaces
• -w – Ignore all white space.

For Notes download BCA Resources App


File Comparisons Commands
3. Comm
• Used to compare two sorted files line by line.
• Syntax: comm option file1 file2
• Options:
• -1 – Hide column 1
• -2 – Hide column 2
• -3 – Hide column 3
• Produces three-column output.
• Col1: lines unique to file1
• Col2: lines unique to file2
• Col3: lines common to both files
4. Uniq
• Filter out the repeated lines in a file.
• Syntax: uniq option filename
• Option:
• -d – Displays only duplicate lines
• -u – Displays unique lines

For Notes download BCA Resources App

You might also like