linux basics june2012
TRANSCRIPT
-
7/31/2019 Linux Basics June2012
1/57
Linux Fundamentals
Courseware Designed & Written by
P Narasimhan
Acknowledgement
Some portions of this reference documentation has been derived from various sources including
the HOWTO's, Guides from the Linux Documentation Project , Man & Info pages, FAQ's and
technical articles from several other sources on the World Wide Web. We are thankful to and do
hereby sincerely acknowledge the creators of these documents.
This courseware is given free of cost as a reference material covering the topics dealt with during
the training programme(s), precisely for internal circulation only and is not intended for sale
anywhere.
Linux is the Trademark of Linus Torvalds and all other brand names and trademarks are
properties of their respective owners.
P Narasimhan
-
7/31/2019 Linux Basics June2012
2/57
No Warranty Clause
The authors disclaim all warranties with regard to this document and the configurations covered
thereto, including all implied warranties of merchantability and fitness for a certain purpose. In no
even shall the authors be liable for any special, indirect or consequential damages or any damage
whatsoever resulting from loss of data, or profits whether in action of contract, negligence or other
tortuous action, arising out of or in connection with the use of this document or any of the
software mentioned therein .
P Narasimhan
-
7/31/2019 Linux Basics June2012
3/57
-
7/31/2019 Linux Basics June2012
4/57
CH A P T E R - 1 : AN O V E R V I E W O F TH E OR I G I N S O F UN I X AN D
LI N U X
During the early days of computing it was very difficult to interact with computers
as many of the luxuries with which we are familiar today were not available those
days. It was left to a few dedicated Engineers at AT&T ( Bell Laboratories) to
initiate research to arrive at what is now known as an Operating System during the
early 1960's. They named the project as 'MULTICS' (Multiplexed Information &
Computing Systems) and the other organisations which formed part of this were
General Electric Co. and MIT. As sufficient interest was not shown by the othersAT&T walked out of this project and initiated a new one, UNICS later renamed as
Unix. The first version was created in Bell Labs in the year 1969 initially through
assembler code( Machine Level Language) and later ported to a new high level
programming language called B, which was co-developed by Ken Thompson and
Dennis Ritchie. The Unix operating system thus developed was ported on to PDP
machines which were lying unused. It is quite interesting to note that this high-end
OS along with its' source code was given away for as low a price as US $ 15-00 by
AT&T.
Further development took place and a higher and more powerful language C came
into existence, once again at Bell Labs. The entire code of Unix was rewritten in 'C'
by the year 1973. This version of Unix came to be known as System V with releases
up to 4 and christened as SVR4. Moreover the AT&T Unix code was used by a
P Narasimhan
-
7/31/2019 Linux Basics June2012
5/57
research group at University of California, Berkeley known as Berkeley Software
Distribution (BSD). The BSD group made significant contribution in the area of
development of various applications for Unix broadly referred to as BSD
tools/utilities. However, the same AT&T code was purchased by hardware giants
such as IBM, HP, Sun Micro Systems who made changes to suit their hardware
architecture and sold the modified OS under different brand names as AIX, UX , and
Sun OS(renamed later as Solaris) respectively. Thus it is recorded that Unix became
a proprietary OS and a hand maid in the hands of the companies almost to the end of
1970's, although the basic work was done by the dedicated researchers at Bell
Laboratories.
The basic beauty of the design methodology is that the output of one program can be
the input for another. This gives the user the flexibility to combine many small
programs together to perform a larger, more complex task instead of relying upon amonolithic single application.
In the year 1984, Richard Stallman, a research student at MIT started the GNU
Project (GNU's Not Unix), a recursive acronym to refer to an environment to develop
a FREE version of a complete Unix-like operating system which is free software:
the GNU system. Variants of the GNU operating system, which use the kernel called
Linux, are now widely used; though these systems are often referred to as Linux,
they are more accurately called GNU/Linux systems.
GNU is a recursive acronym for GNU's Not Unix; it is pronounced guh-noo, like
canoe. Many of the free software applications are under GNU's General Public
License orGPL in short which forms the legal back bone . The current version is 2.0
but version 3.0 is already framed and goes much beyond the terms of the older one
offering greater freedom to the users & developers.
What is Free Software?
``Free software'' is a matter of liberty, not price. To understand the concept, youshould think of ``free'' as in ``free speech,'' not as in ``free beer.''
Free software is a matter of the users' freedom to run, copy, distribute, study, change
and improve the software. More precisely, it refers to four kinds of freedom, for the
users of the software:
P Narasimhan
http://www.gnu.org/philosophy/free-sw.htmlhttp://www.gnu.org/gnu/linux-and-gnu.htmlhttp://www.gnu.org/philosophy/free-sw.htmlhttp://www.gnu.org/gnu/linux-and-gnu.html -
7/31/2019 Linux Basics June2012
6/57
The freedom to run the program, for any purpose (freedom 0).
The freedom to study how the program works, and adapt it to your needs
(freedom 1). Access to the source code is a precondition for this.
The freedom to redistribute copies so you can help your neighbor (freedom 2).
The freedom to improve the program, and release your improvements to the
public, so that the whole community benefits (freedom 3). Access to the
source code is a precondition for this.
He wanted the GNU Project to initially develop applications ,the ultimate goal being
the design of a new 32-bit kernel when the hardware industry would be read for such
an eventuality. He wanted to prevent such occurrences as seizure of software in the
future and hence created a legal basis in the form of General Public License or GPL
as it has come to be known as. Under the GNU GPL Act, the software is first
Copyrighted by the creator of software, thereby preventing someone else from seizing
control of it at a later date. Rights are granted to the public to use, copy, redistribute,
and also to modify/recreate freely under certain carefully defined conditions. These
developments have necessarily to carry with them the source code of the originally
created one and the modified source as well. The withholding of source code will be
viewed as curtailment of programmer's freedom to modify & improve software. His
goal was to recreate an environment free of restrictions with utilities and tools that are
totally 'Free'.
The GNU ( GNU's Not Unix )Project is being administered by Free Software
Foundation which was established to help raise funds for making free software. FSF
is the principal organizational sponsor of the GNU Project. The FSF receives very
little funding from corporations or grant-making foundations, but relies on support
from individuals. Richard Stallman a formidable programmer himself, wrote anamazing amount of software which includes the GCC (GNU 'C' Compiler) and the
versatile 'EMACS' editor.
The Minix (Miniature Unix on Intel 386) project was initiated by that famous
Professor Andrew Tannenbaum in 1989 as an educational version of Unix.
P Narasimhan
-
7/31/2019 Linux Basics June2012
7/57
Unfortunately this code could not execute bsd or gnu applications on Intel 386 based
systems as it was intended to be. The MINIX project took a new turn with the
involvement of a 21 year-old Finnish Computer Science Student at the University of
Helsinki, named Linus Benedict Torvalds in the year 1991. He made modifications to
the MINIX code with which he successfully executed a few Unix programs on Intel-
386 box. He posted the code on Minix Mail Group with a request to other
programmers to help him build it, precisely on 25th August, 1991. The response was
overwhelming and went beyond the wildest expectations. What began as a student
hobby project rapidly developed into a serious efforts at developing an operating
system within a short period of a couple of months.
P Narasimhan
-
7/31/2019 Linux Basics June2012
8/57
Torvalds found everything that is required of an OS in BSD and GNU utilities with
which he integrated his kernel, Linux. He put all this together and wanted to name the
OS as FREAX, perhaps to denote it's freak development. However, his friends
persuaded him to associate the OS with himself: Linux, Linus's Unix which he did
after much hesitation. It is interesting to note that from the very inception Linux
development took place on a collaborative and collective basis involving thousands
of users/developers across the net. This scenario led a prominent Unix developer,
Eric, S Raymond to take a fancy to this model known as an Open Source
Development. He wrote an interesting article christened as The Cathedral & the
Bazaar which is available at : http://www.firstmonday.dk/issues/issue3_3/raymond/ .
He said : Linux overturned much of what I thought I knew. I had been preaching the
Unix gospel of small tools, rapid prototyping and evolutionary programming for
years. But I also believed there was a certain critical complexity above which a morecentralized, a priority approach was required. Linus Torvalds' style of development -
release early and often, delegate as many things as you can, be open to the point of
promiscuity - came as a surprise. No quiet, reverent cathedral-building here - rather,
the Linux community seemed to resemble a great babbling bazaar of differing
agendas and approaches (aptly symbolized by the Linux archive sites, who'd take
submissions from anyone) out of which a coherent and stable system could seemingly
emerge only by a succession of miracles. Linus' open development policy was the
very opposite of cathedral-building. Linus seems to me to be a genius of engineering
and implementation, with a sixth sense for avoiding bugs and development dead-ends
and a true knack for finding the minimum-effort path from point A to point B.
Indeed, the whole design of Linux breathes this quality and mirrors Linus' essentially
conservative and simplifying design approach. Given a large enough beta-tester and
co-developer base through the medium of the World Wide Web, almost every
problem will be characterized quickly and the fix obvious to someone. Thus ran the
First Law of Linus :
Given enough eye balls, all bugs are shallow.
Sociologists years ago discovered that the averaged opinion of a mass of quality
expert (or equally ignorant) observers is quite a bit more reliable a predictor than that
P Narasimhan
http://www.firstmonday.dk/issues/issue3_3/raymond/http://www.firstmonday.dk/issues/issue3_3/raymond/ -
7/31/2019 Linux Basics June2012
9/57
of a single randomly-chosen one of the observers. They called this the "Delphi
Effect".
It appears that what Linus has shown is that this applies even to debugging an
operating system - that the Delphi effect can tame development complexity even at
the complex level of an OS kernel.
LINUX : The advantages
Zero Price Point
Do-it-yourself flexibility
Freedom from User licensing
Stability
Performance
Standards Compliance
Interoperability
Virus-proof
Strong cryptography
Diverse Hardware Support
Linux is not to considered a cooler alternative to MS-Windows, just cheaper &
more stable, virus-free etc. as a few dub that to be. It is much more than that; the
original Unix qualities great expressive power combined with simplicity &
elegance, remain untarnished. This approach is based on the proven track record of
Unix as in the maxim divide and conquer.On Unix systems small utilities/tools
such as awk, sed, find, grep are combined to give you the power to solve the
problems. These are small, modular tools that can be assembled in different ways.
However, Linux is not Unix, as it is written literally from scratch without a single
line of code from Unix. It is Unix-like operating system or a Unix clone. Linus
Torvalds based his Linux code on POSIX standards set by IEEE, and that
unparalled book The Design of the Unix Operating System by Maurice J. Bach.
Linux Support
The very first company to promote Linux commercially has been the company known
as Walnut Creek CDROM which first released Slackware Linux based on Linux
kernel version 1.0 in the year 1994.
P Narasimhan
-
7/31/2019 Linux Basics June2012
10/57
This development triggered other Linux companies to come into existence and
release their own distributions of Linux,some of which are listed below :
Slackware Linux
Debian Linux ( A totally community driven project)
RedHat Linux
SuSE Linux ( A German company now acquired by Novell)
Mandriva Linux
Knoppix( Developed by Dr. Knopper as a Live CD based on Debian)
Ubuntu ( A Debian Derivative)
Damn Small Linux ( A mini Linux distribution)
Linux PPC
Gentoo Linux
Fedora Project
The Fedora Project is sponsored by RedHat but not supported by the said company,
The first version Fedora Core-1 got released in 2003. There are core releases of
Fedora with the latest being Fedora 17 released in April 2012. In between core
releases there are test releases as well which are nothing but beta versions.
The detailed documentation on various aspects of Fedora is available at :
http://www.fedora.redhat.com
http://fedoranews.org
http://fedora project.org
http://www.fedorafaq.org/
The current popular distributation of Linux is Ubuntu version 12.04 released in April 2012.The official
website is ubuntu.com and the links to help and documentation are all present there. It is a totally free
software and can be downloaded from their website. There is choice of either installing the OS on your
hard disk or just try it on the Live CD/DVD/PenDrive without an installation.
P Narasimhan
http://www.fedora.redhat.com/http://fedoranews.org/http://fedoraproject.org/http://www.fedorafaq.org/http://www.fedora.redhat.com/http://fedoranews.org/http://fedoraproject.org/http://fedoraproject.org/http://www.fedorafaq.org/ -
7/31/2019 Linux Basics June2012
11/57
Application Base of Linux
Network Servers
DNS, DHCP servers
Apache Web Server ( Widely & Largely used )
Squid Proxy Server
Sendmail, Qmail, Postfix Mail Servers
NFS and NIS servers ( Integrating a homogeneous network)
Samba Server ( Integrating a heterogeneous network)
RDBMS
PostgreSQL, MySQL ( Open Source Tools),DB2 from IBM, Oracle 10g
Office Automation
Open Office-2.0 ,StarOffice (Sun Microsystems), Koffice, Gnu Cash ( Accounting
software).
Internet Related
Mozilla, Firefox,Opera, - Browsers
Kmail, Evolution, Mozilla-ThunderBird - Mail Clients
Yahoo Messenger, Gaim, ICQ
Currently Internet Telephony is available through Skype, Ekiga Softphone, and
Gizmo Projects as well.
Miscellaneous Applications
IBM ViaVoice : Voice Recognition software
Hylafax : Fax Server
Backup Utilities: BRU Backup & Restore Utility, Amanda, Arkeia
Graphic tools such as GIMP (similar to Photoshop)
Web Authoring tool : NVU
P Narasimhan
-
7/31/2019 Linux Basics June2012
12/57
Desktop publishing Tool : Scribus (similar to Corel Draw)
Entertainment
Audio/MP3 players such as CD Player, XMMS, Banshi, Beep
Video Players : Mplayer, Kplayer, Xine, Kaffeine, Totem, Real Player-10.0 (Latest),Stream Tuner, Webcam, Digital camera & Video Conferencing tools such as Gnome
Meeting.
Linux TV Project
TV Time, Xawtv, Mtv, Zapping TV Viewer etc.
Development Tools
GCC, G++, Pascal, Fortran, Java, Perl, PHP, Python, Tcl /Tk, Zope, Zend
IDE's
GTk, KDevelop , Qt,Eclipse, Anjuta etc.
Embedded Solutions
UcLinux, RTLinux, EmDebian & many others.
Server Antivirus Software: FProt, Panda, Sophos, ClamAV
Enterprise Solutions
Red Hat Enterprise Linux Server( RHEL-4)
SuSE Linux Enterprise Server from Novell( SLES-10)
Ubuntu Server -2006
Firewall Solutions
IP Tables, Shorewall, Firestarter
CAD utility
Varicad
P Narasimhan
-
7/31/2019 Linux Basics June2012
13/57
CD Burning Tools
Gnome Toaster, K3b, Xcdroast
Server Administration Tools
Webmin, SWAT, both web-based and YaST (on SuSe Linux).
Clustering Tools
Enhanced Cluster Tools (ECT), Enfusion, Extreme Linux, Beowulf
Cluster Tools including Sclyd, Oscar.
Linux Distributions are available for Intel, Sun Sparc Alpha Systems Distributions
and for Apple Mac systems. Currently most popular brands of Display Adapters,
Network Interface Cards(NIC), Sound Cards, Printers, Scanners, Modems, Backup
devices including the more recent USB devices, Pen Drives and support for Multi-
Processor Servers, Desktops, Laptops and Personal Digital Devices(PDA) are fully
supported.
P Narasimhan
-
7/31/2019 Linux Basics June2012
14/57
C H A P T E R - 2 : U S E R I N T E R F A C E S
The Default Shell in Linux : Bourne Again Shell (BASH)
The shell is a program that takes your commands from the keyboard and gives them
to the operating system to perform. In the old days, it was the only user interface
available on a Unix computer. Nowadays, we have graphical user interfaces (GUIs)
in addition to command line interfaces (CLIs) such as the shell.
On most Linux systems a program called BASH(which stands for Bourne Again
SHell, an enhanced version of the original Bourne shell program, sh, written by
Steve Bourne) acts as the shell program. There are several additional shell programs
available on a typical Linux system. These include the Bourne, Korn , and the Cshells which have been in use on legacy Unix systems since long.
Bash is an sh-compatible command language interpreter that executes commandsread
from the standard input or from a file. Bash also incorporates useful features fromthe Korn and C shells (ksh and csh). The basic configuration files for bash are :
bash_profile, bashrc
The default shell bash provides the following basic features :
Command Interface
Command Interpreter
P Narasimhan
-
7/31/2019 Linux Basics June2012
15/57
Sets Environment Variables
For example :
1) PS1=[ \u@h\w ] %; export PS1 will change the command prompt to
something like this : [muralinux@galaxy ~ ] %
2) PS1= [ \d \t ] $ :export PS1 will change the command prompt to
something like this : [ Thu Apr 26 22:05:45 ] $
Supports I/O redirection
Job Control
Command line editing is enabled
It supports command repetition and completion as well
It acts like a programming language (Shell Scripts)
The Graphical User Interface
The X Window System
The default underlying support is provided by X Window System orX
It was developed at MIT in 1984 by the name 'Project Athena' & later
renamed as Xfree86 Project
X is not the Graphical User Interface by itself, but provides the base graphics
infrastructure facilities
It effectively replicates a Client/Server Architecture/Windowing environment
with X acting as the server and desktop applications being clients.
X is OS independent
It is TCP aware protocol
It allows remote applications to be run
Top layer special client applications are window managers as they
encapsulate other client applications.
The Desktop Environments available on a Linux system are :
P Narasimhan
mailto:u@hmailto:u@hmailto:muralinux@galaxymailto:u@hmailto:muralinux@galaxy -
7/31/2019 Linux Basics June2012
16/57
KDesktop Environment (KDE) developed by German students
GNOME (Gnu NetworkObject Model Environment) from GNU Project
The other light-weight desktops are : XFCE, Flushbox, and ICEWM
These applications provide the look and feel, colours, icons, panel of the system
The X Window System is also known as the X Protocol. It started as "Project
Athena" by a group set up at MIT in the year 1984. It culminated successfully in the
year 1986 and was renamed as the XFree86 project. It is not a GUI by itself, but only
provides the basic graphics infrastructure. It helps in recognizing & initializing
crucial hardware such as the graphics card, monitor, and the mouse. XFree86 has now
a competitor in Xorg project which is currently used by the current versions of most
of Linux distributions. It is still used today because of its good and extensible
modular design. It has a very flexible structure capable of being ported easily. X is
OS independent and available on many platforms. It is now handled by the X
Consortium and the relevant website is at www.x.org. The software is freely
available, very versatile, and is suitable for a wide range of hardware platforms.
Any X environment consists of two distinct parts, the X server and one or more X
clients. It is important to realize the distinction between the server and the client. The
server controls the display directly and is responsible for all input/output via the
keyboard, mouse or display. The clients, on the other hand, do not access the screen
directly - they communicate with the server, which handles all input and output. It is
the clients which do the "real" computing work running applications or whatever.
The clients communicate with the server, causing the server to open one or more
windows to handle input and output for that client.
Just as the X and xfs are required on the server side, window managers are the most
essential components on the client side.
This replication of client/server model is present on a single, stand-alone machine
running the X protocol and not merely in a network. These applications could be
referred to as the "Super Clients" as these constitute the first step towards
construction of client-side applications. In short it is a window manager that provides
the "look and feel" of the GUI.
P Narasimhan
http://www.x.org/http://www.x.org/http://www.x.org/ -
7/31/2019 Linux Basics June2012
17/57
The X also requires the support of the Desktop environments. Desktop refers to the
presentation of windows, menus, panels, icons, and other graphical elements on the
computer screen. Originally, Linux operated purely in text mode, just commands
typed on the screen. But today it provides a wide range of Desktop environments,
among which GNOME (GNU's Network Object Model Environment) and KDE (K
Desktop Environment), are the most popular.
Starting the X Server
In case you have configured the system to boot in to the text mode and later on decide
to have access to the GUI, it would be necessary to invoke the same from the terminal
as follows:
$ s t a r t x
It is possible to have multiple instances of X to run on a single system concurrently.
This is achieved by running the command :
$ s t a r t x - - : 1
By default the Gnome desktop will be provided for most of the Linux flavours. In
order to switch the default desktop to KDE permanently (provided it is installed)
execute the command :
$ s w i t c h d e s k k d e
If the system is configured to boot in to the GUI login screen through GDM is
available at F7 terminal; you have a choice of choosing a desktop for example among
kde and gnome (from thesession label) for that session or on a permanent basis.
The Application Menu
To run applications on the desktop, most X window managers provide a menu,
similar to the 'start' menu of Microsoft Windows, to display and select X applications.
Currently the GNOME desktop has the panel on the top by default. Applications are
usually organized in well-defined categories.
P Narasimhan
-
7/31/2019 Linux Basics June2012
18/57
From the GNOME or KDE desktops in Linux, open the menu, select the category,
and then select the application to run.
LINUX DESKTOP ENVIRONMENT
By default, Linux gives four virtual desktops to open different
applications/windows. If you want to send an open window from one desktop to
another, right-click on the window's title bar. This opens a drop-down menu. Select
To Desktop and choose the desktop you want to send it to.
Creation of desktop shortcuts :
Right-click on the desktop and go to Create new>Link to application. In the window
that pops up, in the 'General' tab, specify a name for the shortcut. Click on the wheel
icon on the left to select a different icon for the shortcut. In the Execute tab, click on
browse and select the application you want to run. Most applications will be in /bin or
usr/bin directory (/sbin for root user). There are a number of other parameters you can
specify here, which can be ignored for the moment. Your shortcut will now appear on
the desktop. This way, you can create shortcuts only for applications.
Another quick way of creating shortcuts is to go to the file or directory you what the
shortcut for in file manager, and drag it with the mouse to the location where you
want the shortcut. When you release the mouse, a menu opens up with three options-
Copy here, Move here and Link here. Select Link here to create the shortcut. This
way, you can create shortcuts to any file or directory, anywhere.
If you happen to get stuck somewhere, don't worry. There are a number of ways toget help. The first of these is KDE's own help files. Clicking on your KMenu and
choosing Help can access these. Here you can search for the things you are
specifically looking for.
P Narasimhan
-
7/31/2019 Linux Basics June2012
19/57
The next place is under the Documentation tab in your KMenu. Here you'll find the
Linux HOW-TO articles, and lots of other useful guides.On PCQLinux, on the
desktop you will find three icons-PCQuest Linux Articles, Linux@IBM, Indian
Linux Community. Clicking on any of these will open up a corresponding website,
where you can search for what you are looking for, and also browse through the
articles that are already available there.
If you get stuck with any command while working in the Terminal, (the Linux
command line), then you can use the man command to get help.
Giving your desktop a familiar Windows look :
There are a number of things you can do in Linux to make your desktop look and actmore like the Windows desktop that you are used to. The first of these is to change
the complete look and feel of your application windows. To do this, right-click
anywhere on the title bar of any open window. This will open up a drop-down menu,
in which you choose Decoration, and then Win 2K. If you are used to say, Solaris and
not Windows, then you can choose RISC OS here.
To make changes to your KPanel (similar to the Windows taskbar), right-click on
anywhere on your KPanel where there is empty space, that is, not on the application
icons or desktop numbers. Choose 'Setting' from the menu that comes up. Under the
General tab, change the Panel size to Small, and enable the Automatic hide option. As
an extra, you can also specify the time after which your panel will hide itself.
You can also add volume control on your K Panel, just like in Windows or the
MacOS. To do this right-click on your KPanel, select Add/Applet, and choose KMix
Applet.
You can also change your desktop wallpaper to any graphic you want (if it is a BMP,
you will have to convert it to TIF or JPEG first). Now right-click anywhere on your
desktop and select Configure Background. Click on the Wallpaper tab and browse to
the location of the image file that you want to use as your Wallpaper. Like in
Windows, you can choose between various wallpapers modes such as tiled, centered
etc. Click Apply and you're done.
P Narasimhan
-
7/31/2019 Linux Basics June2012
20/57
As an extra, you can choose multiple wall papers here and cycle through them at
fixed intervals that you set up. Also, each virtual desktop can have a different
wallpaper.
Terminating Hung Applications :
Windows has the famous Ctrl+Alt+Del key combination to shutdown applications or
programs that have crashed. What this does is send a 'kill' signal to the process and all
its threads so as to terminate them and thus free up system resources. Win NT, 2000
and XP users would be familiar with the Task Manager from where you can do this.
KDE provides a similar application called the KDE System Guard.
Press 'Ctrl+Esc' to invoke the KDE System guard. You can also invoke the Systemguard from the KMenu, from the System menu item.
The System guard gives comprehensive information about the running or sleeping
processes and the amount of system resources they are using. Each running process
also has a unique identifier called the PID (Process ID). A better way of
understanding this is to switch to 'Tree' view in KDE System guard. Select the erring
process name and right click on it. Choose 'Select all child processes' and hit the 'Kill'
button in the lower part of the System guard window. And you are done.
Playing audio Cds :
The CD player in KDE is located under Multimedia in your K Menu.
It has most of the features which other software CD players have, and getting used to
it shouldn't be a problem. It also has a configuration window, which lets you change
things like LCD color, background color, docking options and more. This can beaccessed by clicking on the small icon showing a hammer and a screwdriver.
Once you insert the CD and close the tray, bring up the CD player and start it off. If
you want it to play the CD automatically, then, click on the hammer and screwdriver
icon (kscd configuratio) icon, select the kscd options tab in the window that opens,
P Narasimhan
-
7/31/2019 Linux Basics June2012
21/57
and enable the 'play on tray close option'.You need to have the CD player application
running when the tray is closed, for this to work.
Audio settings :
Your audio settings can be adjusted using a simple utility called Sound Mixer. You
will find it under the Multimedia tab of your KMenu. This will open up a small
window, which shows you the current level of your Main volume, Microhone, Line-
In, CD Audio etc., which can all be adjusted easily by simply holding and dragging.
If you want a small volume icon next to your clock, click on settings and choose
configure KMix.Now put a tick next to Dock into Panel.
Screen savers, desktop themes and wallpapers :
The Control Center is a central place from where you can carry out all the above
functions. Fire up the Control Center from your KPanel (the fourth icon in your
KPanel). Click on the Look and Feel Tab. In the sub-menu that opens up, locate
Background. Here you can change your background color, and select a wallpaper.
Next click on the Screen saver tab. This opens up a list of screen savers, from which
you can choose the one you want. You can also set the time after which the screen
saver will run, and also specify a password, which will be required to get out of a
screen saver.
Similarly for themes, click on the Theme Manager Tab, and choose from the list of
themes. If you click on the Contents tab of a particular theme, them you can specify
particular areas like icons, wallpaper which you don't want to change after the new
theme takes over. Many sites (like www.kde-look.org) also let you download
additional themes. These files will usually have a .ktheme extension. Once
downloaded you can add it by clicking on the Add button in the Theme Manager
itself. You'll have to browse to the location where you have downloaded it.
Changing the display resolution :
The resolutions that will be available to you, can be specified during your Linux
installation. When your display card is being configured, choose multiple resolutions
and color depths from the select video modes menu (ensure that all of them are
supported, by testing them). Alternatively, you may type 'Xconfigurator' in a terminal
window after installation and choose more resolutions. Once this is done, to switch
P Narasimhan
-
7/31/2019 Linux Basics June2012
22/57
resolutions, use the 'Ctrl+Alt' key combination with + or - (for increasing and decreasing
resolution) from the numeric keypad.
Note however that switching to a higher resolution will increase the overall screen
size rather than 'squeezing' the desktop into the available screen area. This appears
more like 'zooming' your desktop, and you move to areas of the desktop outside your
monitor using the mouse.
Setting the date and time :When you login and start KDE, your clock will be at the right-hand bottom corner of
your screen, in the same position where it is found in Windows, on the KPanel
(similar to the task bar). If you have too many items on the panel, you may have to
scroll the panel to the right to see the clock. KDE allows you not only to change your
date and time, but also to choose from different styles of clocks and display formats.
Right-click on your clock. This will open up a menu with five options.
Let's take a quick look at what all you can do here. The first option is type, which lets
you choose between digital, analog and a fuzzy clock. The fuzzy clock shows the
time in words for example as in ten past nine. The next option is preferences. This
lets you make finer adjustments to the clock you have chosen. You can change its
color, the fonts and choose to show the date as well. The third option 'Adjust date and
time' is where you get to actually change your time and choose your time zone. For
example, in India, then you would choose Asia/Calcutta (you would have already
done that during installation). The next option lets you change the format in which
your time and date is displayed. And finally, the last option lets you copy the present
date and time to the clipboard from where it can be pasted into other applications like
KWord.
Install/uninstall or upgrade Linux apps :
Once you have a Linux system running, you will sooner or later want to install more
software. In Windows these tasks are performed by the Windows installer, which can
be accessed through the Add/Remove Programs applet in Control Panel. Linux
P Narasimhan
-
7/31/2019 Linux Basics June2012
23/57
applications are bundled into something called RPM (RedHat Package Manager)
packages and then installed, upgraded or deleted through the KDE Package Manager.
Shutting down and restarting your Linux machine :
You can shutdown and restart your Linux machine from pretty much the same place
as in Windows. Click on your KMenu button and select Logout. This can also be
used to switch between users, in case multiple people use that same machine. You
can now choose to either log in again as a different user, shutdown your machine,
restart your machine or go into the command line mode. The last option is similar to
restart in DOS mode option in Windows.
Another option you get here is to restart the X Server. If you face problems with your
GUI, like it not refreshing properly, then you need to restart your X Server.
C H A P T E R - 3 : L I N U X I N S T A L L A T I O N
The Basic Premises Underlying the process
Installation process is one of the primary steps required to understand before using
any Operating System. The latest releases of Linux distributions include easy and
user friendly GUI / menu guided screens which makes the installation process easier
and also helps to understand the complexities involved in the process. The following
document contains a brief discussion over the installation process which can be handy
for the end-user to successfully install the OS and have it fully functional.
Identity of Devices
Before starting with the installation process it is very important to know about the
devices involved in the process and as identified by the Operating System.
P Narasimhan
-
7/31/2019 Linux Basics June2012
24/57
The following section defines some of the devices which are relevant for the
installation process.
An standard IDE interface will accept four devices. They are identified as follows:
I D E D e v i c e s
P r i m a r y M a s t e r / d e v / h d a
P r i m a r y S l a v e / d e v / h d b
S e c o n d a r y M a s t e r / d e v / h d c
S e c o n d a r y S l a v e / d e v / h d d
Floppy Drives
F l o p p y D r i v e : 1
/ d e v / f d 0 [ A : \ u n d e r D O S ]
F l o p p y D r i v e : 2
/ d e v / f d 1 [ B : \ u n d e r D O S ]
Communication port
The COM ports are identified as :
C O M p o r t 1 / d e v / t t y S 0
C O M p o r t 2 / d e v / t t y S 1
Parallel Ports
The parallel ports are identified as :
P o r t 1 / d e v / l p 0
P o r t 2 / d e v / l p 1
U S B P o r t s
Any device that is connected to the USB port is invariably identified as a SCSI device
in Linux. It is addressed as /dev/sda or /dev/sdb as the case may be. However, the
identification of the first printer connected to the USB port is/dev/usb/lp0.
P Narasimhan
-
7/31/2019 Linux Basics June2012
25/57
Getting started with the installation Process
To begin with the installation process boot through the Linux installation CD #1. The
installation process begins with a boot prompt. In case a graphical mode is preferred
just press Enter. Otherwise type linux text and press Enter to begin the Installation
in simple text mode.
During the installation process, Linux will prompt for various options relating to the
system hardware settings. It is recommended to have a check list of the available
hardware on the system which helps the user to select the devices without much run
around.
Media Check
This process will check the integrity of complete Installation CD set, to be sure that
none of the CD's in the set is not damaged or corrupted Linux provides a MediaCheck utility. This option can be skipped if you are sure about your media.
Choose language
When prompted, choose your language of interaction and select OK to begin with
other step of installation.
Choose keyboard
Choose the keyboard Type (U.S English) & click OK. This is the general keyboard
architecture used, or select accordingly if a different keyboard is present.
P Narasimhan
-
7/31/2019 Linux Basics June2012
26/57
Choose a mouse
When prompted, indicate the type of mouse and click OK. The normal mouse types
are : serial, PS/2, USB etc.
Choose install type
Choose a configuration, such as Personal Desktop (for laptop, home or desktop PCs),
Workstation (desktop plus software development), Server (file, print, web other
server software) or Custom (Allows to select both the workstation / server category
packages).Among the above options selecting Custom would give the end user a
better control over the selection of the packages.
Partitioning
1) You may choose Auto-partitioning if a first-time user not fully aware of the
partitioning schema . The installer program will provide the following options which
can be selected depending on the requirements.
Remove all Linux partitions on this system
Windows and other non-Linux partitions remain intact with
this selection.
Remove all partitions on this system
This erases all the partitions on the hard disk, including
Linux and non Linux partitions.
Keep all partitions and use existing free space
P Narasimhan
-
7/31/2019 Linux Basics June2012
27/57
This only works if you have enough free space on the harddisk that is not currently assigned to any partition.
2) Using Disk Druid Utility :
All partitions will get displayed in the menu one below the other with the
respective operating systems that are installed in them.
You need to highlight the free space and select New to add a new partition or
Edit to modify existing partition scheme.
Assign a mount point which is the device access point for the particular OS
with the relevant file system selected.
In the above example a /boot partition of size 100 MB is added.
Configure Boot loader
All boot partitions and default boot loader options are displayed. By default,the
installation process will use the GRUB boot loader and will install it in the master
boot record of the computer and choose Linux as the default operating system to boot.
LILO is the older boot loader available in Linux. However, GRUB is the preferred
one currently since it has more options & capabilities.
P Narasimhan
-
7/31/2019 Linux Basics June2012
28/57
Master Boot Record (MBR)
This is the preferred place for GRUB or LILO. It causes either GRUB or LILO to
control the boot process for all the operating systems installed on the hard disk.
Configure Networking
At this point, the system prompts to configure the network. This applies only if the
system is on a network.
The figure shown below is indicative of this.
Set Hostname
This is the name identifying the computer within the domain, example
host1.myhome.edu.
Choose firewall Configuration
The use of firewall has significant impact on the security of the system. Select No
firewall if the system is stand alone.
Select packages
The package selection can be made depending on the system's configuration.
Normally in case of a home PC package categories such as Desktop (both GNOME,
KDE), Development tools, Office & Productivity, Multi Media, Printing, if a printer
is connected to the system may be selected.
Set Root password
You need to choose a password for the root user at this point. The root password
provides complete control of the Linux system, hence it is very important to
remember the assigned password for root user and keep it confidential.
Start of the Installation Process
A screen tells that you are about to begin installing the OS to the selected partition of
the hard disk after which the process is irreversible.
Create book disk
To create a boot disk, insert a blank floppy and click next to create a boot floppy.
P Narasimhan
-
7/31/2019 Linux Basics June2012
29/57
Configure video hardware
Video card should have been detected automatically and should be highlighted. If
not,choose the correct video driver from the list select the amount of video RAM
contained on the board. and click Next.
Select Monitor Configuration
Scroll down the list to find the monitor's manufacturer;then click the plus sign to
choose the model.
Finish Installing
Lastly the Congratulation screen will indicate the successful completion of the
installation process. It then performs certain post-install operations.
After this screen the system reboots to activate the installed Linux OS on the system.
The process of 'First Boot' gets started wherein such parameters as the sound card,
network card etc are allowed to be set up manually. In case you had selected the GUI
mode as the default login you will get a screen for providing your user name and
authentication by the chosen password .
P Narasimhan
-
7/31/2019 Linux Basics June2012
30/57
C H A P T E R 4 : R U N N I N G S H E L L C O M M A N D S & H E L P - L I N E
We have studied the basic features of the default shell bash on a Linux system in an earlier
chapter. Now we need to probe further and understand as to how to use the shell as users
inside the system. Broadly speaking there are two categories of users going by the nature of
privileges these groups enjoy or are denied.
Users
The most privileged user is the administrator logging - in as root
The root has complete control and has an userid (uid) of 0
Unprivileged accounts have UID's greater than 99
Normally the UID's of users start with 500 on a RedHat System.
These users operate under pre-set limitations within their respective areas
On a Linux system there are two class of users; the privileged users and the non-privileged ones. The latter class operate under severe restrictions and strictly within
their respective command areas & location, whereas the user root who is the
administrator of the system has unlimited access to everything in a Linux system.Linux provides for assignment of passwords at installation stage as well as after
logging into the system.
$ p a s s w d
All the users on a Linux system have certain standard utilities made available to
them. These are in the form of "virtual consoles" or multiple login facility. Users
could enter the system in their own personal name or in any other user name created
so as to facilitate & administer databases.
Every user has a home directory, typically under /home which is known by the
personal name of the user.
Contains user specific configuration files as well as user data. It is represented by the
~ character.
P Narasimhan
-
7/31/2019 Linux Basics June2012
31/57
As and when new users are created contents of /etc/skel are copied to their home
directories by default.
Local Logins and Virtual Consoles
User login on virtual console when in run-level 3
User login on GUI mode when in run-level 5
Multiple non-GUI logins are possible through the use of virtual consoles
There are by default 6 virtual consoles
These are invoked by pressing CTRL+ALT+F[1-6] function keys
If X is running, it is available as CTRL+ALT+F7
Changing Your Password Passwords are assigned for users created during the installation process
It is desirable to change passwords after the first login
From a terminal enter:
p a s s w d
n e w p a s s w d : < e x a c t p a s w o r d t o b e e n t e r e d h e r e >
The above command will prompt for the old password after which it will allow the
new password to be entered and re-entered for confirmation.
For example :
m u r a l i n u x @ G a l a x y : ~ $ p a s s w d
C h a n g i n g p a s s w o r d f o r m u r a l i n u x
(current) Unix password:
Enter new Unix password:
Retype new Unix password:
Running Commands
Commands have the following syntax:
P Narasimhan
-
7/31/2019 Linux Basics June2012
32/57
- name [options] [arguments]
Each block is separated by a space
Options modify the command's behavior
Arguments are filenames or other information such as output redirection or piping
the output to another utility to obtain the required output
For listing files & directories :
m u r a l i n u x @ G a l a x y : ~ $ l s
The option -l with the main command will display the same in a longer format with
details.
There are several help lines available for executing the Linux commands from within
the system itself. On the command line you may, for example execute :
m u r a l i n u x @ G a l a x y : ~ < c o m m a n d n a m e > - - h e l p
Alternately the manual pages in the form of man command and info command are
available. The info pages are organised with multiple sections with each section
dealing with a particular command or utility. If info is invoked without any
arguments it opens the complete set of help line available as part of info pages.
Other Help Utilities
Linux documentation Project (LDP) HowTO's
FAQ's
Several URL's with links to full-scale Linux Documentation sites .Just as
you have help from within the Linux system in the form of man and info
pages,there are also numerous other web sites for obtaining
documentation.
The Linux Documentation Project is accessible through the following link :
www.tldp.org .
You may also have access to RedHat-specific documentation from
www.redhat.com/docs/manuals/ where many topics are covered in an extensive
manner.
P Narasimhan
http://www.tldp.org/http://www.metalab.unc.edu/LDPhttp://www.metalab.unc.edu/LDPhttp://www.redhat.com/docs/manuals/http://www.metalab.unc.edu/LDPhttp://www.metalab.unc.edu/LDPhttp://www.tldp.org/http://www.metalab.unc.edu/LDPhttp://www.metalab.unc.edu/LDPhttp://www.redhat.com/docs/manuals/http://www.metalab.unc.edu/LDPhttp://www.metalab.unc.edu/LDP -
7/31/2019 Linux Basics June2012
33/57
The Linux CD-set also contains additional documents in the form of HOWTO's &
FAQ's. These documents help the Linux users to use the system with more precision.
C H A P T E R - 5 : L I N U X F I L E S Y S T E M & S H E L L C O M M A N D S
A basic understanding of the file system is necessary for a proper study of any
Operating System. This is because the file system is the prime component which is
responsible for storage of data on the hard disk or for that matter on any storage
media as such.
This session introduces some features of the Linux file system and its structure. With
this knowledge the user can issue commands to locate the files, and also get to know
the importance of each directory in the existing file system . A file is represented by
an index node called 'inode' whose number is unique to the file it represents.
Inode Definition
An inode is a data structure on a file-system within an Unix-like OS that stores all the
information about a file except its name and its actual data.
When a file is created it is assigned both a name and an inode number, which is an
integer that is unique within the filesystem. Both the file names and their
corresponding inode numbers are stored as entries in the directory that appears to the
user to contain the files. That is, the directory associates filenames with inodes.
Whenever an user or a program refers to a file by name, the system uses that name to
look up the corresponding inode, which then enables the system to obtain the
information it needs about the file to perform further operations. That is, a file name
in a Unix-like operating system is merely an entry in a table with inode numbers,
rather than being associated directly with a file (in contrast to other operating systems
P Narasimhan
-
7/31/2019 Linux Basics June2012
34/57
such as the Microsoft Windows systems). The inode numbers and their corresponding
inodes are held in inode tables, which are stored in strategic locations in a filesystem,
including near its beginning.
Whereas a file contains only its own content and a directory holds only the names of
the files that appear to the user to be contained in it and their inode numbers, an inodecontains all the other information describing a file.
This meta-data includes (1) the size of the file in bytes and its physical location (i.e.,
the addresses of the blocks of storage containing the file's data on a HDD), (2) the
file's owner and group, (3) the file's access permissions (i.e., which users are
permitted to read, write and/or execute the file), (4) timestamps telling when the
inode was created, last modified and last accessed and (5) a reference count telling
how many hard links point to the inode.
Linux File System
The file system on which the Linux works is named as EXT3 file system which
stands for Third Extended file system. This is the latest version of time tested Ext2fs
with additional features such as journaling.
On various Unix flavours Everything is a file Programs, scripts, devices and
configuration settings are all contained in files, and Linux treats all files in the same
way, regardless of where they are located.
As a Unix-like operating system, Linux also works along the same concept and it has
various files like the text file,directory file, a block file, a character file, a socket file,
a named pipe file etc.
The directory structure here resembles that of any Unix flavour, where it is
represented as an inverted tree. The top level of this tree is represented by the
character forward slash (/). This is also known as the ultimate parent directory or the
root directory. All the other directories are under / and can be accessed by
specification of their path.
Features of ext3 File System
P Narasimhan
-
7/31/2019 Linux Basics June2012
35/57
The file name can be up to 255 characters. These characters can be alphabets,
numbers and periods (.). , but cannot contain some special meta characters such as
#, $, / etc. which have special meaning on a Linux system. Since the dot is also
considered as a character, this can be used as a normal character in the file.
Linux doesn't have the concept of extensions, i.e., dot is another character used .Therefore, it doesn't identify a directory or a file by the extension that it has; but
extensions are used just for user identification or as required by a particular program.
For example 'C' Programs have a .c extension which is the requirement of the C
compiler rather than the underlying file system and so on.
File names in Linux are case-sensitive. Hence the file names File1, FiLE1,
FILE1 are all different from each other unlike in MSDOS/MSWINDOWS.
Some of the features of the filesystem are as highlighted below:
5% of every partition is reserved for root user.
Pre-allocation of disk data blocks to regular files.
The block size & the number of inodes in a block can be changed.
Automated filesystem consistency check.
Support for immutable & append-only files
Ext3 Filesystem
P Narasimhan
/
bin boot dev etc home lib
mnt proc root sbin var usr
File System Hierarchical Concepts
-
7/31/2019 Linux Basics June2012
36/57
The block diagram above shows the default system directories beneath the root
directory on a typical Linux system. We will now proceed to explore the basic nature
of the above shown directories.
bin : Used to store user commands. The files here are all binary executables
accessible to all users on the system.
boot : Contains the kernel and other files used during system startup.
dev : Stores device files. They are either character or block device files.
etc : Contains many configuration files and directories.
home : Typical location of users' home directories.
lib : Contains many library files used by programs in /bin and /sbin.
media : The directory contains the mount points for devices mounted after the system
is booted. By default the directories, floppy and cdrom are created to access the
respective devices.
mnt : It is an additional directory for allowing partitions containing other OS's to be
mounted.
opt : It is an optional directory normally used for downloading third-party
applications and extracting them for common usage.
proc : A virtual file system indicating the complete status of the processes that run on
the system. Holds information about kernel parameters and system configuration.
root : The home directory of the superuser.
sbin : Location of system commands. The executables under this location are binary
files that are related to administration & could be invoked only by the superuser.
tmp : This is a temporary directory containing some default Unix socket files and is
available to all the users .
usr : Contains files and directories directly relating to user applications. It has all
commands, libraries, man pages, games and static files for normal operation.
P Narasimhan
-
7/31/2019 Linux Basics June2012
37/57
We have made an exploration of the shell as well as the file system on which it is
being used. Now is the time to put to practical use the base applications or running
the shell commands to extract information from a Linux system.
var : Contains files that change for mail, news, printers log files, man pages, temp
files.
Current Working Directory
The very basic command that is required at the beginning is thepwdcommand. This
command outputs the present working directory the particular user is working on.
pwd
Displays the absolute path to the current directory (present working directory)
ls
List the contents of the current directory or a specified directory
The ls command has a variety of options apart from the basic one of listing the files
and directories.
As for example, it is used to have a long listing with additional details.
$ l s - l
d r w x r - x r - x 2 r o o t r o o t 4 0 9 6 0 4 - 2 2 0 8 : 4 2 b i n
d r w x r - x r - x 7 r o o t r o o t 1 0 2 4 0 8 - 1 4 1 9 : 5 2 b o o t
d r w x r - x r - x 1 7 r o o t r o o t 8 1 9 2 0 0 9 - 2 9 1 7 : 4 4 d e v
d r w x r - x r - x 6 9 r o o t r o o t 8 1 9 2 0 9 - 2 9 1 7 : 4 4 e t c
d r w x r - x r - x 7 r o o t r o o t 4 0 9 6 0 7 - 2 6 1 9 : 1 4 h o m e
d r w x r - x r - x 2 r o o t r o o t 4 0 9 6 2 0 0 1 - 0 6 - 2 2 i n i t r d
d r w x r - x r - x 7 r o o t r o o t 4 0 9 6 0 4 - 2 1 2 3 : 0 3 l i b
d r w x r - x r - x 2 r o o t r o o t 1 6 3 8 4 2 0 0 1 - 1 2 - 2 5 l o s t + f o u n d
d r w x r - x r - x 3 r o o t r o o t 4 0 9 6 0 4 - 2 1 2 2 : 5 9 m i s c
d r w x r - x r - x 1 3 r o o t r o o t 4 0 9 6 0 8 - 3 1 1 7 : 1 7 m n t
P Narasimhan
-
7/31/2019 Linux Basics June2012
38/57
d r w x r - x r - x 2 3 r o o t r o o t 4 0 9 6 0 7 - 2 7 2 3 : 1 3 o p t
d r - x r - x r - x 7 9 r o o t r o o t 0 2 0 0 2 - 0 9 - 2 9 p r o c
d r w x r - x - 3 9 r o o t r o o t 8 1 9 2 0 9 - 2 9 1 7 : 4 6 r o o t
d r w x r - x r - x 2 r o o t r o o t 8 1 9 2 2 0 0 1 - 1 2 - 2 5 s b i n
d r w x r - x r - x 3 r o o t r o o t 4 0 9 6 2 0 0 1 - 1 2 - 2 5 t f t p b o o t
d r w x r w x r w t 1 9 r o o t r o o t 4 0 9 6 0 9 - 2 9 1 7 : 4 7 t m p
d r w x r - x r - x 1 9 r o o t r o o t 4 0 9 6 0 6 - 2 3 1 9 : 0 2 u s r
d r w x r - x r - x 2 6 r o o t r o o t 4 0 9 6 2 0 0 2 - 0 2 - 1 6 v a r
File Manipulation
cp-copy files
mv-Move or rename files
touch- create empty files or update file time stamps
rm- remove files
The copy command is cp in Linux and is used to copy files from one location to
another.
$ c p c p r o g s / h o m e / u s e r 1
It could also be used to create another copy of a file with the same name or anotherone.
$ c p c p r o g s c p r o g s n e w
The command is so powerful as to allow multiple directories/sub-directories and files
to be copied en bloc from location to another very swiftly and effectively. In the
example given below, the directory temp with its' entire content, recursively diving
in to sub-directories is copied to linuser1 directory.
$ c p - R t e m p / l i n u s e r 1 /
The mv command is commonly used to physically move files from one location to
another or to rename a file. You may now look at examples to illustrate the same. The
undermentioned command would move file1 from the cwd to misc directory.
P Narasimhan
-
7/31/2019 Linux Basics June2012
39/57
$ m v f i l e 1 / m i s c
To rename the file "file2" as "newfile" you may type :
$ m v f i l e 2 n e w f i l e
Changing Directories
The cd command changes directories
To an absolute path starting from the top level / :
-$ cd/home/linuser1/projects
To a relative path:
-$ cd projects
- $ cd ./projects
-$ cd ././projects
The cd command is the same as in various flavours of DOS and is used to effect
change from the present working directory to another directory. The syntax "cd .."
would mean that the user is going one step back in the hierarchy. Running the
command as any user would that user to his home directory.
Directory Manipulation
m k d i r - C r e a t e a d i r e c t o r y
r m d i r - R e m o v e a n e m p t y d i r e c t o r y
r m - r f - R e m o v e s a d i r e c t o r y & i t s c o n t e n t s r e c u r s i v e l y
The next set of commands deal with creation and deletion of directories and also with
recursive elimination of directories and its sub-directories.
To create a new directory under the current working directory :
$ m k d i r n e w d i r
To remove a directory which is empty :
$ r m d i r n e w d i r
P Narasimhan
-
7/31/2019 Linux Basics June2012
40/57
To remove a directory which contains several sub-directories & files within it so as
to recursively go down the directory structure and remove files forcibly:
$ r m - f r n e w d i r 2
C A U T I O N :T h e a b o v e c o m m a n d i s p o t e n t i a l l y d a n g e r o u s o n e t o e x e c u t e a s i t i s
c a p a b l e o f w i p i n g o u t y o u r s y s t e m c o m p l e t e l y , u p r o o t i n g t h e f i l e s i n i t s '
e n t i r e t y a n d c a u s i n g i r r e p a r a b l e d a m a g e t o t h e s y s t e m .
Viewing Text Files
cat, more & less provide a quick way to view text files
The cat command enables viewing an entire file at the shell prompt,
sequentially without any break
Files display "concatenated"
The more and less commands offer the display of text files page wise, but
less is more powerful in the sense that it acts as a pager with a facility to
scroll up or down.
The head and tail commands show the first few lines of the beginning and
end of text files respectively
Earlier you have seen the use of the ls command. The more and less commands may
be used in conjunction with ls through a pipe.
The syntax is as given below:
$ l s - l / d e v | m o r e
As the contents of /dev directory is too large to be fitting into a single page, the more
or less commands are used to get page-wise display. Whereas with 'more' you can
only scroll down, less is a pager with the facility to scroll up or down.
The cat command is very powerful and is capable of providing a lot of information.
To view the contents of a file on the console like :
$ c a t f i l e 1
To create a new file & write into it, you need to type :
$ c a t > n e w f i l e
P Narasimhan
-
7/31/2019 Linux Basics June2012
41/57
At this point the user is presented with the cursor wherein a few lines could be typed
and the file saved by pressing CTRL+d by moving over to the next blank line.
Further, the catcommand could be used in conjunction with double operator(>>) to
append contents of one file into another.
$ c a t f i l e 1 > > f i l e 2
The headand tailcommands display the first & last 10 lines of a file specified, like :
$ h e a d / h o m e / m u r a l i n u x / f i l e 1
$ t a i l / h o m e / m u r a l i n u x / f i l e 1
GREP,SORT, DIFF, CUT, UNIQ
The sortcommand sorts all kinds of text data:
$ sort hello.txt
You may use the option -r to sort in the descending order
Another use of sort is to combine it with the grep command:
$ grep bash /etc/passwd |sort -r
The diff command would display the lines which differ in content :
$ diff /root/install.log /root/install.log.syslog
The cutcommand would cut the desired field and display
$ cut -f2 -d: /etc/passwd
The uniq command could be used with cut & sort to display unique lines:
$ cut -d: -f7 /etc/passwd |sort|uniq
PASTE, TR
Merge data from multiple files into one file using paste command:
P Narasimhan
-
7/31/2019 Linux Basics June2012
42/57
$ paste file1.txt file2.txt > newfile.txt
Use the -d option to change output delimiter :
$ paste -d: letters numbers>new.txt
This would paste the numerical values from the file "numbers" in the next fielddelimited by a tab on to the file "letters".
The tr command is used to translate or delete characters from data"
$ tr A-Z a-Z data2.txt (Upper case characters are translated to lower
case ones)
$ tr -d \r < dosfile >Unixfile
This would convert DOS text files to Unix style files.
ASPELL
Using aspell : A very powerful intercative spell-checker
$ aspell check letter.txt
It offers suggestions for corrections via a simple menu driven interface.
STANDARD I/O, PIPES
This section would help you understand standard i/o channels, file redirection and
pipes .
Linux provides three standard I/O channels to processes :
Standard input : keyboard is default stdin channel 0
Standard output : terminal window by default stdout channel 1
Standard error : terminal window by default stderr channel 2
Shell redirection operators allow standard I/O channels to be redirected to/from a file.
Pipes allow standard I/O channels to be connected,i.e, sending the output of one
program to be used as input for the other program.
P Narasimhan
-
7/31/2019 Linux Basics June2012
43/57
For example : $2 < error.txt redirects the error channel to error.txt file.
$ find /etc -name passwd
This command will search for all files named passwd in the /etc directory and its
subdirectories
The value returned by this command would be:
/etc/passwd
There are a set of commands which return values by searching the system for binary
executable files and provide their location as well explanation as to what these
executables do .These are :
[ r o o t @ s e r v e r m u r a l i n u x ] # w h i c h l s
a l i a s l s = ' l s - - c o l o r = t t y '
/ b i n / l s
[ r o o t @ s e r v e r m u r a l i n u x ] # w h e r e i s l s
l s : / b i n / l s / u s r / s h a r e / m a n / m a n 1 / l s . 1 . g z
/ u s r / s h a r e / m a n / m a n 1 p / l s . 1 p . g z
[ r o o t @ s e r v e r m u r a l i n u x ] # w h a t i s l s
l s ( 1 ) - l i s t d i r e c t o r y c o n t e n t s
Redirecting Standard Output
$ find /etc -name passwd >find.txt
This would redirect the standard output to the file and standard error to the terminal.
Overwriting or Appending
If the target file (find.txt) exists, in that case it would be overwritten.
To append data to an existing file, use >> instead of >
Redirecting Standard Error
P Narasimhan
-
7/31/2019 Linux Basics June2012
44/57
$ find /etc -name passwd 2alloutput 2 alloutput
Redirect input with : would bring such processes to the foreground
Locating Files
Linux System uses the slocate utility and locate is the command which is linked to
it.
$ locate inittab
All files created after the system boots do not find a place in the
slocate database. Hence you are required to freshen the same.
To update the slocate database you need to use the command:
$ updatedb
The find command
$ find
The locate command returns values that matches all files that have a specific pattern.
Let us take an example and examine the same :
$ s l o c a t e i n i t t a b
All files with the string "inittab" in their name will be displayed
A live example :
P Narasimhan
-
7/31/2019 Linux Basics June2012
50/57
$ f in d / - na m e . b a s h _ p r o f i l e
Removable Storage Media
The process of mounting actually links the removable media or a partition to the
native Linux file system
This provides an unified approach for viewing the contents of devices
To be able to use any media it has to be mounted at some point under root (/)
This utility also enables a Linux user to unify under its native root file system, and
precisely under the / directory, any other alien file system residing in other
partitions, disks, either in the local system or any system in the network.
For example:
# m o u n t - t m s d o s / d e v / f d 0 / m n t / f l o p p y
To unlink the device :
# u m o u n t / m n t / f l o p p y
P Narasimhan
-
7/31/2019 Linux Basics June2012
51/57
C H A P T E R - 6 : T H E V I E D I T O R
The VI editor is a screen-based editor used by many Unix users. The VI editor has
powerful features to aid programmers, but many beginning users avoid using Vi
because the different, complex features overwhelm them. It was created by a graduate
student of University of California, Berkley called William Joy.
Currently we will go through the basics of vi editor, avoiding the complex parts of it.
We will also browse through the At the end of this section editing vi editor should be
very simple.
Vi is a preferred choice of many advanced users, mainly because it is the only editor
available at the time of booting the system into a rescue mode.
The Three Modes
A vi session begins by invoking the command vi with or without a filename.
# v i t e x t f i l e
If the file exists then the contents of the file will be displayed, otherwise a blank
screen will be displayed. Of the 25 lines that can be displayed on the standard text
mode terminal, only 24 lines are used for displaying text. The last line is used for
displaying status information like, number of lines in the file, current position of the
cursor, name of the file etc.
The moment you start the vi editor, you will be placed in the so called command
mode. This is the mode where you can pass commands to act on the text. Pressing a
key does not appear on the screen, instead each key will be interpreted as a command
by the vi editor.
To enter text you have to switch to input mode. This can be done by pressing the key
'i'. While in input mode any key that is pressed on the keyboard will appear on the
screen. Most of the vi session will usually be spent in this mode.
P Narasimhan
-
7/31/2019 Linux Basics June2012
52/57
Sometimes you may have to switch to the third mode called as ex mode, where you
can enter instructions to act on the whole file.
For example file saving, file rewriting, find and replace operations are performed by
switching to this mode of operation.
To summarize the three modes we can write,
Input mode Where any key pressed is entered as text.
Command mode Where keys are used as commands to act on the text.
exMode Where ex mode commands can be entered in the last line of the screen
to act on text.
The command to quit out of VI is :q. Once in commandmode, type colon, and 'q',
followed by return. If your file has been modified in any way, the editor will warn
you of this, and not let you quit. To ignore this message, the command to quit out of
VI without saving is :q!. This lets you exit VI without saving any of the changes.
Of course, normally in an editor, you would want to save the changes you have made.
The command to save the contents of the editor is :w. You can combine the above
command with the quit command, or:wq. You can specify a different file name to
save to by specifying the name after the :w. For example, if you wanted to save the
file you were working as another filename called filename2, you would type: w
filename2 and return.
Another way to save your changes and exit out of VI is the ZZ command. When in
commandmode, type ZZ and it will do the equivalent of:wq. If any changes were
made to the file, it will be saved. This is the easiest way to leave the editor, with only
two keystrokes.
Some of the important commands that can be used in the command mode or ex mode
of vi are as follows:
:q! - Quit the current file and don't save the changes you just
made to the file
P Narasimhan
-
7/31/2019 Linux Basics June2012
53/57
CTRL +f - Page ahead,one page at a time.
CTRL + b - Page back , one page at a time.
G - Go to the last line of the file.
1G - Go to the first line of the file. (use any number to go to that line).
Some Simple VI Commands
Here is a simple set of commands to get a beginning VI user started. There are many
other convenient commands, which will be discussed in later sections.
a
enter insert mode, the characters typed in will be inserted after the current cursor
position. If you specify a count, all the text that had been inserted will be repeatedthat many times.
h
move the cursor to the left one character position.
i
enter insertmode, the characters typed in will be inserted before the current cursor
position. If you specify a count, all the text that had been inserted will be repeated
that many times.
j
move the cursor down one line.
k
move the cursor up one line.
l
move the cursor to the right one character position.
r
P Narasimhan
-
7/31/2019 Linux Basics June2012
54/57
replace one character under the cursor. Specify count to replace a number of
characters
u
undo the last change to the file. Typing u again will re-do the change.
x
delete character under the cursor. Countspecifies how many characters to delete. The
characters will be deleted after the cursor.
Cutting and Yanking
The command commonly used command for cutting is d. This command deletes text
from the file. The command is preceded by an optional count and followed by a
movement specification. If you double the command by typing dd, it deletes the
current line. Here are some combinations of these:
d^
deletes from current cursor position to the beginning of the line.
d$
deletes from current cursor position to the end of the line.
dw
deletes from current cursor position to the end of the word.
3dd
deletes three lines from current cursor position downwards.
There is also the y command which operates similarly to the d command which take
text from the file without deleting the text.
Pasting
The commands to paste are p and P. They only differ in the position relative to the
cursor where they paste. p pastes the specified or general buffer after the cursor
P Narasimhan
-
7/31/2019 Linux Basics June2012
55/57
position, while P pastes the specified or general buffer before the cursor position.
Specifying countbefore the paste command pastes text the specified number of times.
Inserting New Text
A
Append at the end of the current line.
I
Insert from the beginning of a line.
O
Enterinsertmode in a new line above the current cursor position.
a
Enter insert mode, the characters typed in will be inserted after the current cursor
position. A count inserts all the text that had been inserted that many times.
i
Enter insertmode, the characters typed in will be inserted before the current cursor
position. A count inserts all the text that had been inserted that many times.
o
Enterinsertmode in a new line below the current cursor position.
An online tutorial is available by default on Linux systems. The default location of
the file is /usr/share/vim/vim64/tutor/tutor. The tutorial can be accessed by executing
the command vimtutor.
P Narasimhan
-
7/31/2019 Linux Basics June2012
56/57
emacs is another popular versatile utility for Unix platforms developed by Richard
Stallman. This application can be used not only as an editor but also as a browser.
This is popular among the user groups.
P Narasimhan
-
7/31/2019 Linux Basics June2012
57/57
GUI Editors
xemacs is the GUI eqvivalent of emacs in TUI. The editor is accessible on the GUI
with the name xemacs. It can be invoked by going to K Menu -> Run Command ->
xemacs
nedit is another GUI editor available which can be used to edit text files.
gvim:This particular editor is accessible on the GNOME'S desktop. The editor in
turn uses the vi improved editor at the back-end and saves the data which are in the
text formats.
gedit: Another editor on the GNOME's desktop with a feature of opening multiple
files in a single session. This is useful in case the user wants to work on the project
involving editing of multiple files at a time.
K A T E: TH I SI S Y E TA N O T H E R P O P U L A R T E X T E D I T O R . TH E YA R E
A V A I L A B L E O N K D E D E S K T O P S B Y D E F A U L T. A P R E V I E W O F
K E D I TI S G I V E N I N T H EN E X TP A G E.