Linux Final

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 90

Explain the installation procedure of Linux(standalone).

UBUNTU INSTALLATION
COMPONENTS REQUIRED
LINUX bootable CD Assembled PC with CD ROM.
PROCEDURE
STEP1: You will see the wallpaper and the installation wizard. Select your language and
click "Install Ubuntu 10.04 LTS" button to continue...\
STEP 2: The second screen will feature a map of the Earth. Upon the selection of your
current location, the time for the final system will adjust accordingly. You can also select
your current location from the drop-down list situated at the bottom of the window. Click
the "Forward" button after you have selected your desired location.
STEP3: On the third screen, you will be able to choose a desired keyboard layout. But the
default automatic selection should work for most of you. Click the "Forward" button when
you have finished with the keyboard configuration.
STEP4:

There are four

options for the partition they are as follows:

1. If you have another operating system (e.g. Windows XP) and you want a dual boot
system, select the first option: "Install them side by side, choosing between them at each
startup."
2. If you want to delete your existing operating system, or the hard drive is already empty
and you want to let the installer automatically partition the hard drive for you, select the
second option, "Use the entire disk."
3.The third choice is "Use the largest continuous free space" and it will install Ubuntu 10 in
the un partitioned space on the selected hard drive.
4. The fourth choice is "Specify partitions manually" and it is recommended only for
advanced users, to create special partitions or format the hard drive with other file systems
than the default one. But it can also be used to create a /home partition, which is very
useful in case you reinstall the whole system.
STEP5:

The steps to perform the manual partition are as follows:

- Select the "Specify partitions manually (advanced) and click the "Forward" button;
- Make sure that the selected hard drive is the right one. /dev/sda is the first physical hard
drive. /dev/sdb is the second hard drive in your machine. So, make sure that you know

which the one you want to format is! Else, you will lose all your data on that harddrive.
- Let's say that the selected drive is empty (no other operating system or important data on
it), but it has some partitions on it. Select each one of those partitions and click the "Delete"
button. After a few seconds, it will say "free space." Do this with the other partitions from
the selected hard drive, until they're all deleted and you have a single "free space" line;
- With the "free space" line selected, click on the "Add" button. In the new window, type
2000 in the "New partition size in megabytes" field and select the "swap area" option from
the "Use as:" drop down list. Click the OK button and, in a few seconds, you'll notice a
"swap" line with the specified size;
- With the "free space" line selected, click on the "Add" button. In the new window, select
the "Primary" option, type a value between 10,000 and 50,000 in the "New partition size in
megabytes" field and select / as the "Mount point." Click the OK button and, in a few
seconds, you'll notice an "ext4 /" line with the specified size;
- With the "free space" line selected, click on the "Add" button. In the new window, select
the "Primary" option, type a value between 30,000 and 50,000 (or whatever space you have
left on the drive) in the "New partition size in megabytes" field and select /home as the
"Mount point." Click the OK button and, in a few seconds, you'll notice an "ext4 /home"
line with the specified size.
This is how the partition table should look like. If so, click the "Forward" button to
continue with the installation.
STEP6: On this screen, you must do exactly what the title says. Fill in the fields with your
real name, the name you want to use to log in on your Ubuntu OS the password and the
name.
Also at this step, there's an option called "Log in automatically." If you check the box
on this option, you will automatically be logged in to the Ubuntu desktop. Click the
"Forward" button to continue.
STEP7: This is the final step of the installation. Here, you can select to install the boot
loader on another partition or hard drive than the default one, but it is only recommended
for advanced users. If someone is installing to a USB memory stick, as if it was a USB hard
drive, then they should know that the installer will mess with their computer's hard disk
drive MBR.
STEP8: After approximately 10 to 18 minutes a pop-up window will appear, notifying you
that the installation is complete, and you'll need to restart the computer in order to use the
newly installed Ubuntu operating system. Click the "Restart Now" button.
STEP9: The CD will be ejected; remove it and press the "Enter" key to reboot. The
computer will be restarted and, in a few seconds, you will see the Ubuntu boot splash...

STEP10: At the login screen, click on your username and input your password. Click the
"Log In" button or hit Enter...
STEP11: Have fun using Ubuntu 10.04 LTS.

COMMANDS

Basic commands
a) mkdir
Short for make directory this command is used to create a new directory.
-bash-3.2$ mkdir newdirectory
b)cd
Changes the directory.
-bash-3.2$ cd newdirectory
c) pwd
Short for print working directory the pwd command displays the name of the current
working directory
-bash-3.2$ pwd
/home/11bmca17/newdirectory
d) cal
Calendar for the month and the year.
-bash-3.2$ cal
December 2013
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
e) ls
Lists the contents of a directory
-bash-3.2$ ls
1st 2nd sem

exam2

linuxlab.doc

3rd sem

exam3

Linux Tutorial.docx

4th sem

examsecond

mbox

f1

mca

aa

f2

myfile1

aswathy17

f3

myfile2

f) mv
Renames a file or moves it from one directory to another directory.
-bash-3.2$ mv newdirectory new_dir
g)cp
Copies files from one location to another.
-bash-3.2$ cp file1 newfile
-bash-3.2$ cat file1
hello
-bash-3.2$ cat newfile
hello
h) rm
Deletes a file without confirmation (by default).
-bash-3.2$ rm file1
-bash-3.2$ cat file1
cat: file1: No such file or directory
i)rmdir
Deletes a directory.
-bash-3.2$ rmdir new_dir
-bash-3.2$ cd new_dir
-bash: cd: new_dir: No such file or directory
j) touch
Creates a file
-bash-3.2$ touch file1
k) cat
Allows you to look, modify or combine a file.
-bash-3.2$ cat newfile
hello
l) file
Tells you if the object you are looking at is a file or if it is a directory.
-bash-3.2$ file newfile
newfile: ASCII text

m) ln
Creates a link to a file.
-bash-3.2$ ln -s newfile newfiles
-bash-3.2$ ls -l
lrwxrwxrwx 1 11bmca17 11bmca17

7 Dec 6 17:21 newfiles -> newfile

n) find
Finds one or more files assuming that you know their approximate filenames.
-bash-3.2$ find newfile
Newfile
-----------------------------------------------------------------------------------------------File comparison commands
a) cmp
Compares two files and tells you what line numbers are different
[12amca30@mcalab ~]$ cat m1
Hello
[12amca30@mcalab ~]$ cat m2
hai this is vincy
[12amca30@mcalab ~]$ cmp m1 m2
m1 m2 differ: byte 2, line 1

b)diff
Displays two files and prints the lines that are different.
[12amca30@mcalab ~]$ diff m1 m2
1,2c1
< hello
<
--> hai this is vincy

Disk related commands


a) du
Tells you how much space a file occupies
[12amca30@mcalab ~]$ cd UNIX
[12amca30@mcalab UNIX]$ ls
CHAPTER_4 hw4 hw4.bak hw4HL hw4SL kk
[12amca30@mcalab UNIX]$ du
4
./CHAPTER_4
20
.

b)df
Report how much free disk space is available for each mount you have.
[12amca30@mcalab UNIX]$ df
Filesystem

1K-blocks

/dev/sda3

5952284 5550364

/dev/sda5

109109796 102791736

/dev/sda1
tmpfs

988088
969368

Used Available Use% Mounted on

25524
0

94680 99% /
686076 100% /home

911560 3% /boot

969368 0% /dev/shm

c)dfspace
Report how much free disk space is available for each mount you have.

[12amca30@mcalab UNIX]$ df -h
Filesystem

Size Used Avail Use% Mounted on

/dev/sda3

5.7G 5.3G 93M 99% /

/dev/sda5

105G 99G 670M 100% /home

/dev/sda1

965M 25M 891M 3% /boot

tmpfs

947M

0 947M 0% /dev/shm

d) ulimit
Sets or reports user resource limits.
[12amca30@mcalab UNIX]$ ulimit
unlimited
e) checking disk quota(quotacheck,edquota)
Checks file system quota consistency.
-bash-3.2$ quotacheck -g /usr
Edits user and group quotas.
-bash-3.2$ edquota -u -p davec sharl
Scheduling commands:a) at
Schedules a command to be ran at a particular time, such as a print job late at night.
-bash-3.2$echo uuclean | at 3:00 pm January 24
[12amca30@mcalab ~]$ at 18:51
at> echo "this is vincy">/dev/pts/22
at> <EOT>
job 1164 at 2014-10-21 18:51
b) batch
Runs jobs when the system load level permits.

[12amca30@mcalab ~]$ batch<<!


> hai are you ok
>!
job 1170 at 2014-10-21 18:51

[12amca30@mcalab ~]$ batch 18:54


at> echo "haiiiiiii">/dev/pts/22
at> <EOT>
job 1171 at 2014-10-21 18:54
c) crontab
List of files that you want to run on a regular schedule
-bash-3.2$ touch cronfile
-bash-3.2$ vi cronfile
* * * * * echo"hai welcome to mca lab" > /dev/pts/21
-bash-3.2$ crontab cronfile
-bash-3.2$ mail
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/11bmca17": 5 messages 1 new 5 unread
U 4 11bmca16@mcalab.doma Thu Nov 7 17:35 20/604 "hai"
>N 5 root@mcalab.domain Thu Dec 12 14:52 23/893 "Cron <11bmca17@mcalab"
&5
Message 5:
From 11bmca17@mcalab.domain Thu Dec 12 14:52:02 2013
Date: Thu, 12 Dec 2013 14:52:01 +0530
From: root@mcalab.domain (Cron Daemon)
To: 11bmca17@mcalab.domain
Subject: Cron <11bmca17@mcalab> echo"hai welcome to mca lab"
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/11bmca17>
X-Cron-Env: <PATH=/usr/bin:/bin>

/bin/sh: echohai welcome to mca lab: command not found


Process related commands:a) ps
Reports the process status.
[12amca30@mcalab ~]$ ps
PID TTY
TIME CMD
17938 pts/22 00:00:00 bash
20121 pts/22 00:00:00 ps
b) kill
The kill command is used on Linux and other Unix-like operating systems to terminate
processes without having to log out or reboot (i.e., restart) the computer. Thus, it is
particularly important to the stability of such systems.
[12amca30@mcalab ~]$ kill -9 17938
c) nice
Invokes a command with an altered scheduling priority
[12amca30@mcalab ~]$ nice -n 5 who
root :0
2014-10-21 15:37
11amca23 pts/2
2014-10-21 18:22 (192.168.101.29)
root pts/1
2014-10-21 16:32 (:0.0)
12amca19 pts/3
2014-10-21 18:21 (192.168.101.17)
12amca22 pts/4
2014-10-21 19:01 (192.168.101.21)
12amca25 pts/5
2014-10-21 18:21 (192.168.101.20)
12amca10 pts/6
2014-10-21 18:26 (192.168.101.9)
12amca02 pts/7
2014-10-21 18:33 (192.168.101.4)
12amca05 pts/8
2014-10-21 18:22 (192.168.101.6)
12amca08 pts/9
2014-10-21 18:22 (192.168.101.7)
12amca27 pts/10
2014-10-21 18:22 (192.168.101.26)
12amca26 pts/11
2014-10-21 18:57 (192.168.101.24)
12amca15 pts/12
2014-10-21 18:29 (192.168.101.14)
12amca20 pts/14
2014-10-21 18:22 (192.168.101.19)
12amca18 pts/15
2014-10-21 18:23 (192.168.101.25)
12amca07 pts/16
2014-10-21 18:23 (192.168.101.2)
12amca23 pts/17
2014-10-21 18:23 (192.168.101.22)
12amca30 pts/18
2014-10-21 19:08 (192.168.101.28)
12amca24 pts/19
2014-10-21 18:24 (192.168.101.23)
12amca14 pts/23
2014-10-21 18:29 (192.168.101.13)
12amca29 pts/24
2014-10-21 18:58 (192.168.101.27)
12amca12 pts/25
2014-10-21 18:48 (192.168.101.11)
12amca32 pts/26
2014-10-21 18:33 (192.168.101.5)
12amca13 pts/27
2014-10-21 18:35 (192.168.101.12)
12amca17 pts/28
2014-10-21 18:36 (192.168.101.16)
12amca11 pts/29
2014-10-21 18:36 (192.168.101.15)
[12amca30@mcalab ~]$

