Professional Documents
Culture Documents
1 ***********************/
Log in: ~
When you startup your system, the very first line that you see on your monitor is
Login:
This line means that the UNIX system is ready for you to login. Each user is given a
login name, also referred as user id. After entering your login name to the login:
prompt, the UNIX system prompts you to enter the password as:
Password:
Now you have to enter your password. Like user id, each user is given a unique
password. It is your password that allows you to use this user id. Your password
may be selected either by system administrator or by you. In either case, it is the
password by which the system recognizes that you are an authorized user to use this
user id. After accepting the correct login name and password some kind of welcome
message is printed on the screen. For example:
Login: User 1
Password: punit
Mon Oct 11 07:10:10
ISP 1999
*** Good Morning ***
This means it is ready to accept your command. The command prompt is $, if you are
working in Bourne Shell or a % if it is a C shell.
Log Out: ~
To end a UNIX session, you must log out. You should not end a session by just
turning off your terminal! To log out, enter the command exit. (In many cases, the
command logout will also work.) Depending on your shell, you may also be able to
log out by typing [CTRL-D].
What happens next depends on the place from which you've logged in:
Simple commands:
(1)
(2)
(3)
(4)
(5)
The cp command: ~
Such command is used to copy the content of one file into another file. The
command statement is given below:
$ cp source_file target_file
Here the first argument source_file is the name of the file to be copied and the
second argument target_file is the name of the file to pace the copy content
into.
(6)
The mv command: ~
Such command is used to rename a file. Suppose you want to rename the file
old_letter to new_letter, you would use the mv command as:
$ mv old_letter new_letter
(7)
The rm command: ~
Such command is used to remove a file. The command is used as follow:
$ rm filename
(8)
(9)
(10)
The ls command: ~
The ls command displays the contents of a directory. If your directory has
some files will be displayed typically one per line as:
$ ls
Amit
Punit
Ajay
$
(11)
The cd command: ~
Such command is used to change the directory. Suppose you are working in
/user2 directory and you want to change the directory to /user2/punit, so it can
be done as
$ pwd
/user2
$ cd punit
/user2/punit
(12)
(13)
(14)
vi Editing Modes : ~
The vi editor works in three different modes:
(i)
(ii)
(iii)
command line. The vi editor uses the command line to display messages
and commands. Enter key is pressed to execute the subcommand or
interrupt (Ctrl c) key to cancel it.
Introduction to vi editor: ~
The vi editor is invoked by executing, just like any other UNIX command, along with
the filename as:
$ vi filename
After typing this and pressing Enter key, the contents of the specified file are stored
into the edit buffer, the terminal screen is cleared, a window is displayed in which you
can enter and edit text, and the cursor is initially set at the first character of first line in
the window.
Suppose you would like to create a file punit then invoke the vi editor as:
$ vi punit
it clears you previous contents of the screen and displays a window as shown in
figure.
~
~
~
~
~
punit
Except the first line and the last line, the window shows a character ~ (tilde), the
symbol of empty line. The first line has an underscore (_) in the first colon that waits
for a command to entered by you.
By default the vi editor is placed in command mode and thats why it waits for you to
enter a command. If you want to insert text to the file punit then press i key to
enter the insert mode of vi. When you press the i key, it is not displayed on the screen.
Now you can enter the text whatever you want to insert in figure.
Punit Sharma
Mukesh kumar
Ajay kumar
~
~
punit 3 lines and 31 characters
After typing these names, press the Esc key to return the command mode from the
current mode.
Editing a file: ~
If you want to edit a file then it is necessary to load the file form a disk into buffer and
then move to the part of the file you want to edit. And it is achieved as:
$ vi punit
The vi program will clear your screen and fills it with file you are editing as shown in
fig.
The cursor is placed at first character of the first line. You can move the cursor by
using the different commands.
Punit Sharma
Mukesh kumar
Ajay kumar
~
~
punit 3 lines and 31 characters
These commands are displayed on the screen. The current window screen contains
only the contents of the file. After placing the cursor to the right position you can edit
the file. Unfortunately if you see these commands on the screen then it means that you
are still in insert mode. Therefore, firstly press Esc key to return back to command
prompt and then try these motion commands again. You can also proceed h, j, k, l
command with numbers that allows you to move the cursor a corresponding number
of spaces or lines. Let you want to move 4 lines down then either press j four times or
just type 4j.
some other commands that help in positioning the cursor :
Backspace
Spacebar
$
+
Enter
Adding Text: ~
The first thing you have to do is that place the cursor at position where you want to
add and then press a. the a stands for append. Now whatever you will type is
appended to the text buffer after the current cursor position.
Now when you press Esc key, the cursor returns back to the last character you
entered. It tells you that you are no longer in insert mode.
The vi editor provides another command i command that works similar to a
command. The only difference between the a and i command is that it inserts the
new characters before the current cursor position. Therefore after pressing i
whatever you type, it will be added to the left of the characters on which your cursor
is placed
Deleting Text: ~
The vi editor provides two commands, x and dd, that delete text. If you want to
delete a character then firstly place the cursor at the appropriate position . and, then
press x key. After pressing x, the character at the current cursor position will
disappear and the rest of the line would be moved one position left side.
If you want to delete the 4 characters of a line then just type 4x, this delete the four
characters of the current line and move the line to the left side.
Whereas dd command is used to delete the complete line. You can also used
numbering with dd command. E.g if you want to delete 3 lines, then just press 3dd,
it will delete the 3 lines of the files.
Undo command: ~
UNIX also provide undo command. For this we use character u. suppose after
deleting three lines, you think that you had to delete one line only instead of three
lines then use an u command to get back the most recently deleted lines.
Overwriting Text: ~
The vi editor provides a R command to overwrite the existing contents of a file.
Therefore, whenever you want to overwrite, place the cursor at that special position
and then press R. Now whatever you type next would be overwritten the existing text
at the current cursor position.
Saving a file: ~
The vi editor also provides the ZZ command to save all the changes that you make
to the file and quit. This command is used in command mode.
Scrolling command: ~
Scrolling is the property of a video terminal that makes the top line to leave the screen
as each new line is displayed at the bottom. The vi editor provide following command
for scrolling purpose
Ctrl U
Ctrl D
Ctrl F
Ctrl B
Block Commands: ~
The commands that we have discussed so far deals with a single character, single
word or a single line. The vi editor provides block commands to work on a group of
lines rather that on a single line. For example, we may copy a group of lines from one
part of a file to another part, delete a group of lines from a file by using a single
command. The block command are used to work in ex command mode only. Although
it is not necessary to associate line numbers with the text because block commands
work on line number on which they are supposed to operate.
For example you have a file that contain 20 lines and you want to delete lines from 6
to 10, then you use the command;
6, 10d
Such command delete the 6 to 10 lines.
The vi editor provides a command set number or set nu in the ex command mode
that enables you to display line number. Thus if you are in command mode and want
to display line number then press the colon (:) key that takes you in ex command
mode. Now the cursor is placed at the bottom line of the screen and you type in the
command:
(Esc): set number
Or
(Esc): set nu
The vi editor provide some other useful block commands as:
(i)
:m,n w file
This command writes lines m to n to a file.
(ii)
:m,n w>>file
This command appends lines m to n to a file.
(iii)
:r files
This reads contents of the specified file at current cursor position.
(vi)
:r! command
It executes shell command and output of the command is read at the
current cursor position.
Aim: Develop advance shell program using grep, fgrep & egrep.
The grep command:
The name grep stands for global regular expression printer. The grep command is
used to search more than one file for particular bit pattern globally and displays the
line containing them, The syntax is:
grep char_pattern file[s]
After the execution of this command, each line of each file that contain the specific
char_pattern will be displayed on the display monitor. If you specify more than one
file then each line is also immediately preceded name of the file. If the char pattern
does not exist in the specified file then the grep command simply displays a new
prompt.
Here if you dont use double quote signs then the spaces between son, of and India
would not produce correct result. Now watch carefully the execution of the following
grep command :
$ grep son of India players
grep: cant open of
grep: cant open India
$
Means here, son would be expected as a character pattern and of, India and players
are expected as a file to be searched. Since there is no file called of and India
therefore the grep command displays the message:
Grep: cant open of
Grep:Cant open India.
And then it proceeds to search the file players for the pattern son. Thus it, is
necessary to use single quotes or double quotes on the multi words pattern string is:
$grep son of India players
$grep son of India players
or
-c
-i
-l
-n
-s
-v
:
:
:
:
:
:
For example if we want to know how many times the pattern great occurred in a file
players, then we write
Metacharacter: ~
We can also use metacharacters, special characters such as ?, *, ., [..]
For instance, the following grep command
$grep great players?
Searches all those files that matches upto players? To any 8 characters filenames
starting with players. Here the special character, ?, stands for any one characters.
Example: ~
The program given below represents the functioning of egrep and grep commands:
Read statements is the shells internel tool for taking input from the user that is
Making scripts interactive. It is used with one or more variables and input supplied .
the standerd input is read into these variables.Let us suppose a script named as
employee1.sh.
The script employee1 uses read to take a search string and file name from the
terminal.
$ cat employee1.sh
# script : employee1.sh-interactive version
# the pattern and file name will be supplied by the user
echo \n enter the pattern to be searched :\c
read pname
echo \n enter the file to be used :\c
read filename
echo \n searching for $ pname from file $ filename\n
grep $ pname $ filename
echo \n selected record shown above \n
\c put the cursor at the end of echo argument root to the next line
options.
GNU: ~
Gnu stands for GNU C Compiler, is a simple compiler on GNU/Linux systems.
When building a project, gcc has a default search path to use for things like include
files and libraries. You will find that you will often add components to the path. For
instance:
If you are going to compile the program named as punit1, then you may need to add
an entry to the search path so that the gcc can find the header files for your program
punit1.
The options for adding the entry to the include file search path and library search
options are i, -l respectively.
For example, you have a program that wants to include a file named scsi.h, then your
system may have this file under /usr/include/scsi, which is not default search path.
Therefore you might have:
gcc wall i/usr/include/scsi o myprogram myrogram.c
This option would help the preprocessor to find the scsi.h file. The same concept will
be included for libraries. If your program needs to link to the X11 library, then you
may tell this to linker like this:
gcc l/usr/X11r6/lib wall o myprogram myprogram.c lX11
(ii)
When writing many programs, you will need to link with the libraries. These library
can be anything from that implement mathematical function to ones that provide
support for using a graphical interface in the X Window System. They can be either
static or shared (dynamic); gcc can work with both.
The basic options to link in a library with your current program is -l( a lowercase L)
For instance, if you want to include the math library, you would probably include
math.h in your program. Then, when compiling, you would need to link in the math
library, names simply m. Therefore, a command such as the following would be
appropriate:
gcc Wall o mathprogram mathprogram.c lm
(iii)
All the interaction between the various builds programs are normally hidden from
view.
There details are generally unimportant and distracting.However, you can request the
details to be shown as gcc runs; to do this use the v option.
$ gcc v Wall -03 o test2 test2.c
The output will be the detailed list of build process.
Partitions: ~
Highlighted Free under /dev/had has 28624 Mbytes of Free space. However you can
also install Red Hat Linux on any other partition. Here it is supposed that you are
installing Red Hat Linux on first partition.
Unless you have a reason for doing otherwise, we recommend that you create the
following partition:
Click the New button
Mount Point = /
File System Type = ext3 (default)
Allowable drives = default just the one in the computer
Size MB = 1.7GB 5.0 GB (1.7 GB root partition for desktop installation and
5.0 GB for installation of every package)
Click the New Button
Mount Point = /boot
File System Type = ext3 (default)
Allowable drives = default just the one in the computer.
Size MB = 100 MB.
Next create a swap partition. Red Hat says the swap partition should be twice the
memory or 32 MB, which ever is larger. For 256 MB Memory, it should be 512 MB.
Bootloader Installation left everything default
Use GRUB as the boot loader. You can also select LILO or even choose not to install
a boot loader at all.
Install Boot Loader record on /dev/hda1 Master Boot Record (MBR).
Default Boot Image : red Hat Linux
Click on Next
GRUB Password left default = no GRUB Password Click on Next
Network Configuration left as default (DHCP and activate at boot) its less
overall work to change it after Linux is up Click on Next
Firewall Configuration Selected No firewall (the broadband router does that
function) Click on Next.
Additional Language Support English (USA) (already checked) Click on Next.
Time Zone Selection Click on Time of area you want and then Click on Next.
Account Configuration Entered and Confirmed a password for Root Click on
Next
Authentication Configuration Left all settings at defaults.
Click on Next
Package Group Selection Unless you choose a custom installation ,the installation
program will automatically choose most packages for you. However if you have
chosen custom installation then select the following packages and rest unchecked:
X Window System
CNOME Desktop Environment
Graphical Internet
Web Server In details added all mysql and php options
Windows File Server
FTP Server
SQL Database Server In details added mysql server
Administrative Tools
System Tools
Printing Tools
Next
Remember one thing while selecting package group selection that one should not
select Samba (Windows Networking), you can install it later.
About to install screen Next you will see a screen preparing you for the installation
of Red HatLinux.
Installing Packages
Insert CD #2 in your CD ROM / DVD ROM drive when you are asked to do so.
Insert CD #3 in your CD ROM / DVD ROM drive when you are asked to do so.
Boot Diskette Creation Skip boot disketter creation , if you dont need it
Monitor Configuration Says my shop monitor is an Unprobed Monitor Click on
Next.
Customize Graphics Configuration left it at default: True Colour (24 bits), 800
X 600, Graphical
Click on Next
It ejected the CD
Exit
(If the screen goes bananas like minedid just wait and let the computer reboot)
It rebooted
Welcome Forward
User Account Created an account for myself Forward
Date and Time Did not check Enable network time protocol Forward
Red Hat Network opted not to register Forward
Additional CDs Forward
Finish Setup Forward
It rebooted.
Logged in as root.
(B)
St 2:
St 3:
St 4:
If there is no device node for the disk, create a device node. For example, for
the first SCSI hard disk, enter:
mknod /dev/sda b 8 0
For more details, see the mknod (8) manual page in the Linux documentation.
For an EIDE hard disk, use the appropriate device such as /dev/hda.
/proc/partitions contains a list of major and minor numbers associated with all
the available partitions.
St 5: Modify the hard disk partition table using fdisk. For details, see the fdisk (8)
manual page in the Linux documentation. For example, for the first SCSI hard
disk, enter:
fdisk /dev/sda
For an EIDE hard disk, use the appropriate device such as /dev/hda.
St 6: Make new partitions for Linux root and Linux swap. For example you could
choose ``sda1'' for Linux root and ``sda2'' for Linux swap. Note down which
partition Linux root and Linux swap are on. For details of how to make new
partitions, see the fdisk (8) manual page in the Linux documentation.
St 7:
Press <Ctrl> <Alt> <Del> to reboot your system. A reboot is necessary as the
graphical partition tool may not recognize that you have changed the partition
table using fdisk.
St 8:
St 9:
St 10:
St 11:
St 12:
Shell script can take input from user, file and output them on screen.
Useful to create our own commands.
Save lots of time.
To automate some task of day today life.
System Administration part can be also automated.
esac
[Ctrl + d]
$_
Sr. No.
Objective
2
3
6
7
INDEX
Teacher sign.