Unit-5 (Notes) OS
Unit-5 (Notes) OS
Linux Basic
1
SYLLABUS
2
5.1 OVERVIEW OF LINUX
1. Dual Boot
3. Virtual Installation
Linux can be run as a virtual machine inside
6
another operating system.
User has to install some virtual server
application such as Vmware and then install linux
under host software
Fresh Installation
It is the most popular installation. It installs linux
as the only operating system of the computer.
Here hard disk is formatted and if there is any
existing operating system in computer, it will
removed.
7
LINUX ARCHITECTURE
It is also known as the layered structure of Linux.
Linux is a UNIX-like OS, its architecture resembles
to that of UNIX.
1. Hardware:
8
Figure : Linux architecture
9
Linux operating system:
Next higher layer in Linux OS
It is called system kernel.
Kernel manages all the underlying hardware
It directly interacts with the H/W and provides
user programs required services
It hides complex details of H/W
It provides interface between user program and
H/W
Main service of OS :
Users
Top most layers
User program come in this layer
They interacts with system either by library
procedure to invoke system call or by using utility
program such as shell
12
KERNEL
Kernel is core part of any OS.
Kernel is program, which is loaded in memory
,when system is turned on and provides various
services until system is turned off.
Kernel manages all the underlying hardware
14
DIRECTORY RELATED COMMANDS
Creates a directory.
% mkdir newdir
Removes a directory.
% rmdir dirname
Equivalent:
% rm -r dirname
15
CD AND PWD
Changes your current directory to a new one.
% cd /some/other/dir
Absolute path
% cd subdir
Assuming subdir is in the current directory.
% cd
Returns you to your home directory.
Displays personal working directory, i.e. your
current directory.
% pwd
16
MAN
Manual Pages
The first command to remember
Contains info about almost everything :-)
other commands
system calls
c/library functions
other utils, applications, configuration files
Toread about man itself type:
% man man
NOTE: unfortunately there’s no
% man woman ... 17
PASSWD
Change your login password.
A very good idea after you got a new one.
% date -u
in GMT
% man date
19
CAL
Calendar
for month
entire year
Years range: 1 - 9999
No year 0
Calendar was corrected in 1752 - removed 11 days
% cal current month
% cal 2 2000 Feb 2000, leap year
% cal 2 2100 not a leap year
% cal 2 2400 leap year
% cal 9 1752 11 days skipped
% cal 0 error
20
% cal 2002 whole year
HISTORY
% cal current month
% cal 2 2000 Feb 2000, leap year
% cal 2 2100 not a leap year
% cal 2 2400 leap year
% cal 9 1752 11 days skipped
% cal 0 error
% cal 2002 whole year
21
LS
List directory contents
Has whole bunch of options, see man ls for details.
% ls
all files except those starting with a “.”
% ls -a
all
% ls -A
all without “.” and “..”
22
CAT
Display and concatenate files.
% cat
Will read from STDIN and print to STDOT every line you
enter.
% cat file1 [file2] ...
Will concatenate all files in one and print them to STDOUT
% cat > filename
Will take whatever you type from STDIN and will put it into
the file filename
To exit cat or cat > filename type Ctrl+D to
indicate EOF (End of File).
23
COPY
Copies files / directories.
% cp [options] <source>
<destination>
% cp file1 file2
24
MV
Movesor renames files/directories.
% mv <source> <destination>
The <source> gets removed
% mv file1 dir/
% mv file1 file2
rename
% mv file1 file2 dir/
% mv dir1 dir2
25
RM
Removes file(s) and/or directories.
% rm file1 [file2] ...
% rm -r dir1 [dir2] ...
26
CHMOD
Changes file permissions
Possible invocations
% chmod 600 filename
-rw------- 1 user group 2785 Feb 8 14:18
filename
(a bit not intuitive where 600 comes from)
% chmod u+rw filename
(the same thing, more readable)
For the assignment:
% chmod u+x myshellscript
(mysshellscript is now executable)
-rwx------ 1 user group 2785 Feb 8 14:18 myshellscript
27
ECHO AND GREP
Searches its input for a pattern.
The pattern can be a simple substring or a complex
regular expression.
If a line matches, it’s directed to STDOUT;
otherwise, it’s discarded.
% echo “blah-foo” | grep blah
Will print the matching line
% echo “blah-foo” | grep zee
Will not.
See a separate grep tutorial.
28
PS
Use ps to report the status of a process
/export/home/morris07>ps
Output:
PID TTY TIME CMD
19834 pts/7 0:05 ksh
19954 pts/7 0:04 ps
29
SORT
The sort command sorts data (using ASCII
format).
30
KILL
The kill command waits for the process to
perform cleanup: write to files, close files,etc.
31
5.4 VI
short for: visual editor
is part of GNU/Linux
Filename is optional
33
We’ll be using vim - vi improved
34
GEDIT
It is free software.
36
DIRECTORY
It is a container for other files and sub-directories.
They provide a hierarchical file structure. They
organize files in well manner.
Directory is a file whose data is sequence of
entries. Each entry contains a file name and a
unique identification number called I-node number.
I –node number provides a location of I-node where
information about a file is stored.
Any directories contains two special entries : dot (.)
and dot dot (..) .
These two entries refer to the current directory itself
and its parent directory respectively.
37
DIRECTORY STRUCTURE
38
Top of file is called root (defined by / )
Absolute path :
Relative path :
./test.cpp
39
5.5 LINUX SHELL
A shell is a command interpreter that allows you to
type commands from the keyboard to interact with
the operating system kernel.
42
Linux Command-Line Interface
Libraries Libraries are pre-written code “pieces”
that application programmers use in their
programs.
44