d) bg
Continues a stopped job in the background. This function is not available on all
Unix shell's.
[12amca30@mcalab ~]$ bg
-bash: bg: current: no such job

e) who
Displays who is on the system
[12amca30@mcalab ~]$ who
root

:0

2014-10-21 15:37

11amca23 pts/2
root

pts/1

2014-10-21 18:22 (192.168.101.29)


2014-10-21 16:32 (:0.0)

12amca19 pts/3

2014-10-21 18:21 (192.168.101.17)

12amca22 pts/4

2014-10-21 19:01 (192.168.101.21)

12amca25 pts/5

2014-10-21 18:21 (192.168.101.20)

12amca10 pts/6

2014-10-21 18:26 (192.168.101.9)

12amca02 pts/7

2014-10-21 18:33 (192.168.101.4)

12amca05 pts/8

2014-10-21 18:22 (192.168.101.6)

12amca08 pts/9

2014-10-21 18:22 (192.168.101.7)

12amca27 pts/10

2014-10-21 18:22 (192.168.101.26)

12amca26 pts/11

2014-10-21 18:57 (192.168.101.24)

12amca15 pts/12

2014-10-21 18:29 (192.168.101.14)

12amca24 pts/13

2014-10-21 19:09 (192.168.101.23)

f) nohup
The nohup command runs the command specified by the Command parameter and any
related Arg parameters, ignoring all hangup (SIGHUP) signals or modifies the process
specified with -p option to ignore all hangup (SIGHUP) signals.The nohup command
can also be used to run programs in the background after logging off. To run a nohup
command in the background, add an & (ampersand) to the end of the command.

Note:
-p pid and Command can not be specified together.
When -p pid is used, the output of the specified process will not be re-directed to
nohup.out.
-bash-3.2$ nohup find . -name linexpgms -type d > test
-bash-3.2$ cat test
./linexpgms
----------------------------------------------------------------------------g) fork
A fork is a Unix or Linux system call to create a new process from an existing running
process. The new process is a child process of the calling 'parent' process.
h) killall
killall sends a signal to all processes running any of the specified commands. If no
signal name is specified, SIGTERM is sent
-bash-3.2$ killall -I fgdhf
fgdhfh: no process killed
i)trap
Shell built-in functions to respond to (hardware) signals.
trap 'rm -f /tmp/xyz$$; exit' ERR EXIT
j) exit
Command or option used to close a program or file. The method of exiting from a
program or file varies depending upon the computer or program being used.
[12amca30@mcalab ~]$ exit
k) renice
renice alters the priority of running processes.
-bash-3.2$ renice 18 4766
4766: old priority 0, new priority 18
l) strace
Prints STREAMS trace messages.
-bash-3.2$ strace 41 all all

m) top
The top program provides a dynamic real-time view of a running system. It can display
system summary information as well as a list of processes or threads currently being
managed by the kernel. The types of system summary information shown and the types,
order and size of information displayed for tasks are all user-configurable.
[12amca30@mcalab ~]$ top
top - 15:10:45 up 3:32, 27 users, load average: 0.52, 0.54,
Tasks: 244 total, 1 running, 239 sleeping, 4 stopped, 0
Cpu(s): 0.4%us, 0.6%sy, 0.3%ni, 97.7%id, 1.0%wa, 0.0%hi,
Mem: 1938736k total, 1866036k used,
Swap: 2048276k total,
PID USER

72700k free, 17690

0k used, 2048276k free, 145504

PR NI VIRT RES SHR S %CPU %MEM TIME+

22359 12amca30 19 0 2332 1016 700 R 3.9 0.1 0:00.02


20231 root

15 0 17768 5496 3132 S 1.9 0.3 0:02.38

1 root

15 0 2072 624 532 S 0.0 0.0 0:01.13

2 root

RT -5

0 S 0.0 0.0 0:00.03

3 root

39 19

0 S 0.0 0.0 0:00.00

4 root

RT -5

0 S 0.0 0.0 0:00.00

5 root

RT -5

0 S 0.0 0.0 0:00.05

6 root

39 19

0 S 0.0 0.0 0:00.00

7 root

RT -5

0 S 0.0 0.0 0:00.00

8 root

RT -5

0 S 0.0 0.0 0:00.01

9 root

34 19

0 S 0.0 0.0 0:00.00

10 root

RT -5

0 S 0.0 0.0 0:00.00

11 root

RT -5

0 S 0.0 0.0 0:00.04

12 root

34 19

0 S 0.0 0.0 0:00.00

13 root

RT -5

0 S 0.0 0.0 0:00.00

14 root

10 -5

0 S 0.0 0.0 0:06.39

15 root

10 -5

0 S 0.0 0.0 0:00.01

n) exec
When referring to a command line such as Linux or Unix, exec is a BOURNE and
POSIX shell command that replaces the current shell process with the command
specified after exec and does not create a new PID. For example, if you were to run
exec <command>, the shell would be replaced by that command. When that command
is exited the shell will exit.
[12amca30@mcalab ~]$ exec
Printing commands:a) lpr
Submits print requests.
[12amca30@mcalab ~]$ lpr a
lpr: Error - no default destination available.
b) lpq
Lists the status of all the available printers.
[12amca30@mcalab ~]$ lpq -l
lpq: error - no default destination available.
c) lprm
Removes print requests from the print queue.
d) lpc
Line printer control program.
e) pr
Formats a file to make it look better when printed
File Processing commands
a) wc
Short for word count, wc displays a count of lines, words, and characters in a file.
[12amca30@mcalab ~]$ cat newfile
hai this is vincy
[12amca30@mcalab ~]$ wc -l newfile
1 newfile
[12amca30@mcalab ~]$ wc -w newfile
4 newfile
[12amca30@mcalab ~]$ wc -c newfile
18 newfile
b) sort
A term used to describe the process of organizing data in a particular order allowing for
information to be found easier. For example, names and contact information may be

sorted in alphabetical order to allow the person looking for a name to see if it is
available
[12amca30@mcalab ~]$ cat haii
hai
hello
popy
ants
[12amca30@mcalab ~]$ sort haii
ants
hai
hello
popy
c) cut
The process of removing an item and placing it in a temporary location, called the
clipboard. Once placed in the clipboard the user has the ability of pasting that item
elsewhere. Only programs that allow text to be removed can be cut, other programs
will only enable a user to copy. For example, you can cut text from a web page, but
can cut text from a word processor file.
[12amca30@mcalab ~]$ cat f2
1425
JUAN
14.25
4321
GEORGE 21.11
6781
ANNA
16.77
1451
BEN
21.77
2277
TUAN
18.77
[12amca30@mcalab ~]$ cut -f3 < f2
JUAN
GEORGE
ANNA
BEN
TUAN
---------------d) paste
Merge corresponding or subsequent lines of files.
[12amca30@mcalab ~]$ paste f2 > f11

[12amca30@mcalab ~]$ cat f11


1425

JUAN

14.25

4321

GEORGE 21.11

6781

ANNA

1451

BEN

2277

TUAN

16.77
21.77
18.77

e)dd
Copy a file, converting the format of the data in the process, according to the operands
specified.
-bash-3.2$ dd if=/dev/sr0 of=/home/hope/exampleCD.iso bs=2048 conv=noerror,sync
f) join
join joins the contents of two files, combining common fields of data.
[12amca30@mcalab ~]$ cat test1
1 india
2 us
3 uk
[12amca30@mcalab ~]$ cat test2
1 newdelhi
2 washington
3 london

[12amca30@mcalab ~]$ join test1 test2


1 india newdelhi
2 us washington

3 uk London

g) uniq
Report or filter out repeated lines in a file
[12amca30@mcalab ~]$ cat test3
aa
aa
bb
cc
cc
[12amca30@mcalab ~]$ uniq test3
aa
bb
cc
h) read
[12amca30@mcalab ~]$ echo "enter a number"
enter a number
[12amca30@mcalab ~]$ read a
36
Mathematical commands
a)

expr
Evaluate arguments as an expression
[12amca30@mcalab ~]$ a=10
[12amca30@mcalab ~]$ b=20
[12amca30@mcalab ~]$ c=`expr $a + $b`
[12amca30@mcalab ~]$ echo $c
30

b) eval
Short for evaluate, eval is a function that can be found in various different
interpreted and compiled programming languages that have a variety of different
abilities depending on the programming language you're using.
[12amca30@mcalab ~]$ x=10
[12amca30@mcalab ~]$ y=x
[12amca30@mcalab ~]$ echo '$'$y
$x
[12amca30@mcalab ~]$ eval echo '$'$y
10
c) bc
Calculator.
[12amca30@mcalab ~]$ echo $a + $b |bc
30
d) factor
Factors a number
[12amca30@mcalab ~]$ factor 21
21: 3 7
e) let
[12amca30@mcalab ~]$ let c=1*2
[12amca30@mcalab ~]$ echo $c
2

f) test
Checks file types and compares values.
[12amca30@mcalab ~]$ test 100 -lt 90 $$ echo "yes" || echo "no"
no
Filter commands
a) pr
Formats a file to make it look better when printed
[12amca30@mcalab ~]$ ls -a | pr -n -h "Files in $(pwd)"

2014-10-23 17:54
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

Files in /home/12amca30

.
..
a
ants.sh
apily.exe
arm.sh
autorun.inf
backups.tar
.bash_history
.bash_logout
.bash_profile
.bashrc
bbjq.pif
bb.sh
BIOS.H.lnk
bus_LETTERS
bvdxjq.exe
cbfb.pif
Ch6S1F1
Ch6S2F1

b) head
Displays the first ten lines of a file, unless otherwise stated
[12amca30@mcalab ~]$ head -3 /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
c) tail
Delivers the last part of the file.
[12amca30@mcalab ~]$ tail -3 /etc/passwd
14lmca31:x:1126:1126::/home/14lmca31:/bin/bash
14lmca32:x:1127:1127::/home/14lmca32:/bin/bash
shankar:x:1128:1128::/home/shankar:/bin/bash
d) tr
Translate characters.

