Introduction To Linux OS: Nbkrist Iv B.Tech Cse-Ii Sem
Introduction To Linux OS: Nbkrist Iv B.Tech Cse-Ii Sem
Introduction To Linux OS: Nbkrist Iv B.Tech Cse-Ii Sem
Introduction to Linux OS: OS basics, Linux GUI: Exploring folders, Installation of binary packages,
Built in Package Managers, Introduction to Linux file system, man pages, The first command cat,
Command History, Basic Unix Commands: vi editor, Redirection operators, some Unix commands.
Introduction to Linux OS
It was created in October 1991 by a University of Helsinki student named Linus Torvalds (Linux stands for
Linus’s UNIX). Linux itself is actually just the kernel; it Implements multitasking and multiuser
functionality, manages hardware, allocates Memory, and enables applications to run. A very popular open
source operating system that runs on a verity of hardware platforms. Linux is widely deployed as a server
OS. Linux is multi-tasking, multi user operating system. Although modified by numerous people.
Linux is a UNIX-based operating system originally developed as for Intel-compatible PC's. It is now
available for most types of hardware platforms, ranging from PDAs (and according to some reports, a
wristwatch) to mainframes. Linux is a "modern operating system", meaning it has such features as virtual
memory, memory protection, and preemptive multitasking.
Why use Linux?
Reasons to Install Linux
Components of Linux System
Linux Operating System has primarily three components
Kernel − Kernel is the core part of Linux. It is responsible for all major activities of this operating system. It
consists of various modules and it interacts directly with the underlying hardware. Kernel provides the
required abstraction to hide low level hardware details to system or application programs.
System Library − System libraries are special functions or programs using which application programs or
system utilities accesses Kernel's features. These libraries implement most of the functionalities of the
operating system and do not require kernel module's code access rights.
System Utility − System Utility programs are responsible to do specialized, individual level tasks.
Basic Features
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 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 work 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.
Architecture
The following illustration shows the architecture of a Linux system −
Hardware layer − Hardware consists of all peripheral devices (RAM/ HDD/ CPU etc).
Kernel − It is the core component of Operating System, interacts directly with hardware, provides
low level services to upper layer components.
Shell − An interface to kernel, hiding complexity of kernel's functions from users. The shell takes
commands from the user and executes kernel's functions.
Utilities − Utility programs that provide the user most of the functionalities of an operating systems.
Advantages of Linux
Low cost:
You don’t need to spend time and money to obtain licenses since Linux and much of its software come with
the GNU General Public License. You can start to work immediately without worrying that your software
may stop working anytime because the free trial version expires. Additionally, there are large repositories
from which you can freely download high quality software for almost any task you can think of.
Stability:
Linux doesn’t need to be rebooted periodically to maintain performance levels. It doesn’t freeze up or slow
down over time due to memory leaks and such. Continuous up-times of hundreds of days (up to a year or
more) are not uncommon.
Performance:
Network friendliness:
Linux was developed by a group of programmers over the Internet and has therefore strong support for
network functionality; client and server systems can be easily set up on any computer running Linux. It can
perform tasks such as network backups faster and more reliably than alternative systems.
Flexibility:
Linux can be used for high performance server applications, desktop applications, and embedded systems.
You can save disk space by only installing the components needed for a particular use. You can restrict the
use of specific computers by installing for example only selected office applications instead of the whole
suite.
Compatibility:
It runs all common Unix software packages and can process all common file formats.
Choice:
The large number of Linux distributions gives you a choice. Each distribution is developed and supported by
a different organization. You can pick the one you like best; the core functionalities are the same; most
software runs on most distributions.Fast and easy installation: Most Linux distributions come with user-
friendly installation and setup programs. Popular Linux distributions come with tools that make installation
of additional software very user friendly as well.
Full use of hard disk:
Linux continues work well even when the hard disk is almost full.
Multitasking:
Linux is designed to do many things at the same time; e.g., a large printing job in the background won’t
slow down your other work.
Security:
Linux is one of the most secure operating systems. “Walls” and flexible file access permission systems
prevent access by unwanted visitors or viruses. Linux users have to option to select and safely download
software, free of charge, from online repositories containing thousands of high quality packages. No
purchase transactions requiring credit card numbers or other sensitive personal information are necessary.
Open Source:
If you develop software that requires knowledge or modification of the operating system code, Linux’s
source code is at your fingertips. Most Linux applications are Open Source as well.
Disadvantages of Linux
4.If needed copy the bin file to its final output folder - packages like the Java Runtime Environment require
this. Read the online instructions first...
5.Change directories (folders) to the one containing the bin file, like so : cd /topmost/folder, for example
cd /usr/share
8.If the bin file is the program itself, chances are the file is compressed, untar/unzip in the destination folder,
Firefox comes like that.
9.Copy the archive and unpack it in the output folder, that should produce a folder.
11.Make a starter for convenience, right-click on the desktop, select the option you need and follow the lead
- an icon should appear.
[Or]
Terminal
First, open the Terminal, then mark the file as executable with thechmod command.
chmod +x file-name.run
./file-name.run
If an error message including a problem such as 'permission denied' appears, use sudo to run it as root
(admin). Be careful, sudo allows you to make critical changes to your system. Many software installs will
requiresudo.
sudo ./file-name.run
Linux accesses every object as file. Files are systematically organized in directories. Linux starts file system
with root directory(/). All files and directories are created and managed under the root directory. Since root
directory stands on the top in file system, it has no parent directory. Besides root directory, every directory
in Linux has a parent directory. Linux allows us to create as many files and directories as we want. We can
create files under the existing directories or may create new directories.
System Directories
System directories contain files, software, applications and scripts which are required to run and maintain
the Linux. System directories are automatically created during the installation.Following figure illustrates
some common system directories with their location in LFS.
Directory Description
/ First directory in Linux File System. It is also known as root directory or main directory.
All files and directories are created and managed under this directory.
/home Default directory for user data. Whenever we add a new user, Linux automatically creates a
home directory matching with his username in this directory. Whenever user login, Linux
starts his login session from home directory.
/root This is the home directory for root user. Root user is the super user in Linux. For security
reason Linux creates a separate home directory for root user. Root user account is also
being created during the installation automatically.
/bin This directory contains standard commands files. Commands stored in this directory are
available for all users and usually do not require any special permission to run.
/sbin This directory contains system administration commands files. Commands stored in this
directory are available only for root user and usually requires special privilege to run.
/usr This directory contains user application software files, third party software and scripts,
document files and libraries for programming languages.
/var This directory stores variable data files such as printing jobs, mail box etc.
/mnt This directory is used to mount remote file system and temporary devices such as CD,
/dev This directory contains device files. Usually files in this directory are dynamically
generated and should be never edited.
Exercise -1
List all directories from root directory.
Solution
ls / command will list all directories from root directory.
Key points
1. A Linux file name may have any characters or letters.
3. File name can use space, underscore, minus, period and comma.
5. File extension is not compulsory. We can create files with file extension or without file extension.
7. If file name has spaces, it need to be quoted before we can access it on command prompt. On desktop we
can use it without quotes.
Exercise -2
Create a test directory and move in it. Create blank files with following names:-
test, test.doc, test.docx, test-file, test_file, test.file, test file (‘test file’ at command prompt), .test-file (hidden
file)Verify the file creation. Verify the hidden file. Exit from directory and delete the directory.
Shell
Shell is a command interpreter. It take commands from user, execute them and display the results. Shell
supports I/O ( Input / Output) redirection which means it can read commands from non-standard sources
such as script files. As well as it can also redirect output to any supportive device (such as printer) or data
server.
Several Shells are available in Linux such as Kom, TCSH, Z shell, Bash etc. Although several shells are
available, only one shell is set to default in RedHat Linux. Bash (Bourne Again shell)shell is the default
shell in Red-Hat Linux.
exec /bin/csh To change current shell temporary. At next login default shell will be restored.
chsh –s /bin/csh To change current shell permanently. Change will be applied at next login.
Exercise -3
View the current shell and list all available shells. Change current shell temporary for this login session and
verify the change. Logout from current session and login again and verify that default shell get restored.
Change shell again but this time change it permanently.
Solution
To view the current shell use echo $0 command. To list all available shells either use cat/etc/shells or
use chsh –l command.
To change the current shell permanently use chsh –s /bin/csh command. Change will take place at next
login.
Kernel
Kernel is the core application in Linux operating system. It communicates directly with system devices such
as memory, CPU, CDROM, Hard disk etc.
3. Remove a Package
To remove the “.deb” package, we must specify the package name “flashpluginnonfree“, not the original
name “flashplugin-nonfree_3.2_i386.deb“. The “-r” option is used to remove/uninstall a package.
You can also use ‘p‘ option in place of ‘r’ which will remove the package along with configuration file. The
‘r‘ option will only remove the package and not configuration files.
2. apt-get
It is a high-level package manager for Debian and derivatives, and provides a simple way to retrieve and
install packages, including dependency resolution, from multiple sources using the command line. Unlike
dpkg, apt-get does not work directly with *.deb files, but with the package proper name.
What is apt-get
The apt-get utility is a powerful and free package management command line program, that is used to work
with Ubuntu’s APT (Advanced Packaging Tool) library to perform installation of new software packages,
removing existing software packages, upgrading of existing software packages and even used to upgrading
the entire operating system.
What is apt-cache?
The apt-cache command line tool is used for searching apt software package cache.
1. How Do I List All Available Packages?
To list all the available packages, type the following command.
3.rpm
It is the package management system used by Linux Standard Base (LSB)-compliant distributions for low-
level handling of packages. Just like dpkg, it can query, install, verify, upgrade, and remove packages, and is
more frequently used by Fedora-based distributions, such as RHEL and CentOS.
Some Facts about RPM (RedHat Package Manager)
RPM is free and released under GPL (General Public License).
RPM keeps the information of all the installed packages under /var/lib/rpm database.
RPM is the only way to install packages under Linux systems, if you’ve installed packages using
source code, then rpm won’t manage it.
RPM deals with .rpm files, which contains the actual information about the packages such as: what it
is, from where it comes, dependencies info, version info etc.
5.Zypper
Zypper is the native command-line interface of the ZYpp package manager to install, remove, update and
query software packages of local or remote (networked) media.
1. Install a Package using zypper
To install a package using zypper command, use the following syntax:
zypper install <package Name>
Example: zipper installMozillaFirefox
2.Update a Package
The following will upgrade only MozillaFirefox package.
zypper update MozillaFirefox
# cat<options><File>
Some of basic options are listed below that can be used in cat command.
Thanks
[root@linuxtechi ~]#
root@linuxtechi ~]#
Now press ‘Ctrl-d‘ to inform cat that it has reached end of file (EOF). In this case it will display the line of
text twice because it copies std input to std output.
[root@linuxtechi ~]#
3 Thanks
[root@linuxtechi ~]#
In case if your file has blank lines , then above command will also display the number of blank lines as well,
so to remove the numbering of blank lines , we can use ‘-b‘ option in place of ‘-n’ in the above command.
Example:7 Copy the contents of One file to Another file.
Using greater than ‘>‘ symbol in cat command we can copy the contents of one file to another , example is
shown below :
[root@linuxtechi ~]#
[root@linuxtechi ~]#
Above Command will append the contents of /etc/passwd file to linux_text file at the end. Now we can
verify the contents of linux_text file.
Above command will merge the output of 3 files into a single file ‘linux_merge_text’.
By default sorting will done on the alphabetic order, if you want the sorting on basis of number then use ‘-
n’option in the sort command.
[root@linuxtechi ~]#
Above command will insert ‘$’ at the end of each line in the output.
Example:13 Show the tab space in the file as ‘^I’ using -T option.
Let’s create a file with some tab spaces.
[root@linuxtechi ~]#
[root@linuxtechitmp]# cattest_file
hi there
[root@linuxtechitmp]# cat -v test_file
hithere^M
After pressing this key, you'll see a colon character appear at the beginning of the last line of your vi editor
window, and your cursor will be moved to that position. This indicates that vi is ready for you to type in a
"last line command".
Save and quitting a file
:w => save the file
NBKRIST IV B.TECH CSE-II Sem Page 36
:q => quit the file
:wq => save and quit
:w! => force save the file
:q! => force quit without save
:wq! => save and quit forcefully
Inserting Text
i Insert before cursor
I Insert before line
a Append after cursor
A Append after line
o Open a new line after current line
O Open a new line before current line
r Replace one character
R Replace many characters
Motion(Navigational commands)
h Move left
j Move down
k Move up
l Move right
w Move to next word
W Move to next blank delimited word
b Move to the beginning of the word
B Move to the beginning of blank delimited word
e Move to the end of the word
E Move to the end of Blank delimited word
( Move a sentence back
) Move a sentence forward
{ Move a paragraph back
} Move a paragraph forward
0 Move to the begining of the line
$ Move to the end of the line
1G Move to the first line of the file
G Move to the last line of the file
nG Move to nth line of the file
:n Move to nth line of the file
fc Move forward to c
Fc Move back to c
H Move to top of screen
M Move to middle of screen
L Move to botton of screen
% Move to associated ( ), { }, [ ]
Deleting Text
Redirection operators
Once you type the ' cat ' command, use the Redirection operator and add a name for a file. Then start
typing your line. And finally press Ctrl+D. You will have a file named ' filename ' in the same directory.
Suppose you want to add a single line to an existing file.
Redirect Descriptor:
Descriptor Description
0 (STDIN) Standard Input
1 (STDOUT) Standard Output
2 (STDERR) Standard Error Output
3-9 (UNDEFINED) These handles are defined individually by the application and are
specific to each tool.
> Redirect standard output
2> Redirect standard error
2>&1 Redirect standard error to standard output
< Redirect standard input form
>> Append to standard output
& Run as background process
| Reads the output from one command and writes it to the input of
another command. Also known as a pipe.
Example:
Piping
Piping means to redirect the standard output of a command to become the input to another command.
Thesyntax:
command1 | command2
[root@centos6 ~ ]# date
Sun Aug 16 22:06:18 EET 2016
[ root@centos6 ~ ]# date | tr `a-z` `A-Z`
Sun Aug 16 22:06:18 EET 2016
Command Description
tr Translate characters
cb C program beautifier