The document provides information about Linux OS and shell programming. It discusses the history and evolution of Linux from being a student project to a robust OS. Key people involved in its development like Richard Stallman, Linus Torvalds, and Andy Tanenbaum are mentioned. The architecture of Linux including kernel, system libraries, system utilities etc. is explained. Important commands, file system structure, file permissions and text editors in Linux are also summarized.
1. LINUX OS AND SHELL
PROGRAMMING
MODULE 1
PREPARED BY
SHAHILA SHAHUL
ASSISTANT PROFESSOR
MCA DEPARTMENT
MES AIMAT MARAMPALLY
2. syllabus
UNIT I
Introduction to Linux – History, Architecture, Comparison with
UNIX, Features and Facilities of Linux, Basic commands in Linux,
Files and File Structure - Linux File System, Boot block, Super
block, Inode table, Data blocks, Linux standard directories. File
naming Conventions, Path, Types of file names and Users, File
Commands in Linux, file comparisons, Directory Commands,
Text Editors-Functions of a Text Editor, vi Editor, Locating Files,
File Access Permissions [FAP], Viewing and Changing FAPs,
Redirection, Filters, Pipes.
3. Linux evolved from a project started by a
university student to the robust OS it is now
4. HISTORY
In June 1971, Richard Matthew Stallman
joined MIT Artificial Intelligence Laboratory as
a programmer where he gained popularity with
the hacker community and came to be known
by his now popular name RMS.
• At that time, all the programmers used to
share their code freely among each other cutting
across various institutions
5. In 1980, with the advent of portable software - ie software that can
be compiled to run on different computers, a business model
emerged.
So the companies developing the code refused to share the code
with their clients and began restricting copying and redistribution of
their software by copyrighting it.
In response to this trend, Stallman, who believed in the principle
that software has to be free always, founded the Free Software
Foundation and in 1985, published the GNU Manifesto.
This manifesto outlined his motivation for creating a free OS called
GNU, which would be compatible with Unix.
6. He along with a group of like minded programmers started work in
developing the tools needed to make a complete OS
8. In 1989, Stallman released the first program independent GNU General Public
Licence now popularly known as GPL or copyleft.
Now the only thing that GNU lacked was a completely free OS kernel
In 1990, A finnish student by name Linus Torvalds studying in the University of
Helsinki came into contact with Andy Tanenbaum's OS, Minix.
Linus wanted to upgrade Minix by putting in more features and improvements.
But he was prohibited by Tanenbaum to do so.
Then Linus decided to write his own kernel and released it under GPL.
This kernel is now popularly known as Linux
12. 1). The kernel is the core part of the operating system, which is responsible for all
the major activities of the LINUX operating system. This operating system
consists of different modules and interacts directly with the underlying hardware.
The kernel offers the required abstraction to hide application programs or low-
level hardware details to the system. The types of Kernels are as follows:
• Monolithic Kernel
• Microkernels
• Exo kernels
• Hybrid kernels
2). System libraries are special functions, that are used to implement the
functionality of the operating system and do not require code access rights of
kernel modules.
3). System Utility programs are liable to do individual and specialized-level tasks.
13. 4). The hardware layer of the LINUX operating system consists of peripheral
devices such as RAM, HDD, CPU.
5). The shell is an interface between the user and the kernel, and it affords services
of the kernel. It takes commands from the user and executes the kernel’s
functions. The Shell is present in different types of operating systems, which are
classified into two types: command-line shells and graphical shells.
The command-line shells provide a command-line interface, while the graphical
line shells provide a graphical user interface. Though both shells perform
operations, the graphical user interface shells perform slower than the command
line interface shells. Types of shells are classified into four:
• Korn shell
• Bourne shell
• C shell
• POSIX shell
14. Features of Unix OS
• When compare Unix to Linux, Unix is a Multi-user, multitasking
operating system
• It can be used as the master control program in workstations and
servers.
• Hundreds of commercial applications are available
• In its heydays, UNIX was rapidly adopted and became the standard
OS in universities.
15. Features of Linux Operating System
• Support multitasking
• Programs consist of one or more processes, and each process have one or
more threads
• It can easily co-exists along with other Operating systems.
• Comparing features of Linux and Unix, Linux can run multiple user
programs
• Individual accounts are protected because of appropriate authorization
• When comparing Unix vs Linux, Linux is a replica of UNIX but does not
use its code.
16. KEY DIFFERENCE
• Comparing Unix vs Linux, Linux source code is available to the general public
whereas, in Unix, the source code is proprietary.
• UNIX OS was created in the late 1960s at AT&T Bell Labs whereas Linux is an
operating system built by Linus Torvalds at the University of Helsinki in 1991.
• The main difference between Linux and Unix is Linux is a clone of Unix
• When we compare Unix to Linux, Linux default shell is BASH while the Unix
shell is Bourne Shell.
• One key Unix and Linux difference is that Linux threat detection and solution are
very fast while Unix users require longer wait times to get the proper bug fixing
patch.
• Important versions of Linux are Redhat, Ubuntu, OpenSource, Solaris, whereas
important versions of Unix are HP-UX, AIS, BSD, etc.
17. Features and Facilities of Linux
Following are some of the important features of Linux Operating System.
• Portable – Portability means software's can works on different types of hardware's in
same way. Linux kernel and application programs supports their installation on any kind
of hardware platform.
• Open Source – Linux source code is freely available and it is community based
development project. Multiple teams works in collaboration to enhance the capability of
Linux operating system and it is continuously evolving.
• Multi-User – Linux is a multiuser system means multiple users can access system
resources like memory/ ram/ application programs at same time.
• Multiprogramming – Linux is a multiprogramming system means multiple
applications can run at same time.
• Hierarchical File System – Linux provides a standard file structure in which system
files/ user files are arranged.
• Shell – Linux provides a special interpreter program which can be used to execute
commands of the operating system. It can be used to do various types of operations,
call application programs etc.
• Security – Linux provides user security using authentication features like password
protection/ controlled access to specific files/ encryption of data.
42. File naming convention
1. All file names are case sensitive. So filename vivek.txt Vivek.txt VIVEK.txt all are
three different files.
2. You can use upper and lowercase letters, numbers, “.” (dot), and “_” (underscore)
symbols.
3. You can use other special characters such as blank space, but they are hard to
use and it is better to avoid them.
4. In short, filenames may contain any character except / (root directory), which is
reserved as the separator between files and directories in a pathname. You cannot
use the null character.
5. No need to use . (dot) in a filename. Some time dot improves readability of
filenames. And you can use dot based filename extension to identify file. For
example:
• .sh = Shell file
• .tar.gz = Compressed archive
43. Most modern Linux and UNIX limit filename to 255 characters (255 bytes).
However, some older version of UNIX system limits filenames to 14 characters
only.
A filename must be unique inside its directory. For example, inside /home/vivek
directory you cannot create a demo.txt file and demo.txt directory name. However,
other directory may have files with the same names. For example, you can create
demo.txt directory in /tmp.
Please note that Linux and UNIX allows white spaces, , |, , :, (, ), &, ;, as well as
wildcards such as ? and *, to be quoted or escaped using symbol.
44. File Management Commands
mkdir - creating directory
mkdir dirname
rmdir – removing directory and its contents
rmdir dirname
cd – Change directory
cd dirpath
cp – Copying files
cp file1 file2
mv – Moving or renaming files
mv oldfile newfile
45. File Management – contd..
ln – Creating links between files
ln file1 file2
Difference between copying files and linking files
cp src dst
Contents of src will be present in dst
Changing content in src will not affect contents of dst and vice
versa
ln src dst
Contents of src will be present in dst
Changing content in src or dst will get reflected in the other
file
46. Commands
Help about commands
Man (man <<cmd name>>)
Viewing file’s content
cat <<filename>>
Viewing users
who – List all Users
who am I – List the current user
Changing file permission/owner
chmod – changes file permission
chown – changes file owner
47. User information in /etc/passwd
Password info is in /etc/shadow
Group information is in /etc/group
/etc/passwd and /etc/group divide data fields using “:”
/etc/passwd:
joeuser:x:1000:1000:Joe User,,,:/home/joeuser:/bin/bash
/etc/group:
joeuser:x:1000:
48. • ps – displays processes owned by the current user
• ps – ef displays all processes.
• pstree – displays all processes running in the system in tree format
49. Listing files and Emulating Terminal
Listing files in a directory
ls – Lists all files in a directory
ls –a – Lists all files (including hidden files)
ls –l – Lists files in a directory along with owner
information, permission etc
ls –R recursive list
50.
51. PATH
-r-xr-xr-x 1 root root 68524 2011-12-19 07:18 /usr/bin/top
---------- --- ------- ------- -------- ------------ -------------
| | | | | | |
| | | | | | File Name
| | | | | |
| | | | | +--- Modification Time/Date
| | | | |
| | | | +------------- Size (in bytes
| | | |
| | | +----------------------- Group
| | |
| | +-------------------------------- Owner
| |
| +-------------------------------------- “link count”
|
+---------------------------------------------- File Permissions
Group
The name of the group that has permissions in addition to the file's owner.
Owner
The name of the user who owns the file.
File Permissions
The first character is the type of file. A "-" indicates a regular (ordinary)
file. A "d” indicate a directory. Second set of 3 characters represent the
read, write, and execution rights of the file's owner. Next 3 represent the
rights of the file's group, and the final 3 represent the rights granted to
everybody else.
(Example modified from http://www.linuxcommand.org/lts0030.php)
52. Types of filename and users
When looking at the output from “ls -l” in the first column you might see:
d = directory
- = regular file
l = symbolic link
s = Unix domain socket
p = named pipe
c = character device file
b = block device file
55. There are two ways to set permissions when
using the chmod command:
Symbolic mode:
testfile has permissions of -r--r--r--
U G O*
$ chmod g+x testfile ==> -r--r-xr--
$ chmod u+wx testfile ==> -rwxr-xr--
$ chmod ug-x testfile ==> -rw--r--r--
U=user, G=group, O=other (world)
File permissions, Viewing And Changing
FAP’S
56. Absolute mode:
We use octal (base eight) values represented like this:
Letter Permission Value
R read 4
W write 2
X execute 1
- none 0
For each column, User, Group or Other you can set
values from 0 to 7. Here is what each means:
0= --- 1= --x 2= -w- 3= -wx
4= r-- 5= r-x 6= rw- 7= rwx
File permissions cont.
57. Numeric mode cont:
Example index.html file with typical permission values:
$ chmod 755 index.html
$ ls -l index.html
-rwxr-xr-x 1 root wheel 0 May 24 06:20 index.html
$ chmod 644 index.html
$ ls -l index.html
-rw-r--r-- 1 root wheel 0 May 24 06:20 index.html
File permissions cont.
58. Two critical points:
1.The permissions of a directory affect whether
someone can see its contents or add or
remove files in it.
2.The permissions on a file determine what a
user can do to the data in the file.
Example:
If you don't have write permission for a directory, then you can't
delete a file in the directory. If you have write access to the file
you can update the data in the file.
Inherited permissions
62. VI Editor(Visual Editor)
Popular text editor
Just type vi <<filename>> at the prompt and hit the
enter key.
A new file will be opened
Type the contents needed and save
To save, press the Esc Key and then press : (colon) w
q and then enter
To quit with out saving Esc + : + q and then enter
63. Vi editor
Navigation
Left - h
Down- j
Up - k
Right - l
Top of the screen – H (shift + h) //caps lock will not work
Middle of the screen – M (shift + m)
Bottom of the screen – L (shift + l)
$ - End Key, 0 – Home Key
Edit Commands
Cut – X, x
Copy – yy, yw
Paste – P, p
66. Redirection and Pipes
Redirection
Input redirection
wc < file1 – Content of file 1 is given as input for wc
command that counts the no of lines, words and
characters in a file
Output redirection
cat file1 > newfile – Copies file’s content to newfile. Over
writes the existing content
cat file1 >> newfile – Appends the new content to the
existing content
Pipes
Output of first command is input for the second and so on
who | wc –l l– Number of lines in the output of who
command will be displayed