Page 1

[12amca30@mcalab ~]$ echo "123456 789" | tr 1234 mca


mcaa56 789
e) pg
Files perusal filters for CRTs.
Files perusal filters for CRTs.
-bash-3.2$ pg filename
f) more
Displays text one screen at a time.
[12amca30@mcalab ~]$ more -3 f2
1425
JUAN
14.25
4321
GEORGE 21.11
6781
ANNA
16.77
--More--(60%)
For each file examined, initially execute the more command in the command argume
nt. If the command is a positioning command, such as a line number or a regular
expression search, set the current position to represent the final results of th e
command, without writing any intermediate lines of the file.
g) less
It is similar to more, but has the extended capability of allowing both forward and
backward navigation through the file
[12amca30@mcalab ~]$ less -3 f2
1425
JUAN
14.25
4321
GEORGE 21.11
6781
ANNA
16.77
1451
BEN
21.77
2277
TUAN
18.77
f2 (END)
Filter using regular expression
a) grep
Finds text within a file.
[12amca30@mcalab ~]$ grep hello
hai vincy
hello bye
hello bye
b) egrep

Search a file for a pattern using full regular expressions.


[12amca30@mcalab ~]$ cat new_file
mca
ucc
semester4
[12amca30@mcalab ~]$ egrep "mca" new_file
mca
c) fgrep
Search a file for a fixed-character string
[12amca30@mcalab ~]$ fgrep "u" new_file
ucc
d)sed
Sort for Stream Editor sed allows you to use pre-recorded commands to make
changes to text.
[12amca30@mcalab ~]$ sed 's/mca/computer/g' new_file >n1
[12amca30@mcalab ~]$ cat n1
computer
ucc
semester4

e)awk
Short for Aho, Weinberger, and Kernighan, awk is a script processing language also
known as oawk, gawk, mawk and nawk allows for pattern scanning and processing.
-bash-3.2$ awk 'length >72' chapter 1
Communication commands
a) mesg
Lets you control if people can use the write command, to send text to you over the
screen
[12amca30@mcalab ~]$ mesg
is y
b) talk
Talk with other logged-in users.
[12amca30@mcalab ~]$ talk 12amca27
c) write

When referring to data or data storage, writing is the process of taking data and moving
it to an alternate location. For example, saving data onto a diskette is the same as saying
you are writing information to a diskette.
Write is a term may that describes the action of typing text.
Linux

command, see the write command page for further information about this

command
[12amca30@mcalab ~]$ write 12amca29
haiiiiiiiiii

d) wall
Wall sends a message to everybody logged in with their mesg permission set to yes.
The message can be given as an argument to wall, or it can be sent to wall's
standard input. When using the standard input from a terminal, the message should
be terminated with the EOF key (usually Control-D).
[12amca30@mcalab ~]$ wall good evng
Broadcast message from 12amca30 (pts/15) (Thu Oct 12 18:14:32 2014):
good evng
e) finger
Lists information about the user.
[12amca30@mcalab ~]$ finger 12amca30
Login: 12amca30
Name: vincy
Directory: /home/12amca30
Shell: /bin/bash
On since Thu Oct 23 17:56 (IST) on pts/15 from 192.168.101.88
1 second idle
New mail received Thu Oct 23 18:15 2014 (IST)
Unread since Tue Oct 21 19:03 2014 (IST)
No Plan.

f) Ping
Sends ICMP ECHO_REQUEST packets to network hosts.
[12amca30@mcalab ~]$ ping 192.168.101.200
PING 192.168.101.200 (192.168.101.200) 56(84) bytes of data.
64 bytes from 192.168.101.200: icmp_seq=1 ttl=64 time=0.028 ms
64 bytes from 192.168.101.200: icmp_seq=2 ttl=64 time=0.025 ms
64 bytes from 192.168.101.200: icmp_seq=3 ttl=64 time=0.026 ms

64 bytes from 192.168.101.200: icmp_seq=4 ttl=64 time=0.024 ms


64 bytes from 192.168.101.200: icmp_seq=5 ttl=64 time=0.024 ms
64 bytes from 192.168.101.200: icmp_seq=6 ttl=64 time=0.025 ms
64 bytes from 192.168.101.200: icmp_seq=7 ttl=64 time=0.024 ms
64 bytes from 192.168.101.200: icmp_seq=8 ttl=64 time=0.025 ms
64 bytes from 192.168.101.200: icmp_seq=9 ttl=64 time=0.026 ms
64 bytes from 192.168.101.200: icmp_seq=10 ttl=64 time=0.026 ms
64 bytes from 192.168.101.200: icmp_seq=11 ttl=64 time=0.026 ms
64 bytes from 192.168.101.200: icmp_seq=12 ttl=64 time=0.027 ms
64 bytes from 192.168.101.200: icmp_seq=13 ttl=64 time=0.024 ms
64 bytes from 192.168.101.200: icmp_seq=14 ttl=64 time=0.024 ms
64 bytes from 192.168.101.200: icmp_seq=15 ttl=64 time=0.025 ms
64 bytes from 192.168.101.200: icmp_seq=16 ttl=64 time=0.024 ms
64 bytes from 192.168.101.200: icmp_seq=17 ttl=64 time=0.026 ms
64 bytes from 192.168.101.200: icmp_seq=18 ttl=64 time=0.027 ms
64 bytes from 192.168.101.200: icmp_seq=19 ttl=64 time=0.026 ms

h) whoami
Print effective userid.
[12amca30@mcalab ~]$ whoami
12amca30
i)hostname
Set or print name of current host system. Additional information about the term
hostname can be found on our hostname definition.
[12amca30@mcalab ~]$ hostname
mcalab.domain
j) uname
Print name of current system.
[12amca30@mcalab ~]$ uname
Linux

k) umask

Get or set the file mode creation mask.


[12amca30@mcalab ~]$ umask
0002
l) chfn
chfn is used to change a user's finger information.
[12amca30@mcalab ~]$ chfn
Changing finger information for 12amca30.
Password:
Name [vincy]: vincy
Office []:
Office Phone []:
Home Phone []:
Finger information changed.

Bash start up files


a) /etc/profile file
Here is a base /etc/profile. This file starts by setting up some helper functions and some
basic parameters. It specifies some bash history parameters and, for security purposes,
disables keeping a permanent history file for the root user. It also sets a default user
prompt. It then calls small, single purpose scripts in the /etc/profile.d directory to
provide most of the initialization.
[11bmca17@mcalab ]$ install --directory --mode=0755 --owner=root --group=root
/etc/profile.d
The second file that the operating system uses at login time is the /etc/profile file.
The /etc/profile file controls system-wide default variables, such as:

Export variables

File creation mask (umask)

Terminal types

Mail messages to indicate when new mail has arrived


The system administrator configures the /etc/profile file for all users on the system.

Only the system administrator can change this file.


The following example is a typical /etc/profile file:
#Set file creation mask
unmask 022
#Tell me when new mail arrives
MAIL=/usr/mail/$LOGNAME
#Add my /bin directory to the shell search sequence
PATH=/usr/bin:/usr/sbin:/etc::
#Set terminal type
TERM=lft
#Make some environment variables global
export MAIL PATH TERM
b) .bashrc
The ~/.bashrc file determines the behavior of interactive shells. A good look at this file
can lead to a better understanding of Bash. Example is shown below,
a.

# =============================================================== #

b.

c.

# PERSONAL $HOME/.bashrc FILE for bash-3.0 (or later)

d.

# By Emmanuel Rouat [no-email]

e.

f.

# Last modified: Tue Nov 20 22:04:47 CET 2012

g.
h.

# This file is normally read by interactive shells only.

i.

#+ Here is the place to define your aliases, functions and

j.

#+ other interactive features like your prompt.

k.

c) .bash_profile
Most of the time you dont want to maintain two separate config files for login and
non-login shells when you set a PATH, you want it to apply to both. You can fix this
by sourcing .bashrc from your.bash_profile file, then putting PATH and common
settings in .bashrc.
To do this, add the following lines to .bash_profile:
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
Now when you login to your machine from a console .bashrc will be called.
d) .bash_logout
Upon logout, the commands in ~/.bash_logout are executed, which can for instance clear the
terminal, so that you have a clean window upon logging out of a remote session, or upon
debby:~> cat .bash_logout
# ~/.bash_logout
Clear

leaving the system console

e).bash_history
BASH is the default shell for Linux computers. Bash has history command. It display
the history list with line numbers i.e. it lists everything you have entered on the
command line. You can recall commands from history so that you can save the time.
Environment variables and positional parameters
a) env

Displays your Unix environment variables.


[12amca30@mcalab ~]$ env
HOSTNAME=mcalab.domain
SHELL=/bin/bash
TERM=ansi
HISTSIZE=1000
KDE_NO_IPV6=1
QTDIR=/usr/lib/qt-3.3
QTINC=/usr/lib/qt-3.3/include
USER=12amca30
LS_COLORS=no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd
=40;33;0
1:or=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;
32:*.b
tm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;3
1:
*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;3
1:*
.
bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=0
1;3
5:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35:
KDEDIR=/usr
MAIL=/var/spool/mail/12amca30
PATH=/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/bin:/bin:/home/12amca30/bin
LOGIN=12amca30
INPUTRC=/etc/inputrc
PWD=/home/12amca30
LANG=en_US.UTF-8
KDE_IS_PRELINKED=1
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
KRB5CCNAME=FILE:/tmp/krb5cc_p17633
SHLVL=1
HOME=/home/12amca30
LOGNAME=12amca30
QTLIB=/usr/lib/qt-3.3/lib
CVS_RSH=ssh
LESSOPEN=|/usr/bin/lesspipe.sh %s
G_BROKEN_FILENAMES=1
_=/usr/bin/env

b) set
Calling set without arguments displays the names and values of all shell
variables, sorted by name, in the following format: Variable="value"

-bash-3.2$ set +A array a b c d


echo ${array[*]}
abcd
c ) unset
Unsets the variable name and then assigns the parameter list specified on the command
line to thearray elements of the variable name starting at name[0].
-bash-3.2$ set -A array a y
echo ${array[*]}
xy
d)shift
shift renames the positional parameters so that i+nth positional parameter becomes the
ith positional parameter, where n is the value of the given arithmetic expression. If you
omit expression, the default value is 1. The value of expression must be between zero
and the number of positional parameters ($#), inclusive. The value of $# is updated.
[12amca30@mcalab ~]$ set a b c d
[12amca30@mcalab ~]$ shift 2
[12amca30@mcalab ~]$ echo $*
cd

-bash-3.2$ set a b c d
shift 2
echo $*
produce:

cd
e)export

export marks each variable name so that the current shell makes it automatically
available to the
environment of all commands run from that shell. Exported variables are thus
available in the
environment to all subsequent commands.
[12amca30@mcalab ~]$ export name="hello"
[12amca30@mcalab ~]$ echo $name
hello
[12amca30@mcalab ~]$ bash
[12amca30@mcalab ~]$ echo $name
hello

File system management


