Linux Operating System Overview for BCA
Linux Operating System Overview for BCA
A
Linux sem 3
Chapter
Contents
[Link] architecture
Linux Features,
Types of Shell ( C, Bourn, Korn )
Linux file system
Directory Structure of Linux
Types of File
o Ordinary Files
o Directory Files
o Device Files
[Link] Commands :passwd, logout, who, who am i,
clear, bc, factor, cal, date
[Link] and Directory Related Command : ls, cat, cd,
pwd, mv, cp, ln, rm, rmdir, mkdir,umask, chmod,
chown, chgrp, find,
pg, more, less, head, tail,wc, touch
Year Description
1965 GE & AT&T and MIT created MULTICS (multiuser) by Dennies
Ritchie, Brein
Kernigham)
1969 UNICS (single version of MULTICS) implemented on PDP 7 to PDP 11
by KEN
THOMPSON
1970 UNIX was created in Assembly Language UNIX ver. 1
1973 Unix version3
1979 Unix version 7
1981 BSD(Berkely software Distribution developed at California Uni.)
1982 System II was developed
1987 Minix was developed
1991 FINNISH student Linus Torvalds developed Linux
History of Linux
Architecture of Linux:
The Shell
Kernel
Features of Linux:
Following are some of the important features of Linux Operating System.
Portable: Portability means software can works on different types of
hardware in same way. Linux kernel and application programs support
their installation on any kind of hardware platform.
Open Source: Linux source code is freely available and it is community based
development project. Multiple team 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 protect jon! controlled access to specific files! encryption of data.
File
"File is a container for storing information.”
This contains only printable characters. For example your "C" language's
code is to be said as text file.
(ii) Binary file:–
This contains printable and non–printable characters also. For example picture
file or any object code or executable file are also known as binary file.
(2) Directory File
As you have proper cupboards in library for storage of various books similarly
directories are some sort of containers for files stored in a computer system. In
other words,
Prepared by Prof. Gunja
7
OS using B.C.A
Linux sem 3
"The directory contains no data but keeps some details of the files and
sub–directories."
A directory file contains entry for every file and subdirectory that is contains.
Suppose you have 20 files in directory then you'll have 20 entries in the directory.
Each entry has two components
The filename
A unique identification number for the file (known as inode number)
(3) Device File
We know that printer is used for printing files also CD ROM is also used for data
transfer etc.,
Here the entire device attached to computer is treated as file. And all thing are
located at /dev
folder of Linux
One advantage of it is that we can use all command that related to ordinary files
also be used with device file.
Top level of the Unix file structure file structure (/) is known as a root directory
or slash directory, and it always has a certain set of subdirectories, including bin,
dev, etc, lib, mnt, tmp, and usr.
Directories
Among the most important portions of any computer are its device drivers.
Without them, you would not have any information on your screen. You
Prepared by Prof.
would notGunja
be able to enter information.
8
OS using B.C.A
Linux sem 3
When files are recovered after any sort of problem or failure, they are placed in
the lost + found directory, if the kernel cannot ascertain the proper location in
the system.
6. The mnt directory
The mnt directory is an empty directory reserved for mounting removable file
systems like hard disks, removable cartridge drives, and so on.
7. The tmp Directory
The tmp directory contains temporary files created by LINUX system programs.
8. The usr Directory
The usr directory consists of several subdirectories that contain additional
LINUX commands and data files. It is also the default location of user home
directories.
Ownership
File ownership is an important component of LINUX that provides a secure
method for storing files.
In LINUX files and directories are belongs to different kind of users as following.
Permissions
There are three specific permissions on LINUX-like systems that apply to each
class:
(a) Read Permission
The read permission grants the ability to read a file.
When set for a directory, this permission grants the ability to read the
names of files in the directory (but not to find out any further
information about them such as contents, file type, size, ownership,
permissions, etc.)
(b) Write Permission
The write permission grants the ability to modify a file. When set for a
directory, this permission grants the ability to modify entries in the
directory.
This includes creating files, deleting files, and renaming files.
(c) Execute Permission
The execute permission grants the ability to execute a file. This permission
must be set for executable binaries.
For example, a compiled C++ program or shell scripts, in order to allow the
operating system to run them.
When set for a directory, this permission grants the ability to access file
contents
Symbolic Notations
There are several ways by which linux permissions are represented.
The most common form is symbolic notation as shown by ls -l.
File type
The first character indicates the file type and is not related to permissions. The
remaining nine characters are (Generally there is d which denotes directory).
In three sets, each representing a class of permissions as three
characters. The first set represents the user class. The second set
represents the group class. The third set represents the others
class.
Prepared
Eachby Prof.
of theGunja
three characters represent the read, write, and execute permissions:
1
r if reading is permitted, and – (dash/hyphen) if it is not.
OS using B.C.A
Numeric Notations
Another method for representing LINUX permissions is an octal (base-8)
notation. This notation consists of at least three digits. Each of the
three rightmost digits represents a different component of the
permissions: owner, group, and others.
Field Explanation:
$ ls – l
-rw-r----- 1 admin1 admin1 13 21 July 19 15:27 [Link]
If first character is – then it is normal file
If it is d then it is directory
Field 1 – File Permissions: Next 9 character specifies the files permission. Each 3 characters
refers to the read, write, execute permissions for user, group and world In this example, -rw-
r—– indicates read-write permission for user, read permission for group, and no permission
for others.
Field 2 – Number of links: Second field specifies the number of links for that file. In this
example, 1 indicates only one link to this file.
Field 3 – Owner: Third field specifies owner of the file. In this example, this file is owned by
username ‘admin1.
Field 4 – Group: Fourth field specifies the group of the file. In this example, this file belongs
to ”admin1” group.
Field 5 – Size: Fifth field specifies the size of file. In this example, ’13′ indicates the file size.
Field 6 – Last modified date & time: Sixth field specifies the date and time of the last
modification of the file. In this example, ’21 July 19 15:27′ specifies the last modification
time of the file.
Prepared by Prof. Gunja
1
OS using B.C.A
Field 7 – File or directory name: The last field is the name of the file or directory. In this
example, the file name is [Link]
In windows operating system with the help of RUN command from start menu we can execute
UNIX Shell commands from remotely located computer.
Syntax :-
Basic Commands:
2. Logout: To end the session and exit from current logged user's session
$logout command is used.
Syntax: logout
3. Who: This commands displays all the users currently logged into the system.
Syntax: who
Description: It gives the Username, the terminal and login time of user.
Options:
Option Use
-H It gives the headers of each columns
Description: - Print the user name associated with the current effective user id.
5. Clear: It clears the terminal screen.
Syntax : clear
Description :
Clear clears your screen if this is possible, including its scroll back buffer.
Clear ignores any command-line parameters that may be present.
Options:
Option Use
-q It ignores welcome message.
-l Define the standard math library.
Example:-
Options:
Format (this is only for your knowledge in exam write 3–5 formats only.)
%a Sets abbreviated weekday name (e.g., Sun)
%A Sets full weekday name (e.g., Sunday)
%b Sets abbreviated month name (e.g., Jan)
%B Sets full month name (e.g., January)
%c Sets date and time (e.g., Thu Mar 3 23:05:25 2005)
%C century; like %Y, except omit last two digits (e.g., 21)
%d day of month (e.g, 01)
%D date; same as %m/%d/%y
%e day of month, space padded; same as %_d
%F full date; same as %Y-%m-%d
%g last two digits of year of ISO week number (see %G)
%H hour (00..23)
%I hour (01..12)
%k hour ( 0..23)
%l hour ( 1..12)
%m month (01..12)
%M minute (00..59)
%n a newline
%N nanoseconds (000000000..999999999)
%p locale’s equivalent of either AM or PM; blank if not
known
%P like %p, but lower case
%r locale’s 12-hour clock time (e.g., 11:11:04 PM)
%t tab
Example:-
$ date
Fri Feb 19 09:55:15 IST 2016
$ date +%m
02
$ date +%h
Feb
$ date +%y
16
$ date +"Date is %D %t Time is %T"
date is 19/02/16 Time is 10:52:34
10. exit :- It is used to terminate a program, shell or log you out of a network normally.
Syntax :- exit
Example:-
$ ls – l
-rw-r----1 admin1 admin1 13 21 July 19 15:27 [Link]
2. cat (Concatenating, displaying and creating file): It is used for creating
file, displaying file and concatenating of file.
Syntax : - cat [options] [FILE]...
Description :-
Two basically three uses of the cat command.
(i) for
creating file
Syntax
cat >
filename
cat>[Link]
t
Above syntax creates [Link] and allow us to insert content for this
file.
(ii) for
appending file
Syntax
cat >> filename
(iii) for displaying file (concatenating)
Syntax
cat filename
You can also display multiple files using :– cat file1 file2….
o After creating or appending for save file use ctrl + d
command.
Concatenating file
contents cat [Link] >>
[Link]
It can concatenate the contents of two files. For this you have to use
append output redirection operator.
The contents of [Link] will be appended to [Link].
Options
cat –n :–Prints the number of line
cat –e :– Prints $ at the end of line in a file
cat –v :– Prints displays nonprinting characters as if they were
Prepared by Prof. Gunja
visible, except for tabs and the end of line character 1
OS using B.C.A
Example:
Options:
–i it will ask before copying a file if there is already file present.
–r It will copies all directories and sub–directories contained in main
directory.
If the destination directory is not then it will create first directory.
Example:-
$ cp file1 file2
The above cp command copies the content of [Link] to [Link]
Though the name of the file may be different but they have same inode
number
It is similar to the shortcut to the Windows OS.
Options:
–s it is used to create symbolic link to the file.
–i If the destination file already exists then it
asks to
overwrite the existing link.
–f It is used to forcefully overwrite file with link.
Example:
ln -s [Link] [Link] -- will create symbolic link of file1 in current
directory.
$ cat [Link]
This is a file.
$ cat [Link]
This is a file.
Options:
Example :-
$ rm [Link]
Remove the file [Link]. If the file is write-protected, you will be
prompted to confirm that you really want to delete it.
$ rm *
Remove all files in the working directory. If it is write-protected, you
will
Prepared by Prof. be prompted before rm removes it.
Gunja
$ rm -f [Link] 1
OS using B.C.A
Remove the file [Link]. You will not be prompted, even if the file is
write- protected; if rm can delete the file, it will.
$ rm -f *
Remove all files in the working directory. rm will not prompt you for any
reason before deleting them.
$ rm -i *
Attempt to remove every file in the working directory, but prompt before
each file to confirm.
9. rmdir (Removes
directories) Syntax :- mkdir
[options] directory
Description:-
It is used to delete directories.
If the directory contains the files it can't be deleted and prompts the
message "Directory is not empty".
The parent(main) directory can't remove if there is sub–directory present
in main directory.
Options:
Example:
rmdir bca
rmdir -p dir3/dir4/dir5
10. mkdir (Makes Directory)
Syntax: mkdir [options] directory(s)
Description: It removes only empty directory.
Options:
12. chmod (Change Mode): chmod command allows you to alter / Change
access rights to files and directories.
Syntax:- chmod [options] [MODE] FileName
For example,
Changing modes using relative method
$ chmod u+x [Link]
-> this will add execution mode to user with [Link] file.
For example
Changing modes using absolute method
$ chmod 000 [Link]
This will remove all the permissions from [Link]
13. chown: Command for system V that changes the
owner of a file. Syntax :- chown [options] <newowner>
filename/directoryname
Prepared by Prof. Gunja Description:
2
OS using B.C.A
Example :-
$ ls -l [Link]
-rw-r--r-- 1 root root 0 Jan 31 05:48 [Link]
$ chown vivek [Link]
-rw-r--r-- 1 vivek root 0 Jan 31 05:48 [Link]
14. Chgrp (Change the group): chgrp command is used to change the
group of the file or directory.
Syntax: chgrp [options] newgroup filename/directory
name chgrp ''group'' ''target1'' [''target2'' ..]
Description:
The group parameter indicates the new group with which the targets
should be associated.
It may either be a symbolic name or an identifier.
The target1 parameter indicates the files or directories for which the
change should be made.
The target2 parameter indicates optional additional files or directories for
which the change should be made.
Example :-
$ ls -l [Link]
-rw-r--r-- 1 root root 0 Jan 31 05:48 [Link]
$ chgrp vivek [Link]
-rw-r--r-- 1 root vivek 0 Jan 31 05:48 [Link]
15. Find: Finds one or more files assuming that you know their approximate
path.
Syntax :- find [options] path [expressions]
Description :-
Find is one of the powerful utility of Unix (or Linux) used for searching
the files in a directory hierarchy.
It finds through one or more directory trees of a file system, locates files
based on some user-specified criteria and applies a user-specified
action on each matched file.
By default, find returns a list of all files below the current working
directory.
For never to follow symbolic links. Use -P flag.
The -L flag will cause the find command to follow symbolic links.
The -H flag will only follow symbolic links while processing the
command line arguments.
Find From current directory
Find . -name 'my*'
This searches in the current directory (represented by a period) and
below it, for files and directories with names starting with my.
Prepared by Prof. Gunja
2
OS using B.C.A
Options:
Example:-
$ find -name "[Link]"
./bkp/[Link]
./[Link]
Example :-
$ head [Link]
➢ Display the first ten lines of [Link].
$ head -c 20 [Link]
➢ Will output only the first twenty bytes (characters) of [Link]. Newlines
count as a single character, so if head prints out a newline, it will count it as a
byte.
$ head -n 5K [Link]
➢ Displays the first 5,000 lines of [Link].
22. touch
Syntax: touch [file_nm1] [file nm 2]….
Description:-
Prepared byProf.
It isGunja
used to change the modification time or access time of file.
2
OS using B.C.A
The created using the touch command is empty. This command can be used when the
user doesn’t have data to store at the time of file creation.
Options: