Linux Guide
- Linux OS
- File System
- Processes
- Programming Languages
- XWindows
- Gnome
- Games
- Networking
- bash
- Shell Programming
I.
The Linux OS
a.
History of Linux
Linux was developed in the late 1980s by Linus Torvalds, a Finnish student
who could not
afford a Unix machine. He developed Linux as a
free clone of Unix, with an open source model of source code so that
other poor students like him would be able to have an OS.
Over time, several several variants of Linux have developed, all of
which are available for free download via their websites :
- Red Hat
(http://www.redhat.com) :
Beginners' linux.
- SuSE
(http://www.suse.com) : For Business Users,
includes several accounting packages.
- Slackware,
(http://www.slackware.org) :
The open-source slackware.
- Caldera
(http://www.caldera.com)
- BSD (Berkely Software Distribution)
(http://www.bsd.org, http://www.freebsd.org)
Several varieties of Unix exist, including
IBM AIX, Sun Solaris OS,
HP-UX, etc.
b.
Advantages of Linux
- Free :
Linux is available at no cost for downloading from
the Internet.
Compare that
with Windows NT,
which lists for $149 per workstation upgrade and $439
per server with 10
client licenses.
[Information Week, January 24, 2000]
- Fewer Bugs :
Open-Source Scrutiny leads to
constant Peer Review and early elimination of bugs and robustness
- Stability: Linux OS is stable, greatly reducing the
possibility of system crashes
and server downtime.
In a study by Gartner Datapro, Linux ranked higher
than
Windows NT and all commercial Unix OSs in customer
satisfaction.
[ Computer User, Dec. 2000 ]
-
Scalable: It's inherently scalable, suitable for CPU-intensive
database
applications as well as
straightforward Web serving.
-
Flexible:
It's flexible, allowing developers to obtain the optimum blend
of hardware and software components to serve up an ad
banner, or safeguard customer
data.
- Industry Backing : Several big companies have
started backing linux, including
Dell, Compaq, and IBM.
IBM may even create an open-source `Blue Linux'
c.
OS Holy War
Linux and Unix dominate the server market :
|
O/S
|
Server Market Share
|
Windows NT
|
36 %
|
Linux
|
24 %
|
NetWare
|
19 %
|
Unix
|
15 %
|
Host/Server
|
3 %
|
Other
|
3 %
|
Table: Server Market 1999 (5.7 million shipments)
IDC, IT Forecaster, August 8, 2000
|
As per ComputerUser.com,
"Linux is the leading choice for Web deployment,
powering 30 percent of all public Web sites, according
to a study conducted last May [1999] by
Netcraft, Inc.."
Google is powered by linux servers:
"Google, based in Mountain View, Calif., relies on more that 4,000 Apache
Web
servers running Linux to drive its wildly
successful search engine technology,
incorporated into the Net initiatives of companies
like Palm Inc., Cisco Systems,
Hungry Minds.com, and the Washington Post."
"Free shall make you free" was the clarion call of the original Web,
Torvalds and other open-source pioneers such as Richard
Stallman of the GNU project and Jon
"maddog" Hall--currently executive director of Linux
International--heard that message, tirelessly
promoting it in the burgeoning Web
community.
2000
|
2003 (projected)
|
O/S
|
Machines
|
O/S
|
Machines
|
Linux
|
15 million
|
Linux
|
30 million
|
Unix
|
4.5 million
|
Unix
|
4.8 million
|
Table: User Base
`Unix vs. Linux,'
Dan Blacharski, Computer User, Dec. 2000 (IDC)
Linux is thus outpacing Unix, and is arising as a serious competitor to
Microsoft in the client desktop programming market.
By comparison,
NT user base is 2 - 4 million
and the
Mac user base is 22 million
50 million units of Windows 3.1 and 3.11 have been
installed as per microsoft.com.
Prior to Win 95 launch [ 1995 ], there was a user base of
50 million Win 3.x users
|
O/S
|
Client Market Share
|
MicroSoft
|
87.7 %
|
Linux
|
4.1 %
|
Mac OS
|
5.0 %
|
Other
|
3.8 %
|
Table: Client/Desktop Market (98.8 million shipments)
IDC, Press Release 07/17/00
|
Linux has been branded as the number one threat to
Microsoft's dominance of the client market. An `OS Holy War'
has thus broken out.
The OS Holy War on Rediff,
http://www.rediff.com/computer/dgos.htm
d.
Restricted User Priveleges
Linux does not give all users the same priveleges.
Users only have access to their own files,
while certain group members have access to group files;
the root or superuser has priveleged access to all files.
Thus, the spread of viruses is inhibited.
Users should choose difficult to choose passwords, which are not
dictionary words and including
special characters.
Login is accomplished by entering a valid user name and password.
Commands in Linux have command-line options (preceded by a -).
Basic User commands: Try these basic commands after logging in:
- $ who
- $ date
- $ passwd
- $ exit
Further information about a particular command can be
obtained from the in-built system manuals :
- $ man who
- $ info who
- $ who -h
- $ who --help
- $ apropos who
II.
File System
a.
Editing Files
- pico (`pico')
[ simple file editor with few commands ]
- Commands
^X (`eXit' :save and exit)
^J (`justify' :format paragraphs)
^T (`thesaurus' :spell checker)
^O (`out' :write to specified output file)
- Examples
-
$pico f.txt
(edit file f.txt)
- pilot (`pilot')
[ file browser program used with pico ]
- Examples
-
$pilot .
(view present dir)
- vi (`vi')
[ advanced file editor ]
- Modes: vi has two modes: command mode
(entered via `ESC` and
edit mode (entered into by typing `i`)
- Command Mode
:q! (`quit' :quit without saving)
:w (`write' :write)
:wq (`write and quit' :write and quit)
:%s/world/Globe/g (`search' :global search and replace)
- Examples
-
$pico f.txt
(edit file f.txt)
b.
Listing and Viewing Files
- ls (`list')
[ lists contents of a directory ]
- Options
-a (`all' :display all files, including dot files)
-l (`long' :long listing)
-R (`recursive' :listing of subdirectories)
-t (`time' :sorted by modification time)
- Examples
-
$ls -la
(long listing of all files)
-
$ls -lR | less
(long listing of subdirectories piped to less)
-
$ls --color
(list in color; defaults changed by
LS_COLORS=*.tex=1:*.html=34:*.txt=35; export LS_COLORS
which can also be set via dircolors)
- cat (`concatenate')
[ append files and print to output ]
- tac (`reverse concatenate')
[ concatenate and write files in reverse ]
- Options
-r (`regex' :treat separator as regular expression)
- Examples
-
$tac f.txt
(display file in reverse)
- head (`head')
[ output the first part of file, first 10 lines by default ]
- Options
-c N (`char' :print first N characters)
- Examples
-
$head -c 5 f.txt
(display first 5 characters of file)
- tail (`tail')
[ output the last part of file, last 10 lines by default ]
- Options
-n N (`number' :display last N lines)
- Examples
-
$tail -5 f.txt
(or $tail -n 5 f.txt )
(display last 5 lines of file)
- wc (`word count')
[ count words in a file ]
- Options
-w (`words')
-l (`lines')
-c (`characters')
- Examples
-
$wc f.txt
(count lines, words and characters of file f.txt)
-
$wc -w f.txt
(or
$wc --words f.txt )
(count words in a file)
-
$wc -c f.txt
(or
$wc --chars f.txt )
(count characters in a file)
- more (`more')
[ pagewise text-viewing program, deprecated in favour of less ]
- Options
-n (`number' :display n rows)
- Commands
SPACE (`forward') display next screenful
b or ^B (`back') back one screenful
- Examples
-
$more -25 f.txt
(display 25 rows of file at a time)
- less (`less is not less than
more')
[ pagewise text-viewing program ]
- Options
- Commands
SPACE (`forward') display next screenful
b or ^B (`back') back one screenful
f or ^F (`forward') forward one screenful
- Examples
-
$less f.txt
(standard usage)
- cp (`copy')
- Examples
-
$cp f1.txt f2.txt
(copy file f1.txt onto f2.txt)
-
$cp ../dir/f.txt .
(copy file f.txt in a directory dir under the superdirectory
to the present dir `.`)
- mv (`move')
- Examples
-
$mv f1.txt f2.txt
(standard usage)
-
$mv dir1 dir2
(move directory dir1 into directory dir2)
-
$mv f1.txt ~/dir/subdir
(move file to a subdirectory subdir in a
directory called dir in the home directory)
- rm (`remove')
- Examples
-
$rm f.txt
(remove file f.txt)
-
$rm *
(remove all files)
-
$rm -i *.temp
(interactively remove all files ending in .temp, prompting
user)
-
$rm *.d??
(erase all files having a three-lettered suffix
followed by two characters)
-
$rm -r cache/
(recursively remove all files and subdirectories
of a directory called cache)
c.
Formatting Files
- nl (`number lines')
- Options
-b style(`body numbering' :numbering style, style types
include `a' (number all lines),
`pREGEXP' (number only lines that contain a match for REGEXP), etc.
-i number (`increment')
-n format (`number format' :format is ln, rn or rz)
- Examples
-
$nl f.txt
(number lines)
-
$nl -i 5 f.txt
(number lines with increment 5)
-
$nl -n rn f.txt
(number lines right-aligned)
- fmt (`format')
- Options
-w n (`width')
-u (`uniform spacing')
- Examples
-
$fmt -w 20 f.txt
(or
$fmt --width=20 f.txt )
(width 20)
-
$fmt -u f.txt
(uniform spacing)
- $fmt is equivalent to resizing the Xwindow
in pico and using ^L
d.
Directories
- cd (`change directory')
- Examples
-
$cd mydir
(go to directory dir)
-
$cd
(return to home directory)
-
$cd ..
(up one directory)
-
$cd /usr/local/bin
(using fully qualified path names)
- mkdir (`make directory')
- Options
- Examples
-
$mkdir d
(make directory d)
-
$mkdir -m 700 d
(close new directory for all other users)
- rmdir (`remove directory')
[ remove directory if empty ]
- Examples
-
$rmdir d
(remove directory d)
- df (`disk filesystem usage')
[ reports the amount of disk space used and available on
filesystems in units of 1024 bytes]
- Examples
-
$df
(show usage)
-
$df -m
(show usage in MB)
- du (`disk usage')
[ reports the disk space for the current or specified
directory in units of 1024 bytes]
- Options
-a (`all' :show counts for all files, not just directories)
-k (`kilobytes' :display size in kilobytes)
-m (`megabytes' :display size in megabytes)
- Examples
-
$du
(show directory usage)
-
$du -ak
(show directory and all file sizes in kB)
- pwd
(`present working directory')
- Examples
-
$pwd
(show current directory)
e.
Finding and Searching Files
- find (`find file')
- Examples
-
$find . -name '*.txt'
(search current directory tree for files ending in txt)
-
$find . -size +30k
(search current directory tree for files larger than 30k)
-
$find . -type f -print |xargs grep train
(find files containing string train)
-
$info find
(more information on find)
- grep (`grep')
[ search for lines matching a pattern ]
- Options
-i (`ignore case' :ignore case in the pattern)
-r (`recursive searoh' :search all files in a directory
and its subdirectories)
- Examples
-
$grep myword *.txt
(search all files ending in txt for myword)
-
$grep -e '-some' *.???
(search all files with a three letters suffix for -some)
-
$ grep -ri Samar mydir|less
(search all files in mydir and subdirectories for
string Samar, ignoring case, piping output to less)
- xargs (`execute arguments')
[ execute command lines from standard input ]
- Examples
-
$ find . -name '*.txt' | xargs grep myword
(find all files in full directory tree ending in text,
piping the output to a match for myword)
- spell (`check spelling')
[ verify spelling ]
- Several different varieties of spell checkers exist,
such as :
-
$ spell f.txt
(lists wrong words only without correcting the original file;
this is linux aspell script mimicking the original
Unix spell)
-
$ ispell f.txt
(interactive spell checker, user simply enters number of
closest choice from matched words, `quit' to quit)
-
$ aspell -c f.txt or
$ aspell check f.txt
(linux spell checker)
-
$ aspell --help | less
(linux spell checker help)
f.
File Permissions
- chmod (`change mode')
[ change permissions ]
- Examples
-
$chmod 744 *.txt
(change permission for global read access)
- chgrp (`change group')
[ change permissions ]
- umask (`user mask')
[ set the digits to be subtracted from
full permission set ]
g.
Compressing Files
- gzip (`gzip')
[ compress files using Lempel-Ziv
coding (LZ77) ]
- Options
-d (`decompress' :same as $gunzip)
-r (`recursive' :descend into subdirectories)
- Examples
-
$gzip -9 *.txt
(ultra-compression in maximum time)
-
$gunzip *.gz
(uncompress all gzipped files)
-
$ cat file1 file2 | gzip > foo.gz
(concatenate files and then compress)
- zip (`zip')
[ compress files in a format compatible with
PKZIP (Phil Katz's ZIP for MSDOS systems) ]
- Examples
-
$zip z.zip *.txt
(zip all txt files into a file called z.zip)
-
$unzip z.zip
(unzip the given file)
- tar (`tape archive')
- Options
-c (`create')
-v (`verbose')
-f (`file' :use archival file name)
- Examples
-
$tar -cvf t.tar *.jpg
(create tar file containing all jpeg images)
-
$tar -tvf t.tar
(verbosely tabulate the contents of the tar file)
-
$tar -xvf t.tar
(verbosely extract the contents of the tar file)
- compress (`compress')
h.
Root File System
Directory
|
Purpose
|
/
|
Root Directory
|
/home
|
Holds Users' Home directories, in many LINUX systems this
is /usr, /users or /u
|
/bin
|
Binaries Directory, containing files that are executable which
only computers could understand.
|
/usr
|
Holds user-oriented directories
|
/usr/bin
|
User-oriented Linux programs
|
/var
|
Subdirectories:
mail holds mail files, spool
holds files to be printed, and uucp holds files
copied between Linux machines.
|
/dev
|
Device Files.
These are special files that serve as gateways to
physical computer components.
|
/etc
|
Etcetera: Linux Configuration Files.
|
/sbin
|
System Binaries usually run automatically by the Linux system.
|
III.
Processes
a.
Process Commands
- ps (`process status')
[ display processes ]
- Options
-e (`everything')
-u (`user' :display user's processes)
-f (`full')
- Examples
-
$ps
(display processes using default settings)
-
$ps -ef | less
(write all processes)
-
$ps -u samar
(show samar's processes)
- sleep (`sleep')
[ delay for a specified amount of seconds ]
- Examples
-
$sleep 10
(suspend for 10 seconds)
-
$sleep 100 &
(suspend and place in background)
-
$ps -u samar
(show samar's processes)
- kill (`kill')
[ terminate a process ]
- Examples
-
$kill -2 27645
(terminate process ID 27645, which can be obtained from
$ps)
-
$kill -9 103
(definitely kill process ID 103)
- at (`at')
[ execute process at specified time ]
- Examples
-
$at 11:53 < mpeg.ftp
(execute commands given in a text file mpeg.ftp:)
mpeg.ftp
|
ftp mm-ftp.cs.berkeley.edu > log
anonymous
abbas@
lcd /user2/abbas/bin/
cd pub/mpeg/play/
bin
get mpeg_play-linux-elf.tar.gz
bye
|
-
$atq
(at queue:show list of at jobs after executing at)
-
$atrm 4
(remove job in at queue)
-
$at 12:30
at> date
at> who
at> <^D>
(execute using simple date format)
- crontab (`cron table')
[ edit crontab file ]
- top (`show all processes')
[ show all processes ]
IV.
Programming Languages
a.
Compilers
- perl
(`practical extraction and reporting language')
[ language ]
-
$perl p.pl
(perl compiler)
- java
(`java')
[ programming language ]
-
$javac f.java
(java compiler)
-
$java f
(java virtual machine)
- C
(`C')
[ programming language ]
-
$cc f.c
(C compiler)
-
$gcc f.c
(GNU C and C++ Compiler)
- Fortran
(`Formula Translation')
[ programming language ]
-
$f77 p.f
(Fortran 77 compiler)
-
$f90 p.f or
$fort90 p.f
(Fortran 90 Compiler)
b.
Mathematical Aids
- bc
(`best calculator')
[ arbitrary precision calculator using
scale, the number of decimal digits ]
-
$bc
scale=4
2/3
0.6666
quit
- dc
(`desk calculator')
[ arbitrary precision calculator ]
V.
X Windows
a.
Initialization
-
~/.xinitrc (`x initialization file')
[ init file ]
-
~/.Xresources (`x resources')
[ init file ]
- Default: /etc/X11/xinit/xinitrc
b.
Commands
- startx (`start x windows')
[ start command ]
- xterm (`x terminal')
[ new terminal ]
-
$xterm &
(new x terminal)
-
$xterm -g 80x24+0+0 -name "Samar Abbas"&
(new x terminal at 0,0,
80 digits wide, 24 lines high named as given)
- xsetroot (`set background')
[ change bg color ]
-
$xsetroot -solid gray
(sets background)
- xclock (`x clock')
[ clock ]
-
$xclock -geometry 80x80 &
(displays clock)
- animate (`animate')
[ display series of images ]
-
$animate f*.jpg
(display images)
Games which can be started from the
command prompt in xwindows: xevil, xdino, battlestar, atc,
trek, robots, worm, doom, etc.
cf. /usr/x11/bin
Desktop can be changed using
Gnome Footprint | Programs | System | Desktop Switching Tool.
To make the Taskbar visible, please click on the K
Menu icon on the K Panel. Next, click on Settings >
Applications > Panel. Then in the K Panel
Configuration pop-up box, please move the dot under
Taskbar from Hidden to Bottom by clicking on Bottom.
Please see Figure 4 (above) and Figure 5 (below).
VI.
Gnome
x.
AbiWord
( MS Word clone )
- Download :
http://www.abisource.com/free.phtml
- Starting :
Click on AbiWord logo in menu.
- Features
x.
GIMP
(`gnome image manipulation program',
a free replacement of Adobe Photoshop )
- Download :
http://www.gimp.org/download.html ;
not necessary with Red Hat Linux 7+ as already installed.
- Starting :
Footprint | Programs | raphics | The GIMP
- Features
- Full suite of painting tools including Brush, Pencil, Airbrush,
Clone, etc.
- Converts images to various formats
x.
Gnome-DB
(`gnome database')
- Download :
http://www.gnome-db.org/download.php
- Starting :
Click on Gnome-DB logo in menu.
- Features
- Supports multiple database backends, including Postgresql, Mysql,
Oracle, ODBC, Sybase
x.
Guppi
(`graphing and plotting program')
- Download :
http://www.gnome.org/guppi/
- Starting :
Click on Guppi logo in menu.
- Features
x.
Dia
(`Diagram')
- Download :
http://www.gnome.org/gnome-office/dia.shtml
- Starting :
Click on Dia logo in menu.
- Features
- Support for flow charts, structure diagrams, etc...
x.
OpenWriter
(OpenOffice
wordprocessor.)
Sun
is integrating their OpenOffice Suite with GNOME, which means all
the applications of OpenOffice will become part of
GNOME Office.
- Download :
sw.openoffice.org
- Starting :
Click on Open Office logo.
- Features
- Full word processor
- Handles MS Word 95, 97, 2000
x.
StarOffice
(`Sun Office suite')
- Download :
http://www.sun.com/products/staroffice/get.html
- Starting :
Click on Star Office logo.
- Features
VII.
Games
Not all of these games may be present on the particular
linux installation, all however can be downloaded for free
from various websites.
a.
Adventure and Text Games
- battlestar :
/usr/games/battlestar
(space adventure game)
- paranoia :
/usr/games/paranoia
(spy adventure game)
b.
War Games
- doom
(`full graphics war grame')
[ arbitrary precision calculator using
scale, the number of decimal digits ]
- xevil
c.
Board Games
- xcarrom
(`carrom')
- gnuchess (graphical) :
/usr/bin/xboard
(graphical chess game for x windows)
- gnuchess (text) :
/usr/bin/gnuchess
(character-based chess game)
d.
Video Games
- xbill :
Start | Programs | Games
(destroy an evil hacker)
- xeyes :
Start | Programs | Games
(big eyes)
e.
Card Games
VIII.
Networking
a.
E-Mail
- pine (`pine')
[ simple e-mail program ]
- Commands (virtually identical to pico)
^X (`exit' :send a message)
^J (`justify' :format paragraphs)
^T (`thesaurus' :spell check)
- Examples
- mail (`send mail')
[ command-line email ]
- Examples
-
$mail
(view mail, use v 12 to view message no. 12)
-
$mailx
(extended mail program available on some systems)
-
$mail dcswain@hotmail.com
(send mail to given address)
-
$mail -s "hello samar" abbas@samarstan < f.txt
(send mail with given subject, using f.txt as body;
useful for shell scripting)
-
~/.forward
(file used for forwarding emails)
-
~/.mailrc
(mail configuration file)
- elm (`elm')
[ elm ]
b.
Chatting
- write (`write letter')
[ chat to a user logged in ]
- Examples
-
$write saroj
whence saroj must reply
$write samar
-
$write samar tty03
(write samar on terminal tty03)
-
$write santosh@venus.xly.com
(write across the internet)
- Conditions
- Login: User must be logged in.
- Permission: User must have granted talk permission:
$mesg y
.Entering
$mesg n disables all input.
- wall (`write all')
[ broadcast message to all users ]
- Examples
-
$wall "Hello from Samar Abbas"
-
$write santosh@venus.xly.com
(write across the internet)
- Conditions
- Login: User must be logged in.
- Permission: User must have granted talk permission:
$mesg y
Entering
$mesg n disables all input.
- On some systems, only root can send a wall message
usually stored in /etc/wall
- finger (`finger user')
[ find out info about user ]
- Examples
-
$finger samar
-
$finger abbas@unix.mit.edu
(finger across the internet)
-
~/.plan : file executed by finger
- talk (`talk')
[ chatting program ]
- Examples
-
$talk samar@webtech.com
(talk to samar across internet)
- Conditions
- Login: User must be logged in.
- Permission: User must have granted talk permission:
$mesg y
Entering
$mesg n disables all input.
- talkd (talk daemon) must be running under the superserver
daemon, ,
cf file /etc/inetd.conf.
c.
Telnet
To telnet to another machine, use the hostname
$telnet mars or the IP address,
$telnet 198.100.11.15
and then supply required username and password.
Use netstat to check on network peroformance.
d.
ftp
To use ftp services use the hostname
$ftp venus.ensindia.com
or use the IP address
$ftp 198.100.11.15, supplying required username and password.
The following commands are used to retrieve files:
- > get f.txt
- > put f.txt
- > mput *
e.
www
- netscape (`internet scape')
[ graphical web browser ]
- Running Netscape:
-
$startx
(start x mode, not necessary if window mode running)
-
$netscape
(or click on Netscape logo)
- lynx (`links')
[ fast text browser ]
- Examples
-
$lynx http://www.google.com
(works for direct internet connection)
-
$lynx .
(browse home dir)
-
$lynx -source http://www.ibm.com/index.html > new.html &
(download file in background)
-
$http_proxy ="http://some.server.dom:port/"
$export http_proxy
(proxy server settings,
other variables are ftp_proxy, gopher_proxy, then use)
$lynx http://www.google.com
- Commands
f.
Other Commands: rlogin, ping, traceroute
- ping (`ping pong')
[ send ICMP ECHO_REQUEST packets to network hosts ]
- Examples
-
$ping 198.100.11.14
(test connection to given host)
-
$ping mars.venus.com
(ping using hostname)
- traceroute (`draw route')
[ print the route packets take to network host ]
- Examples
-
$ /usr/sbin/traceroute 198.100.11.14
-
$ /usr/sbin/traceroute hotmail.com
(find route across network)
- rlogin (`remote login')
[ login to a remote host ]
- Examples
-
$ rlogin 198.100.11.14
(remote login)
-
$ rlogin -l user mars
(remote login)
IX.
bash (Bourne Again Shell)
Definition of Shell : -
Program layer providing a
human interface point and user environment for communication with the
Linux kernel
|
a.
Features of bash
- Command-Line Completion : bash can automatically
complete the command-line via the TAB key, eg.
$pi<TAB><TAB> displays alll possible commands beginning
with 'pi', while entering
$pico f<TAB> either completes the name of the
file, or displays all files beginning with f.
- Command History :
bash keeps track of a certain number of previous
commands that have been entered into the shell. The number of commands is
given by a shell variable called
HISTSIZE in a default file ~/.bash_history
set using the HISTFILE bash variable. The up- and down-arrow keys
scroll through the
commands that have been previously entered.
-
$history
- displays entire history file
-
$history 10
- displays last 10 commands
-
$cat ~/.bash_history
- displays entire history file
- Command Aliasing : bash supports the ability
to give nicknames to longer commands.
-
$alias ll="ls -l"
- alias ll to long listing
-
$alias copy='cp'
- alias copy to cp
-
$unalias mycommand
- unalias mycommand
-
$alias
- display all aliases
- IO Redirection : bash permits input and output to
be redirected from the standard output (ie.the monitor).
-
$ls -lR > l.txt
- rediret output to a file
-
$ls -lR | less
- pipe listing to less fileviewing program
- Job Control : bash provides job control
via the $fg and $bg and ^Z commands.
b.
Shell Initialization and De-Initialization
- /etc/profile is the default initialization file.
- ~/.bash_profile
~/.bash_login
~/.profile (bash searches for
the first of these files and executes them;
~/.bashrc is often made to point to any of these
so as to permit non-interactive login initialization)
- ~/.bash_logout
(executed on logout)
- ~/.bashrc(subshell or non-login shell initialization file)
c.
Shell Environment Variables
Using $export
causes the value of a variable to be made visible to all subprocesses that
belong to the
current shell.
- PS1 (`prompt symbol')
[ First user prompt ],
bash has two levels of user prompt. The first level
(default $) is what you see when
bash is waiting for a command to be
typed, The second level of prompt is displayed when bash is expecting more
input from you in order to complete a
command. The default for the second level prompt is >.
eg.
-
PS1=" Are You Samar ? "
- changes prompt to given text string, ie.
Are You Samar ?
-
PS1="Time: \t * "
- changes prompt to given time, ie.
Time: 11:51:58 *
-
PS2="\u % "
- changes second-level prompt to user login with percent symbol,
ie.
abbas %
-
PS1="\u@\h # "
- changes prompt to user login with percent symbol, ie.
abbas@venus #
-
PS1="`hostname`:`pwd`> "
- changes prompt to user login with percent symbol, ie.
abbas@venus #
-
PS1="\h:\w $ "; export PS1
- changes prompt to hostname and
working directory and export the value mars:~/dir $
-
PROMPT_COMMAND=/usr/games/fortune; export PROMPT_COMMAND
- sets prompt command
and exports it to subshells
Character
|
Meaning
|
\!
|
Displays the history number of this command.
|
\#
|
Displays the command number of the current command.
|
\$
|
Displays a $ in the prompt unless the user is root. When the user is root,
it displays a #.
|
\\
|
Displays a backslash.
|
\d
|
Displays the current date.
|
\h
|
Displays the host name of the computer on which the shell is
running.
|
\n
|
Prints a newline character. This will cause the prompt to span more than
one line.
|
\nnn
|
Displays the character that corresponds to the octal value of the number
nnn.
|
\s
|
The name of the shell that is running.
|
\t
|
Displays the current time.
|
\u
|
Displays the username of the current user.
|
\W
|
Displays the base name of the current working directory.
|
\w
|
Displays the current working directory.
|
Table: Prompt special character
codes.
Source: Red Hat Linux Unleashed, Ch.10
- TERM (`terminal')
-
TERM = xterm; export TERM
- sets the terminal to standard x terminal
-
TERM = vt220; export TERM
- sets the terminal to vt220 emulation
- TMOUT (`timeout')
[ Idle time before automatic logout ]
-
unset TMOUT
- unset time out.
d.
Shell Meta-Characters
The following are shell meta-characters, also known as
wildcards:
- * - match any character and any number of characters
- ? - match any single character
- $ ls *.???
(list files ending in three characters)
- [] - matches any single character contained within the brackets.
The following are important shell symbols:
- > - write to another output
- > > - append to output
- < - read from input
- | - pipe output from one command to another
- & - place command in the background, eg.
- $ sleep 10 &
$ ps
(place sleep process in background and view the process status)
- ; - execute several commands successively, eg.
X.
Shell Programming
a.
Basic Shell Scripts
- Write the Shell Progam using an editor like pico or vi:
hello.sh
|
echo "Hello World"
echo "From Samarstan"
|
- Execute Permission is to be granted :
$chmod 755 hello.sh
if this is not done,
"Permission denied" will be echoed once the script is executed.
- Execution of the Shell Script : Execute the
script as if it were a command, giving its full path name, eg.
$./hello.sh
where ./ refers to the present directory,
or
$bash hello.sh
or
$"`pwd`/hello.sh"
where pwd returns the present working
directory,
or
$set `pwd`=$PWD; $PWD/hello.sh
or
$ ~/dir/subdir/hello.sh using the
full path name.
In all cases, you should see "Hello World From Samarstan"
printed to the screen.
basic.sh
|
#! /bin/bash
who
echo '******************'
ls
echo "******************"
# This is a comment
ps
echo '******************'
|
It is often customary to write the
shell at the top of the script, as in
#! /bin/bash , and
# lines are comments.
b.
Quotation Marks
The double quotation marks (""), the
single quotation marks (''), and the backslash (\) are all used to hide
special
characters from the shell.
- " " (double quotes) the least powerful for hiding
special characters from the shell
- ' ' (single quotes) the most powerful for hiding
special characters from the shell
- \ (backslash) hides special characters as well
- ` ` (backquotes, on upper left hand corner of keyboard)
are used when results of a command are to be used in another command.
logname.sh
|
echo '******************'
echo "hello $LOGNAME"
echo "******************"
|
Note that using echo 'hello $LOGNAME'
would not work, returning "hello there $LOGNAME" as
the single quotes would hide the variable from the shell.
c.
Variables
d.
Conditional Statements
References
- The Holy War
http://www.rediff.com/computer/dgos.htm
(source of the Holy War logo)
- OS Holy Wars,
http://www.internetwk.com/reviews/rev0901.htm
- Microsoft's Holy War on Java,
http://www.slashdot.org/articles/98/09/23/165217.shtml
- Spreading the Gospel,
http://www.haverford.edu/publications/summer99/linux.htm
- Replacing Windows NT with Lnux
http://citv.unl.edu/linux/LinuxPresentation.html
-
Information Week, January 24, 2000
http://www.informationweek.com/770/linuxOS.htm