a) mount
Once you create a partition, you should use mount command to mount the partition
into a mount point (a directory), to start using the filesystem.
[11bmca17@mcalab ~]# mount -t type device destination_dir
b) fsck
Linux fsck utility is used to check and repair Linux filesystems (ext2, ext3, ext4,
etc.).Depending on when was the last time a file system was checked, the system
runs the fsck during boot time to check whether the filesystem is in consistent state.
System administrator could also run it manually when there is a problem with the
filesystems.
# fsck /dev/sda6
c) mkfs
Build a Linux file system.
[11bmca17@mcalab ~] #mkfs -t ext2 /dev/fd0
d) umount
umount stands for unmount, which unmounts the file system. Use umount to
unmount a device / partition by specifying the directory where it has been mounted.
[11bmca17@mcalab ~]#umount /mnt
e) /etc/fstab file
fstab is a configuration file that contains information of all the partitions and storage
devices in your computer. The file is located under /etc, so the full path to this file is
/etc/fstab.
[11bmca17@mcalab ~]$ /etc/fstab

-bash: /etc/fstab: Permission denied


Archiving and compression utilities
a) compress
compress compresses each input file using Lempel-Ziv compression techniques. If
you do not specify any input files, compress reads data from standard input (stdin)
and writes the compressed result to standard output (stdout).
[11bmca17@mcalab ]$ compress -v bigfile.exe
b) uncompress
Uncompressed compressed files.
[11bmca17@mcalab]$ uncompress myfile.txt
c) gzip(with options)
compress or expand files
[11bmca17@mcalab ]$ gzip -c file1 > foo.gz
OPTIONS
-a --ascii :Ascii text mode: convert end-of-lines using local conventions.
-c --stdout --to-stdout :Write output on standard output; keep original files
unchanged.
-d --decompress --uncompress :Decompress.
-f --force :Force compression or decompression even if the file has multiple links or
the corresponding file already exists, or if the compressed data is read from or
written to a terminal.
-h --help :Display a help screen and quit.
-l --list :For each compressed file, list the following fields:
compressed size: size of the compressed file
uncompressed size: size of the uncompressed file
ratio: compression ratio (0.0% if unknown)
uncompressed_name: name of the uncompressed file
The uncompressed size is given as -1 for files not in gzip format, such as
compressed .Z files.

-L --license :Display the gzip license and quit.


-n --no-name :When compressing, do not save the original file name and time
stamp by default) When decompressing, do not restore the original file name if
present and do not restore the original time stamp if present This option is the
default when decompressing.
-N --name :When compressing, always save the original file name and time stamp;
this is the default. When decompressing, restore the original file name and time
stamp if present. This option is useful on systems which have a limit on file name
length or when the time stamp has been lost after a file transfer.
-q --quiet :Suppress all warnings.

-r --recursive :Travel the directory structure recursively. If any of the file names
specified on the command line are directories, gzip will descend into the directory
and compress all the files it finds there (or decompress them in the case of gunzip ).
-t --test :Test. Check the compressed file integrity.
-v --verbose :Verbose. Display the name and percentage reduction for each file
compressed or decompressed.
-V --version :Version. Display the version number and compilation options then
quit.
d) gunzip(with options)
compress or expand files
[11bmca17@mcalab ]$ gunzip -c myfile.gz > myfile.txt

Options are same as gzip


e) cpio
Creates and un-creates archived cpio files. And also is capable of copying files to things
other than a hard disk.

[11bmca17@mcalab]$ find . -print | cpio -ocv > /dev/fd0


f) dump
dump command makes backup of filesystem or file and directories.

[11bmca17@mcalab]$ dump -0uf databackup /home/user1/data


g) restore
restore - command restores the data from the dump-file or backup-file created using dump
command.

[11bmca17@mcalab]$ restore -if databack


h) rsync
Faster, flexible replacement for rcp.

[11bmca17@mcalab]$ rsync -t *.htm hope:public_html/


i) tar
tar reads, writes and lists archive files. An archive file is a single file containing one or more
files, directories, or both.

[11bmca17@mcalab]$ tar cvzf archive directory


j) zcat
zcat takes one or more compressed data files as input. The data files should be compressed with
the compress command. If no data files are specified on the command line, zcat reads standard
input (stdin).

[11bmca17@mcalab]$ zcat myfile


k) bzip2

bzip2 linux command is used to compress the file. Each file is replaced by a compressed
version of itself with .bz2 extension.

[11bmca17@mcalab]$ bzip2 -c log.txt >log.txt.bz2


[11bmca17@mcalab]$ls l
-rw-rw-r-- 1 11bmca17 11bmca17

2Dec 6 17:40 log.txt

-rw-rw-r-- 1 11bmca17 11bmca17 14 Dec 30 14:31 log.txt.bz2


l) zip
zip is used to compress the files to reduce file size and also used as file package utility.
[11bmca17@mcalab]$ zip archive pp
adding: pp (deflated 43%)

File permissions
a) chmod
Changes the permission of a file.
[12amca30@mcalab ~]$ touch one
[12amca30@mcalab ~]$ chmod o+w one
-rw-rw-rw- 1 12amca30 12amca30

0 Oct 23 18:35 one

b) chown
Command for system V that changes the owner of a file.

[11bmca17@mcalab ~]$ chown -R 11bmca17 sample


c) chgrp
changes the group that has access to a file or directory.

[11bmca17@mcalab]$ chgrp 11bmca17 one


User Administration
a) useradd
Enables a super user or root to create a new user or updates default new user information.

[11bmca17@mcalab ~]#useradd hiox


b) usermod
Enables a super user or root user to modify a users account.

[11bmca17@mcalab ~]#usermod -d /home/newperson newperson


c) userdel
Enables a super user to remove a users account.

[11bmca17@mcalab ~]#userdel -r hiox


d) groupadd
Creates a new group.

[11bmca17@mcalab ~]#groupadd newgroup


e) groupmod
Enables a super user or root to modify a group.

[11bmca17@mcalab ~]#groupmod -n bettergroup newgroup


f) groupdel
Enables a super user or root to remove a group.

[11bmca17@mcalab ~]#groupdel newgroup


g)/etc/passwd file
[12amca30@mcalab ~]$ cat /etc/passwd
14lmca11:x:1106:1106::/home/14lmca11:/bin/bash
14lmca12:x:1107:1107::/home/14lmca12:/bin/bash
14lmca13:x:1108:1108::/home/14lmca13:/bin/bash
14lmca14:x:1109:1109::/home/14lmca14:/bin/bash
14lmca15:x:1110:1110::/home/14lmca15:/bin/bash
14lmca16:x:1111:1111::/home/14lmca16:/bin/bash
14lmca17:x:1112:1112::/home/14lmca17:/bin/bash
14lmca18:x:1113:1113::/home/14lmca18:/bin/bash
14lmca19:x:1114:1114::/home/14lmca19:/bin/bash
14lmca20:x:1115:1115::/home/14lmca20:/bin/bash
14lmca21:x:1116:1116::/home/14lmca21:/bin/bash
14lmca22:x:1117:1117::/home/14lmca22:/bin/bash
14lmca23:x:1118:1118::/home/14lmca23:/bin/bash
14lmca24:x:1119:1119::/home/14lmca24:/bin/bash
14lmca25:x:1120:1120::/home/14lmca25:/bin/bash
14lmca26:x:1121:1121::/home/14lmca26:/bin/bash
14lmca27:x:1122:1122::/home/14lmca27:/bin/bash
14lmca28:x:1123:1123::/home/14lmca28:/bin/bash
14lmca29:x:1124:1124::/home/14lmca29:/bin/bash

14lmca30:x:1125:1125::/home/14lmca30:/bin/bash
14lmca31:x:1126:1126::/home/14lmca31:/bin/bash
14lmca32:x:1127:1127::/home/14lmca32:/bin/bash
shankar:x:1128:1128::/home/shankar:/bin/bash

g) /etc/shadow
/etc/shadow file stores actual password in encrypted format for user's account with additional
properties related to user password i.e. it stores secure user account information. All fields are
separated by a colon (:) symbol.

[11bmca17@mcalab ~]# cat /etc/shadow | grep bob


Linux start up and shut down
a) init
Process control initialization.

b) /etc/inittab file
inittab - format of the inittab file used by the sysv-compatible init process

To start the ident process at all run levels, enter:


ident:0123456789:Action:Command

c) chkconfig
Chkconfig command is used to setup, view, or change services that are configured to start
automatically during the system startup.

[11bmca17@mcalab ~]$ chkconfig --list | grep 3:on


d) xinetd service
xinetd stands for extended Internet services daemon. This is a replacement for inetd. xinetd
starts and listens on all the service ports that youve defined, and when there is an incoming
request to a particular port that it is listening to, it starts the corresponding service.
[12amca30@mcalab ~]$ ls -l /etc/xinetd.d
total 172
-rw-r--r-- 1 root root 1157 Dec 6 2006 chargen-dgram

-rw-r--r-- 1 root root 1159 Dec 6 2006 chargen-stream


-rw-r--r-- 1 root root 523 May 14 2009 cvs
-rw-r--r-- 1 root root 1157 Dec 6 2006 daytime-dgram
-rw-r--r-- 1 root root 1159 Dec 6 2006 daytime-stream
-rw-r--r-- 1 root root 1157 Dec 6 2006 discard-dgram
-rw-r--r-- 1 root root 1159 Dec 6 2006 discard-stream
-rw-r--r-- 1 root root 1148 Dec 6 2006 echo-dgram
-rw-r--r-- 1 root root 1150 Dec 6 2006 echo-stream
-rw-r--r-- 1 root root 323 Sep 9 2004 eklogin
-rw-r--r-- 1 root root 347 Sep 6 2005 ekrb5-telnet
-rw-r--r-- 1 root root 323 Feb 14 2012 gssftp
-rw-r--r-- 1 root root 310 Sep 9 2004 klogin
-rw-r--r-- 1 root root 322 Dec 1 2010 krb5-telnet
-rw-r--r-- 1 root root 308 Sep 9 2004 kshell
-rw-r--r-- 1 root root 267 Apr 15 2009 ktalk
-rwxr-xr-x 1 root root 722 Jul 17 2009 rmcp
-rw-r--r-- 1 root root 317 Jul 13 2006 rsync
-rw-r--r-- 1 root root 1212 Dec 6 2006 tcpmux-server
-rw-r--r-- 1 root root 510 May 19 2009 tftp
-rw-r--r-- 1 root root 1149 Dec 6 2006 time-dgram
-rw-r--r-- 1 root root 1150 Dec 6 2006 time-stream

e) reboot
The reboot command in Linux is used to reboot the system. This command invokes the
reboot() system call or the shutdown() system call depending on how it is used.

[11bmca17@mcalab ~]$ reboot r now


f) shut down
shutdown - bring the system down

[11bmca17@mcalab ~]$ shutdown -h 20:00


g) poweroff

Stop the computer.

[11bmca15@mcalab ~]$ poweroff


h) halt
Stop the computer.
Syntax
halt [-l] [-n] [-q] [-y]

shutdown -h 20:00
i) startx
Initializes an X session.

To start an X session on a workstation, or an X terminal, enter:


startx

j) lilo
lilo - install boot loader

[11bmca17@mcalab ~]$ lilo -q


k) grub
grub - the grub shell

l) telinit
telinit can also tell init how long it should wait between sending processes the SIGTERM and
SIGKILL signals. The default is 5 seconds, but this can be changed with the -t sec option.
telinit can be invoked only by users with appropriate privileges

To request the init command to reexamine the /etc/inittab file, enter:


telinit q
Vi editor commands:a) Basic commands
h :- moves the cursor to the previous character
l :- moves the cursor to the next character
k :- moves the cursor to the line above the current line
j :- moves the cursor to the line below the current line
x :- deletes the character at the current cursor position
:wq<Enter> :- Saves all the changes and quits the vi editor
:w<Enter> :- Saves the file

:ql<Enter> :- Quits without saving changes


:e<filename><Enter> :- opens the specified file
:r<filename><Enter> :- Reads and inserts the contents of the file after the current file
:w<filename><Enter> :- Writes to the specified file
:w!<filename><Enter> :- Forcefully writes to the specified file
:!<command_name><Enter> :- Executes a shell command
b) Insert and replace commands
a :- Enables you to append text after the current character.
A :- Enables you to append text at the end of the line.
i :- Enables you to insert text before the current character.
I :- Enables you to insert text at the beginning of the line.
o:- Inserts a blank line below the current line and allows you to insert text.
O:- Inserts a blank line above the current line and allows you to insert text.
rx :- Replaces the current character with the specified character.
Rtext<Esc> :- Replaces characters at the current cursor position with the specified text
until the <Esc> key is pressed
c) Deletion and modification commands
dw :- Deletes a word.
dd :- Deletes a line.
cw :- Changes a word
cc :- Changes a line.
X :- Deletes the character before the current cursor position.
J :- Joins lines.
u :- Undoes the last change made.
.(dot) :- Repeats the last change made
Software package management
a) rpm
RPM command is used for installing, uninstalling, upgrading, querying, listing, and
checking RPM packages on your Linux system.
RPM stands for Red Hat Package Manager.
[11bmca17@mcalab ~]$ rpm -qa | grep 'cdrecord'

cdrecord-2.01-10.7.el5
b) dpkg
dpkg queries, installs, removes, and maintains Debian software packages and their
dependencies.

[11bmca17@mcalab ~]$ dpkg -l '*vi*'


c) yum
Installing, removing, and updating packages is a typical activity on Linux. Most of the
Linux distributions provides some kind of package manager utility. For example, aptget, dpkg, rpm, yum, etc.
On some Linux distributions, yum is the default package manager.
Yum stands for Yellowdog Updater Modified.
The following command will list all the packages available in the yum database.
[11bmca15@mcalab ~]$ yum list | less
Loaded plugins: rhnplugin, security
*Note* Red Hat Network repositories are not listed below. You must run this comm
and as root to access RHN repositories.
Installed Packages
Deployment_Guide-en-US.noarch
GConf2.i386

5.2-11

installed

2.14.0-9.el5

installed

GConf2-devel.i386

2.14.0-9.el5

ImageMagick.i386

6.2.8.0-4.el5_1.1

MAKEDEV.i386
NetworkManager.i386

3.23-1.2

OpenIPMI.i386

installed

1:0.7.0-9.el5

NetworkManager-gnome.i386
ORBit2-devel.i386

installed
installed

1:0.7.0-9.el5

NetworkManager-glib.i386
ORBit2.i386

installed

installed

1:0.7.0-9.el5
2.14.3-5.el5
2.14.3-5.el5
2.0.16-5.el5

installed
installed
installed
installed

OpenIPMI-libs.i386

2.0.16-5.el5

installed

OpenIPMI-tools.i386

2.0.16-5.el5

installed

PyQt.i386

3.16-4

installed

PyQt-devel.i386

3.16-4

installed

PyXML.i386

0.8.4-4

installed

1.2.10-8.el5

installed

SDL.i386
SDL-devel.i386

1.2.10-8.el5

installed

SysVinit.i386

2.86-15.el5

installed

Xaw3d.i386

1.5E-10.1

installed

Xaw3d-devel.i386

1.5E-10.1

installed

d) apt-get
apt-get is the command-line tool for working with APT software packages.

[11bmca17@mcalab ~]$ apt-get install libc6


LAN card configuration procedure
-ifconfig command
The "ifconfig" command allows the operating system to setup network interfaces and
allow the user to view information about the configured network interfaces.
Syntax
ifconfig [-L] [-m] interface [create] [address_family] [address[/prefixlength]
[dest_address]] [parameters]
ifconfig interface destroy
ifconfig -a [-L] [-d] [-m] [-u] [address_family]
ifconfig -l [-d] [-u] [address_family]
ifconfig [-L] [-d] [-m] [-u] [-C]
Using the ifconfig command, you can determine whether your Ethernet (and other
network interfaces) are up and running. Type the following command:
# ifconfig
The output that appears is similar to the following:
eth0 Link encap:Ethernet HWaddr 00:90:27:4E:67:35
inet addr:10.0.0.10 Bcast:10.0.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:156 errors:0 dropped:0 overruns:0 frame:0

TX packets:104 errors:0 dropped:0 overruns:0 carrier:0


collisions:0 txqueuelen:100
RX bytes:20179 (19.7 Kb) TX bytes:19960 (19.4 Kb)
Interrupt:11 Base address:0xe000 Memory:ff8ff000-ff8ff038
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:3924 Metric:1
RX packets:56 errors:0 dropped:0 overruns:0 frame:0
TX packets:56 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3148 (3.0 Kb) TX bytes:3148 (3.0Kb)
In this example, two network interfaces are up on the current computer. The first
section
shows your Ethernet interface (eth0), and its Ethernet hardware address, IP address
(inet
addr), broadcast address, and netmask. The next lines provide information on packets
that
have been sent, along with the number of errors and collisions that have occurred.
If your eth0 interface does not appear, it may still be configured properly, but not
running at the moment. Try to start the eth0 interface by typing the following:
# ifconfig eth0 up
After this, type ifconfig again to see if eth0 is now running
ifconfig -a
Display info on all network interfaces on server, active or inactive.
ifconfig eth0 down
If eth0 exists would take it down causing it cannot send or receive any information.
ifconfig eth0 up
If eth0 exists and in the down state would return it back to the up state allowing to to
send and receive information.

ifconfig eth0 192.168.1.102 netmask 255.255.255.0 broadcast 192.168.1.255


Assign eth0 with the above values for IP, netmask and broadcast address.

Server configuration procedure-DHCP,DNS,FTP,Telnet,SSH,NFS

TELNET
1. You need to install xinetd and telnet-server:
[root@switchroot ~]# yum install xinetd telnet-server -y
Note: telnet is managed by xinetd in RedHat
2. Now open the file /etc/xinetd.d/telnet in your favourite text editor and change the
following line:
disable = yes
to read as:
disable = no
save and exit the file.
3. Restart the xinetd service:
[root@switchroot ~]# service xinetd restart
4. To make sure that the service remains running on next boot, run:
[root@switchroot ~]# chkconfig xinetd on
5. In case if you have firewall (iptables) running, then you need to open the port 23 for
the network from where you want to connect to server. For Example: To be able to
connect from 192.168.0.0/24 network on both tcp and udp port 23, following rules
might be appropriate for you:
[root@switchroot ~]# iptables -I INPUT -s 192.168.0.0/24 -p tcp --dport 23 -j ACCEPT
[root@switchroot ~]# iptables -I INPUT -s 192.168.0.0/24 -p udp --dport 23 -j
ACCEPT
6. Thats it. To test the telnet server, try connecting to it from remote machine with
following command:
[root@remote ~]# telnet 1.2.3.4
<prompt for username and password>

FTP

The File Transfer Protocol (FTP) is used as one of the most common means of copying
files between servers over the Internet.
Regular FTP
The VSFTP allows Linux users to copy files to and from their home directories
with an FTP client.
Anonymous FTP
Anonymous FTP a username of
anonymous and your email address for the
password.
Once logged in to a FTP server, you automatically have access to only the default
anonymous FTP directory

Start VSFTP

Use the chkconfig command to configure VSFTP to start at boot:


chkconfig vsftpd on
Use service vsftpd to start,stop, and restart VSFTP after booting:
service vsftpd start
service vsftpd stop
service vsftpd restart
Configuration file: /etc/vsftpd/vsftpd.conf

Anonymous FTP settings

Before going to change vsftpd.conf, remember to make a backup:


cp vsftpd.conf vsftpd.conf.bak
anonymous_enable=YES
Allow Anonymous
anon_upload_enable=YES
Allow Anonymous upload
anon_mkdir_write_enable=YES
Allow Anonymous upload to create directory
no_anon_password=YES
Do not ask password for anonymous login
anon_max_rate=30000
Limit the transfer rate of anonymous, e.g. 30000 = 30k byte per second
anon_root=/data/directory
Directory for anonymous is /var/ftp

Local users settings

local_enable=YES
Allow Linux users to use VSFTPD
chroot_list_enable=YES
VSFTPD will use a file to limit some users to change their home directories
after login
chroot_list_file=/etc/vsftpd/chroot_list

A text file which contain a list of Linux usernames.


These users will limit to their home directories

userlist_deny=YES
VSFTPD will use a file to reject some users.
userlist_file=/etc/vsftpd/user_list
A text file which contain a list of Linux usernames which DO NOT
allow to use VSFTP.
local_max_rate=30000
Limit the transfer rate of local user, e.g. 30000 = 30k byte per second

Other Settings

max_clients=10
Limiting the maximum number of client connections
max_per_ip=1
Limiting the number of connections by same IP address
idle_session_timeout=600
Disconnect the idle connection after 600 seconds.
xferlog_enable=YES
Record all the file transfer records.
xferlog_file=/var/log/vsftpd.log
Filename and directory of log file.

Limit the access on hosts


FTP server usually can use tcp_wrappers to allow or deny a hosts access.
Add this statement to vsftpd.conf:
tcp_wrappers = yes
Under /etc, create a new file hosts.deny:
If you want to allow a specific host, create a hosts.allow with same format.
Power of hosts.allow > hosts.deny
DNS
Setting Up a Domain Name System Server
The Domain Name System (DNS) is essentially a distributed database that translates
hostnames
into IP addresses (and IP addresses back to hostnames). That database also contains
information related to each domain, such as how the domain is organized into zones,
where to
route mail for that domain, and whom to contact with questions associated with the
domain
By setting up a DNS server, you become part of a hierarchy of DNS servers that make
up the
Internet. At the top of this hierarchy is the root server, represented by a dot (.). Below
the root

server are the Top Level Domains, or TLDs (such as .com, .org, and so on). Domains
that
individual organizations own and maintain lie below the TLDs, branching in a way that
looks
like an upside-down tree structure.
Understanding DNS
The basic function of a name server is to answer queries by providing the information
that
those queries request. A DNS name server primarily translates domain and hostnames
into IP
addresses. Each domain is typically represented by at least two DNS servers.
Primary (master) name server This name server contains the master copy of
authoritative information about the domains that it serves.
Secondary (slave) name server This name server gets all information for the
domain
from the primary name server.
DNS configuration files (named.conf file and named directory) The
/var/named/chroot/etc/named.conf file is where you add most of the general
configuration information that you need to define the DNS services for your domain.
DNS lookup tools : Used to check that your DNS server is
resolving hostnames properly. These include commands such as host, dig, and
nslookup (which are part of the bind-utils software package).
To maintain your DNS server correctly, you can also perform the following
configuration
tasks with your DNS server:
Logging You can indicate what you want to log and where log files reside.
Remote server options used to set options for specific DNS servers to perform such
tasks as blocking information from a bad server, setting encryption keys to use with a
server, or defining transfer methods.
Identifying your DNS servers
DNS server IP addresses (the static IP addresses of your DNS servers, probably primary
and slave)
DNS server hostnames (often ns1.yourdomain.com, where you replace
yourdomain.com with your domain name for the primary; the slave hostname is
ns2.yourdomain.com)
Creating DNS configuration files (named.conf and var/named)
In configuring a DNS server, youre actually creating definitions that apply to a
particular zone
in the public DNS tree, as well as several local zones that apply to your computer and
local

network. To create a useful DNS server for your example small-office environment,
you have
the following zones:
Public DNS server zone The DNS server is authoritative for the domain that
youre
serving. This zone serves the names and IP addresses for your public servers. In the
example named.conf file shown in the next section, you need to replace the name
yourdomain.com with the domain that youre creating. These records become
accessible
to everyone on the Internet.
Private DNS server zone So each computer on the private network doesnt need
to
know the IP addresses for other computers on your private network, a zone is added in
the example named.conf file to let the DNS server resolve these addresses. The names
and IP addresses (which are private) are available only to computers on your LAN.
Starting the named (DNS) daemon
To start the named daemon and see whether its working, type the following (as root
user):
# /etc/init.d/named start
To set the named daemon to start each time that the system
boots up, type the following:
# chkconfig named on
restart the named service (as root user) as follows:
# /etc/init.d/named restart
Checking that DNS is working
The host command to get the IP address for the host computer named blue in the
local
domain:
# host blue
blue.yourdomain.com has address 10.0.0.3
The dig command is used with a domain name to get information about the
addresses for a domain:
# dig yourdomain.com
The nslookup looks up the server that is resolving
ftp.yourdomain.com:
# nslookup -sil yourdomain.com
To check the status of your DNS server daemon:
# /etc/init.d/named status

NFS

Creating an NFS file server is an easy way to share large amounts of data among the
users and
computers in an organization. An administrator of a Linux system that is configured to
share
its file systems using NFS has to perform the following tasks to set up NFS:
1. Set up the network If a LAN or other network connection is already connecting
thecomputers on which you want to use NFS (using TCP/IP as the network transport),
youalready have the network you need.
2. On the server, choose what to share Decide which file systems on your Linux
NFS
server to make available to other computers.
3. On the server, set up security You can use several different security features to
suit
the level of security with which you are comfortable
4. On the client, mount the file system Each client computer that is allowed access
to
the servers NFS shared file system can mount it anywhere the client chooses. For
example, you may mount a file system from a computer called oak on the /media/oak
directory in your local file system.
Sharing NFS file systems:
To share an NFS file system from your Linux system, you need to export it from the
server
system. Exporting is done in Fedora and Red Hat Enterprise Linux by adding entries
into the
/etc/exports file. Each entry identifies the directory in your local file system that you
want to share with other computers. The entry identifies the other computers that can
share the
resource (or opens it to all computers) and includes other options that reflect
permissions
associated with the directory.
Using the NFS Server Configuration window:
The NFS Server Configuration window (system-config-nfs command from the package
of the same name) allows you to share your NFS directories using a graphical interface.
Start
this window from the Desktop menu by clicking System-> Administration >Server Settings
-> NFS. (If it's not there, type yum install system-config-nfs to install it.)
To share a directory with the NFS Server Configuration window, do the following:
1. From the NFS Server Configuration window, click File -> Add Share. The Add NFS

Share window appears,


2. In the Add NFS Share window Basic tab, enter the following information:
Directory
Host(s)
Basic permissions
3. Click the General Options tab. This tab lets you add options that define how the
shared
directory behaves when a remote host connects to it (mounts it):
Allow connections from ports 1024 and higher
Allow insecure file locking
Disable subtree checking
Sync write operations on request
Force sync of write operations immediately
Hide filesystems beneath
Export only if mounted
Configuring the /etc/exports file:
The shared directory information you entered into the NFS Server Configuration
window is
added to the /etc/exports file. As root user, you can use any text editor to configure the
/etc/exports file to modify shared directory entries or add new ones. Heres an example
of
an /etc/exports file, including some entries that it could include:
/cal *.linuxtoys.net(rw,sync) # Company events
/pub (ro,insecure,all_squash) # Public dir
/home maple(rw,squash uids=0-99) spruce(rw,squash uids=0-99)
/cal Represents a directory that contains information about events related to the
company.
/pub Represents a public directory. It allows any computer and user to read files
from
the directory (indicated by the ro option), but not to write files.
/home This entry enables a set of users to have the same /home directory on
different computers.
Security options that you can add to your /etc/exports
file are described throughout the sections that follow.
The format of the /etc/exports file is:
Directory Host(Options) # Comments
Exporting the shared file systems:
After you have added entries to your /etc/exports file, you can actually export the

directories listed using the exportfs command. If you reboot your computer or restart
the
NFS service, the exportfs command is run automatically to export your directories.
However, if you want to export them immediately, you can do so by running exportfs
from
the command line (as root).
Heres an example of the exportfs command:
# /usr/sbin/exportfs -a -v
exporting maple:/pub
exporting spruce:/pub
exporting maple:/home
exporting spruce:/home
exporting *:/media/win
The -a option indicates that all directories listed in /etc/exports should be exported. The
-v option says to print verbose output. In this example, the /pub and /home directories
from
the local server are immediately available for mounting by those client computers that
are
named (maple and spruce). The /media/win directory is available to all client
computers.
Running the exportfs command makes your exported NFS directories immediately
available. Any changes to your /etc/export file will be used again the next time you
reboot or otherwise restart the NFS service.
Starting the nfsd daemons:
For security purposes, the NFS service is turned off by default on your Fedora or RHEL
system. You can use the chkconfig command to turn on the NFS service so that your
files
are exported and the nfsd daemons are running when your system boots.
There are two startup scripts you want to turn on for the NFS service to work properly.
The
nfs service exports file systems (from /etc/exports) and starts the nfsd daemon that
listens for service requests. The nfslock service starts the lockd daemon, which helps
allow
file locking to prevent multiple simultaneous use of critical files over the network.
You can use the chkconfig command to turn on the nfs service by typing the following
commands (as root user):
# chkconfig nfs on
The next time you start your computer, the NFS service will start automatically and
your

exported directories will be available. If you want to start the service immediately,
without
waiting for a reboot, you can type the following:
# /etc/init.d/nfs start
The NFS service should now be running and ready to share directories with other
computers
on your network.
Using autofs to mount NFS file systems on demand:
The following steps explain how to turn on the autofs facility:
1. As root user from a Terminal window, open the /etc/auto.master file and look for a
line that appears as follows:
/net -hosts
This causes the /net directory to act as the mount point for the NFS shared directories
you want to access on the network. (If there is a comment character at the beginning of
that line, remove it.)
2. Start the autofs service by typing the following as root user:
# service autofs start
3. Set up the autofs service to restart every time you boot your system:
# chkconfig autofs on
Believe it or not, thats all you have to do. Provided that you have a network
Unmounting NFS file systems:
After an NFS file system is mounted, unmounting it is simple. You use the umount
command
with either the local mount point or the remote file system name. For example, here are
two
ways you could unmount maple:/home/chris/files from the local directory
/media/maple:
# umount maple:/home/chris/files
# umount /media/maple
Either form will work. If maple:/home/chris/files is mounted automatically

DHCP
Setting Up a DHCP Boot Server
The Dynamic Host Configuration Protocol (DHCP) is a standardized
networking protocol used by servers on an IP network to allocate IP addresses to
computers. The purpose of DHCP is to automate the IP address configuration of a
computer without a network administrator. IP addresses are typically selected from a
range of assigned IP addresses stored in a database on the server and issued to a
computer which requests a new IP address.

For setting up a DHCP Boot Server:


Using Dynamic Host Configuration Protocol (DHCP)
Setting up a DHCP server
Setting up a DHCP client
Using Dynamic Host Configuration Protocol
Setting up a DHCP server enables you to centrally manage the addresses and
other network information for client computers on your private network.With DHCP,
you can greatly simplify the initial network configuration that each client computer on
your network needs to do.
Setting Up a DHCP Server
To configure a DHCP server you need to install the dhcp package.
working are:
A firewall that allows requests for DHCP service
A configured /etc/dhcpd.conf file
A running dhcpd server daemon (which can be started at boot time)
After the DHCP server is running, it listens to UDP port 67 for requests from DHCP
clients on the LAN.
Opening your firewall and SELinux for DHCP
The firewall on your DHCP server must be configured to allow access to UDP ports 67
and 68. Type the following as root user:
# iptables -I INPUT -i eth0 -p udp --sport 67:68 --dport 67:68 -j ACCEPT
DHCP uses the UDP protocol (-p udp). If your DHCP server is also a routing firewall
for your network.To change your firewall, type the following (as root user):
# service iptables save
To restore those firewall settings without rebooting, use the iptables-restore command:
# iptables-restore < /etc/sysconfig/iptables
Configuring the /etc/dhcpd.conf file
ddns-update-style interim;
ignore client-updates;
subnet 10.0.0.0 netmask 255.255.255.0 {
option routers 10.0.0.1;
option domain-name-servers 10.0.0.1;
The DHCP server is serving a single LAN, represented by a 10.0.0.0 network
address with a 255.255.255.0 netmask. Other data in this file define what information
the DHCP server
will hand out to clients on this LAN.
Starting the DHCP server
After the /etc/dhcpd.conf file is configured, you can start the DHCP server immediately.
As root user from a Terminal window, type the following:
# service dhcpd start

Your DHCP server should now be available to distribute information to the


computers on your LAN. If there are client computers on your LAN waiting on your
DHCP server, their network interfaces should now be active.
If everything is working properly, you can have your DHCP server start
automatically each time your computer boots by turning on the dhcpd service as
follows:
# chkconfig dhcpd on
Setting Up a DHCP Client
Configuring a network client to get addresses from your DHCP server is fairly easy.
Different types of operating systems, however, have different ways of using DHCP.
Here are examples for setting up Windows and Linux DHCP clients.
Windows (Vista)
Windows (95, 98, 2000, or XP)
Fedora/RHEL

SSH
Using ssh for remote login/remote execution
Although the telnet and rlogin login commands and rsh remote execution command
have been around much longer, the ssh command is the preferred tool for remote logins
and
executions. The reason is that ssh provides encrypted communication so you can use it
securely over insecure, public networks between hosts that dont know each other.
ssh is being used to log in to a computer named maple, no user is specified, ssh tries to
log in as the current user. to log in as a different user, you could use the -l option.
Eg: # ssh maple
root@maple's password
to log into the computer named maple as the user named jake
Eg: # ssh jake@maple
jake@maple's password:
The ssh command can also be used to execute a command on the remote computer. For
example, if you wanted to monitor the messages file on a remote computer for a
minute, you
could type the following command:
# ssh root@maple "tail -f /var/log/messages"
root@maple's password:
After you typed the password in the preceding case, the last several lines of the
/var/log/messages file on the remote computer would be displayed. As messages were

received, they would continue to be displayed until you decided to exit (press Ctrl+C to
exit
the tail command).
Using the ssh commands
Three commands you can use with the SSH service are ssh, sftp, and scp. Remote users
use the ssh command to log in to your system securely. The scp command lets remote
users
copy files to and from a system. The sftp command provides a safe way to access FTP
sites.
To test the SSH service from another computer on which SSH has been installed (or
even from the same computer if another is not available), type the ssh command
followed by a space and the name of the system you are connecting to. For example, to
connect to the system ratbert.glaci.com, type:
$ ssh ratbert.glaci.com
If you don't specify a user name when you start the ssh connection, the SSH daemon
assumes
you want to use the user name you are logged in as from the client. If you want to log in
as a
different user name (such as chris, for example), you could type the following:
$ ssh chris@ratbert.glaci.com
or
$ ssh -l chris ratbert.glaci.com

SHELL SCRIPTS

PROGRAM NO: 01
DATE: 15/10/13
AIM:Write a shell script to accept a string and display the same.

[12amca30@mcalab ~]$ cat pgm1.sh


echo "enter a string"
read n
echo "the string is $n"
[12amca30@mcalab ~]$ bash pgm1.sh
enter a string
vincy g
the string is vincy g

PROGRAM NO: 02
DATE: 15/10/13
AIM:Write a shell script to check whether an inputted number is odd or even and display the
corresponding message.

[12amca30@mcalab ~]$ cat odds.sh

echo "enter a number"


read n
((x=n%2))
if [ $x -eq 0 ]
then
echo "$n is even"
else
echo "$n is odd"
fi
OUTPUT

[12amca30@mcalab ~]$ bash odds.sh


enter a number
5
5 is odd
[12amca30@mcalab ~]$ bash odds.sh
enter a number
36
36 is even

PROGRAM NO: 03
DATE: 17/10/13
AIM:Write a shell script to find the factorial of a number.
[12amca30@mcalab ~]$ cat facts.sh
echo "enter a number"
read n
f=1
for ((i=1;i<=$n;i++))
do
((f=f*i))
done
echo "the factorial of $n is $f"
[12amca30@mcalab ~]$ bash facts.sh
enter a number
4
the factorial of 4 is 24
[12amca30@mcalab ~]$ bash facts.sh
enter a number
3
the factorial of 3 is 6

PROGRAM NO: 04
DATE: 19/10/13
AIM:Write a shell script to print the sum of digits of a given number.
[12amca30@mcalab ~]$ cat sum.sh
echo "enter a number"
read n
s=0
while [ $n -gt 0 ]
do
((r=n%10))
((s=s+r))
((n=n/10))
done
echo "sum of digits is $s"
[12amca30@mcalab ~]$ bash sum.sh
enter a number
153
sum of digits is 9
[12amca30@mcalab ~]$ bash sum.sh
enter a number
36
sum of digits is 9
[12amca30@mcalab ~]$ bash sum.sh
enter a number
32
sum of digits is 5

PROGRAM NO: 05
DATE: 28/10/13
AIM:Write a shell script to check whether a given year is leap year or not.
[12amca30@mcalab ~]$ cat leap.sh
echo "enter an year"
read y
if (( (( $y % 4 ==0 )) && (( $y %100 !=0 )) )) || (( $y % 400 ==0 ))
then
echo "$y is a leap year"
else
echo "$y is not a leap year"
fi

[12amca30@mcalab ~]$ bash leap.sh


enter an year
2000
2000 is a leap year
[12amca30@mcalab ~]$ bash leap.sh
enter an year
2001
2001 is not a leap year

PROGRAM NO: 06
DATE: 28/10/13
AIM:Write a shell script to check whether a given string is palindrome or not.
[12amca30@mcalab ~]$ cat pal.sh
echo "enter a string"
read n
len=`echo $n|wc -c`
((x=len-1))
((y=x/2))
i=1
j=1
while [ $j -le $y ]

do
a=`echo $n|cut -c $j`
b=`echo $n|cut -c $x`
if [ $a != $b ]
then
f=1
echo "$n is not a palindrome"
break
else
((j=j+1))
((x=x-1))
f=0
fi
done
if [ $f -eq 0 ]
then
echo "$n is a palindrome"
fi

[12amca30@mcalab ~]$ bash pal.sh


enter a string
malayalam
malayalam is a palindrome
[12amca30@mcalab ~]$ bash pal.sh
enter a string
popy
popy is not a palindrome

PROGRAM NO: 07
DATE: 30/10/13
AIM:Write a shell script to print the contents of a file from a given line number to next given
line number.
[12amca30@mcalab ~]$ cat f14
cat
mat
hai this is me.
hello
how are you
are you fine
men in black
popy
twinkle
god
st
jude

[12amca30@mcalab ~]$ cat lin.sh

echo "enter the line numbers you preffer to view"


read a
read b
head -n $b< f14 >f15
((x=b-a+1))
tail -n $x <f15 >f18
cat f18

[12amca30@mcalab ~]$ bash lin.sh


enter the line numbers you preffer to view
4
8
hello
how are you
are you fine
men in black
popy

PROGRAM NO: 08
DATE: 30/10/13
AIM: Write shell script using for loop to print the following patterns on screen
a)

*
*
*
*

*
*
*

*
*

[12amca30@mcalab ~]$ cat stars.sh


echo "enter the number of rows"
read n
for ((i=1;i<=$n;i++))
do
for ((j=1;j<=$i;j++))
do
echo -n "*"
done

echo ""
done

[12amca30@mcalab ~]$ bash stars.sh


enter the number of rows
4
*
**
***
****

PROGRAM NO: 09
DATE: 2/11/13
AIM: Write a shell script to print nos as 5,4,3,2,1 using while loop.
[12amca30@mcalab ~]$ cat num.sh
echo "the numbers are"

i=5
while [ $i -gt 0 ]
do
echo $i
((i=i-1))
Done
[12amca30@mcalab ~]$ bash num.sh
the numbers are
5
4
3
2
1

PROGRAM NO: 10
DATE: 5-11-13

AIM: Write a shell script, using case statement to perform basic math operation .
[12amca30@mcalab ~]$ cat maths.sh
echo "enter 2 numbers"
read a
read b
i=1
while [ $i -eq 1 ]
do
echo " 1. addition 2. substraction 3.multiply 4. division 5. exit"
echo "enter your choice"
read s
case $s in
1)

echo "sum is"


echo "$a + $b"|bc -l
;;

2)

echo "difference is"


echo "$a - $b"|bc -l
;;

3)

echo "product is "


echo "$a * $b"|bc -l
;;

4)

echo "quotient is"


echo "$a / $b"|bc -l
;;

5)

echo "exit"

i=5
;;
esac
done

[12amca30@mcalab ~]$ bash maths.sh


enter 2 numbers
4.5
2.5
1. addition 2. substraction 3.multiply 4. division 5. exit
enter your choice
1
sum is
7.0
1. addition 2. substraction 3.multiply 4. division 5. exit
enter your choice
2
difference is
2.0
1. addition 2. substraction 3.multiply 4. division 5. exit
enter your choice
3
product is
11.25

1. addition 2. substraction 3.multiply 4. division 5. exit


enter your choice
4
quotient is
1.80000000000000000000
1. addition 2. substraction 3.multiply 4. division 5. exit
enter your choice
5
Exit

PROGRAM NO :11
DATE

:6-11-13

AIM

: Write a program to print all prime numbers from 1 to 300.

[12amca30@mcalab ~]$ cat primes.sh


echo "the prime numbers are"
for((i=1;i<=300;i++))
do

c=0
for((j=1;j<=i;j++))
do
((x=i%j))
if [ $x -eq 0 ]
then
((c=c+1))
fi
done
if [ $c -eq 2 ]
then
echo -n " $i "
fi
done
echo ""

[12amca30@mcalab ~]$ bash primes.sh


the prime numbers are
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73
79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163
167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251
257 263 269 271 277 281 283 293

PROGRAM NO :12
DATE
AIM
loops.

:6-11-13
: Write a program to generate all combinations of 1, 2 and 3 using for

[12amca30@mcalab ~]$ cat num1.sh


echo "the combinations are"
for ((i=1;i<=3;i++))
do
echo -n $i
for ((j=1;j<=3;j++))
do
if [ $i -ne $j ]
then
echo -n $j
fi
done
echo ""
done
for ((i=1;i<=3;i++))
do
echo -n $i
for ((j=3;j>=1;j--))
do
if [ $i -ne $j ]
then
echo -n $j
fi
done
echo ""
done

[12amca30@mcalab ~]$ bash num1.sh


the combinations are
123
213
312
132
231
321

echo "COMBINATIONS OF 123"


for (( i=1;i<=3;i=i+1 ))
do
echo -n " $i "
for (( j=1;j<=3;j=j+1 ))
do
if [ $j -eq $i ]
then
continue
else
echo -n " $j "
fi
done
echo " "
echo -n " $i "
for (( j=3;j>=1;j-- ))
do
if [ $j -eq $i ]
then
continue
else
echo -n " $j "
fi
done
echo " "
done
OUTPUT

COMBINATIONS OF 123
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
PROGRAM NO :13
DATE

:7-11-13

AIM
: A file called wordfile consists of several words. Write a shell script which
will receive a list of filenames, the first of which would bewordfile. The shell script
should report all occurrences of each word in wordfile in the rest of the files supplied as
arguments.
echo "occurance of words"
for arg in `cat $1`
do
count=0
for j in `cat $2`
do
if [ $arg = $j ]
then
((count=$count+1))
fi
done
echo $arg ...$count
done
OUTPUT
[11bmca17@mcalab linexpgms]$ cat wordfile

vb
c++
java
linux
python
[11bmca17@mcalab linexpgms]$ cat f2
java
c++
c
python

[11bmca17@mcalab linexpgms]$ bash pgm3.sh wordfile f2


occurance of words
vb ...0
c++ ...1
java ...1
linux ...0
python ...1

PROGRAM NO :14
DATE

:12-11-13

AIM
: Write a shell script which deletes all lines containing the word unix in
the files supplied as arguments to this shell script.
[12amca30@mcalab ~]$ cat nn1.sh
echo "contents of exsisting file"
cat hh1
grep -v "unix" hh1 > hh2
cp hh2 hh1
echo "contents in new file"
cat hh1
cat hh2

[12amca30@mcalab ~]$ bash nn1.sh


contents of exsisting file
403 unix and linux
unix used as a reference now

currently linux is used

contents in new file


currently linux is used

currently linux is used

PROGRAM NO :15
DATE

:12-11-13

AIM
: The word unix is present in only some of the files supplied as
arguments to the shell script. Your shell script should search each of these files in turn
and stop at the first file that it encounters containing the word unix . this filename
should be displayed on the screen.
for arg in $*
do
echo $arg
grep "unix" $arg > temp
if [ -s temp ]
then

echo "First file containing word unix is $arg"


break
fi
done
OUTPUT
[11bmca17@mcalab linexpgms]$ bash pgm5.sh fi2 fi1
fi2
fi1
First file containing word unix is fi1

PROGRAM NO :16
DATE

:13-11-13

AIM
: A shell script receives even numbers of filenames. Suppose four
filenames are supplied then the first file should get copied into second file, the third file
should get copied into fourth file, and so on. If odd number of filenames are supplied then
no copying should take place and an error message should be displayed.
arg=$#
(( b=$arg%2 ))
if [ $b -eq 0 ]
then
cp $1 $2
cp $3 $4

echo "coping files"


echo "contents of file 1"
cat a1
echo "contents of file 2"
cat a2
echo "contents of file 3"
cat a3
echo "contents of file 4"
cat a4
else
echo "operation is only performed on even number of files"
fi

OUTPUT
[11bmca17@mcalab linexpgms]$ bash evenfile.sh a1 a2 a3 a4
coping files
contents of file 1
U C college
contents of file 2
U C college
contents of file 3
M C A Department
contents of file 4
M C A Department

PROGRAM NO :17
DATE

:13-11-13

AIM
: Write a shell script which displays a list of all files in the current
directory to which you have read,write and execute permissions.
[12amca30@mcalab ~]$ cat ex.sh
ls -l|grep "^-rwx"|tr -s " "|cut -d " " -f9

[12amca30@mcalab ~]$ bash ex.sh


cibdfy.tmp
class
Documents.lnk

DrvMon.{645FF040-5081-101B-9F08-00AA002F954E}.lnk
Music.lnk
New
New
Passwords.lnk
Pictures.lnk
st.jude.lnk
Video.lnk
VINCY.lnk
vin.sh

PROGRAM NO :18
DATE

:15-11-13

AIM
: Write a shell script which will receive any number of filenames as
arguments. The shell script should check whether every argument supplied is a file or a
directory. If it is a directory it should be appropriately reported. If it is a filename then
name of the file as well as the number of lines
present in it should be reported.

i=1
for arg in $*
do
if [ -f $arg ]
then
echo "number of lines in file and its name which is given as argument $i is:"
wc -l $arg
else
echo "$arg is a directory "
fi
((i=i+1))
Done
OUTPUT
[11bmca17@mcalab linexpgms]$ bash checking.sh dir1 uc mca
dir1 is a directory
number of lines in file and its name which is given as argument 2 is:
2 uc
number of lines in file and its name which is given as argument 3 is:
2 mca

PROGRAM NO :19
DATE

:15-11-13

AIM
: Write a shell script which will receive any numbers of filenames as
arguments. The shell script should check whether such files already exist. If they do, then
it should be reported. If these files do not exist then check if a sub-directory called mydir
exists in the current directory. If it doesnt exist then it should be created and in it the

files supplied as arguments should get created. If mydir already exists then it should be
reported along with the number of files that are currently present in mydir.
for arg in $*
do
if [ -f $arg ]
then
echo "$arg is a file"
elif [ -d "mydir" ]
then
f=1
echo "Directory named mydir exists"
cd mydir
if [ -f $arg ]
then
echo "$arg is in this directory"
else
echo "File $arg created"
touch $arg
fi
else
mkdir mydir
cd mydir
echo "File $arg created"
touch $arg
fi

done
if [ $f -eq 1 ]
then
echo "Number of files in this directory"
ls > t
wc -l t
fi
OUTPUT
[11bmca17@mcalab linexpgms]$ bash checking2.sh mca uc dir1
mca is a file
uc is a file
Directory named mydir exists
dir1 is in this directory
Number of files in this directory
3t

PROGRAM NO :20
DATE

:15-11-13

AIM

: Write a shell script to print given number in reverse order.

[12amca30@mcalab ~]$ cat rev.sh


echo "enter a number"
read n
s=0
while [ $n -gt 0 ]
do
((r=n%10))
((s=s*10+r))
((n=n/10))
done
echo "the reverse is $s"

[12amca30@mcalab ~]$ bash rev.sh


enter a number
361
the reverse is 163

PROGRAM NO :21
DATE

:17-11-13

AIM

: Construct pipes to carry out the following jobs

a) List all files beginning with the character P on the screen and also store them in a
file called file1
[12amca30@mcalab ~]$ ls -l [p]* > FILE1
[12amca30@mcalab ~]$ cat FILE1
-rw-rw-r-- 1 12amca30 12amca30 297 Oct 27 18:09 pal.sh
-rw-rw-r-- 1 12amca30 12amca30 53 Oct 23 18:47 pgm1.sh
-rw-rw-r-- 1 12amca30 12amca30

9 Aug 21 17:04 popy2

-rw-rw-r-- 1 12amca30 12amca30 112 Sep 18 14:39 pos.sh


-rw-rw-r-- 1 12amca30 12amca30 183 Oct 27 19:16 primes.sh

popy:
total 0

popy1:

total 4
drwxrwxr-x 2 12amca30 12amca30 4096 Oct 7 15:09 popy2

b) List all files beginning with the character P on the screen twice in succession.
[12amca30@mcalab ~]$ ls -l [p]* | tee b|tee /dev/pts/11
-rw-rw-r-- 1 12amca30 12amca30 297 Oct 27 18:09 pal.sh
-rw-rw-r-- 1 12amca30 12amca30 53 Oct 23 18:47 pgm1.sh
-rw-rw-r-- 1 12amca30 12amca30 9 Aug 21 17:04 popy2
-rw-rw-r-- 1 12amca30 12amca30 112 Sep 18 14:39 pos.sh
-rw-rw-r-- 1 12amca30 12amca30 183 Oct 27 19:16 primes.sh
popy:
total 0
popy1:
total 4
drwxrwxr-x 2 12amca30 12amca30 4096 Oct 7 15:09 popy2
-rw-rw-r-- 1 12amca30 12amca30 297 Oct 27 18:09 pal.sh
-rw-rw-r-- 1 12amca30 12amca30 53 Oct 23 18:47 pgm1.sh
-rw-rw-r-- 1 12amca30 12amca30 9 Aug 21 17:04 popy2

-rw-rw-r-- 1 12amca30 12amca30 112 Sep 18 14:39 pos.sh


-rw-rw-r-- 1 12amca30 12amca30 183 Oct 27 19:16 primes.sh
popy:
total 0
popy1:
total 4
drwxrwxr-x 2 12amca30 12amca30 4096 Oct 7 15:09 popy2

c) Output of who should be sorted and displayed on the screen along with the total
no of users. The same Output except the no of users should also be sorted in a file
file1.
[12amca30@mcalab ~]$ who | sort -d | tee file87 | wc -l
29
[12amca30@mcalab ~]$ cat file87
10amca21 pts/8
2014-10-28 18:41 (192.168.101.60)
11amca23 pts/28
2014-10-28 19:14 (192.168.101.59)
12amca01 pts/5
2014-10-28 18:45 (192.168.101.31)
12amca02 pts/21
2014-10-28 18:30 (192.168.101.33)
12amca05 pts/26
2014-10-28 18:32 (192.168.101.34)
12amca06 pts/22
2014-10-28 18:53 (192.168.101.35)
12amca07 pts/20
2014-10-28 18:30 (192.168.101.36)
12amca10 pts/9
2014-10-28 16:38 (192.168.101.211)
12amca11 pts/18
2014-10-28 19:10 (192.168.101.40)
12amca12 pts/23
2014-10-28 18:32 (192.168.101.41)
12amca13 pts/27
2014-10-28 18:34 (192.168.101.42)
12amca14 pts/2
2014-10-28 17:59 (192.168.101.43)
12amca15 pts/10
2014-10-28 19:12 (192.168.101.44)
12amca16 pts/6
2014-10-28 18:18 (192.168.101.45)
12amca17 pts/15
2014-10-28 18:19 (192.168.101.91)
12amca18 pts/3
2014-10-28 16:36 (192.168.101.128)
12amca19 pts/4
2014-10-28 18:49 (192.168.101.48)
12amca20 pts/24
2014-10-28 18:55 (192.168.101.38)
12amca22 pts/7
2014-10-28 16:37 (192.168.101.51)
12amca23 pts/17
2014-10-28 18:28 (192.168.101.208)

12amca24 pts/14
12amca25 pts/12
12amca26 pts/16
12amca27 pts/13
12amca27 pts/29
12amca29 pts/1
12amca30 pts/11
12amca31 pts/25
12amca32 pts/19

2014-10-28 18:19 (192.168.101.186)


2014-10-28 18:19 (192.168.101.54)
2014-10-28 18:21 (192.168.101.55)
2014-10-28 18:45 (192.168.101.56)
2014-10-28 19:11 (192.168.101.56)
2014-10-28 18:50 (192.168.101.131)
2014-10-28 16:41 (192.168.101.58)
2014-10-28 18:43 (192.168.101.50)
2014-10-28 18:30 (192.168.101.32)

d)Merge the contents of the files a.txt, b.txt, c.txt, sort them and disply the sorted Output
on the screen page by page.

[12amca30@mcalab ~]$ sort a b c

always
bye
god
hai
is
joy
jude
leenama
pop
popy
roy
st
us
with
[11bmca17@mcalab ~]$ sort a b c
A
B

C
D
E
F
K
L
M
N
O
S
T
U
V
W
X
e)Display the list of last 20 files in current directory. Also store this list in a file profile.
[11bmca17@mcalab ~]$ ls | tail -20 > profile
[11bmca17@mcalab ~]$ cat profile
LF
Linux Administration Handbook 2nd Edition.pdf
LINUXLABCYCLE.docx
m11
m22
m33
m44
mydir
numprint.sh
p1
p19.sh
p2
p22.sh
p3
pfile
printf.sh
profile
sal.py
sal.sh
t

PROGRAM NO :22
DATE

:18-11-13

AIM

: Write a shell script to calculate the gross salary of an

employee.If basic salary is > =3000, DA=11% of BS, HRA=4% of BS and if


basic salary <3000, DA=4% of BS, HRA=10% of BS.Display employee
name, basic salary, DA, HRA and Gross salary.
echo "Enter the name of the employee"
read name
echo "Enter the basic salary of the employee"
read bs
if [ $bs -ge 3000 ]
then
da= ` echo "$bs*0.11" | bc `
hra=` echo "$bs*0.04" | bc`
else
da=` echo "$bs*0.04" | bc`
hra=` echo "$bs*0.10" | bc `

fi
gs=` echo "$bs+$da+$hra" | bc`
echo " Name
:$name"
echo " Basic Salary :$bs"
echo " DA
:$da"
echo " HRA
:$hra"
echo " Gross Salary :$gs"

OUTPUT
[11bmca17@mcalab ~]$ bash emplo.sh
Enter the name of the employee
aswathy
Enter the basic salary of the employee
6000
Name
:a
Basic Salary :6000
DA
:660.00
HRA
:240.00
Gross Salary :6900.00

You might also like