0% found this document useful (0 votes)
55 views79 pages

Linux Final

The document describes the 11 step procedure for installing Linux Ubuntu 10.04 LTS as a standalone operating system. It involves booting from the Ubuntu installation CD, selecting language and location, configuring the keyboard, partitioning disks to specify swap and root file systems, creating a user account, installing the boot loader, and restarting for first use. Basic Linux commands are also outlined including file management commands like mkdir, cd, ls as well as disk usage commands like df and du.

Uploaded by

Shalu saju
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
55 views79 pages

Linux Final

The document describes the 11 step procedure for installing Linux Ubuntu 10.04 LTS as a standalone operating system. It involves booting from the Ubuntu installation CD, selecting language and location, configuring the keyboard, partitioning disks to specify swap and root file systems, creating a user account, installing the boot loader, and restarting for first use. Basic Linux commands are also outlined including file management commands like mkdir, cd, ls as well as disk usage commands like df and du.

Uploaded by

Shalu saju
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 79

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
a 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
-bash-3.2$ cat newfile
hello
-bash-3.2$ cat newfile2
how are u?

-bash-3.2$ cmp newfile newfile2


newfile newfile2 differ: byte 2, line 1
b)diff
Displays two files and prints the lines that are different.
-bash-3.2$ diff newfile newfile2
1c1,2
< hello
---
> how are u?
Disk related commands
a) du
Tells you how much space a file occupies

-bash-3.2$ cd linexpgms
-bash-3.2$ du
8 ./mydir/mydir/mydir
12 ./mydir/mydir
20 ./mydir
4 ./dir1
228 .
b)df
Report how much free disk space is available for each mount you have.
-bash-3.2$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 5952284 4593480 1051564 82% /
/dev/sda5 109109796 102180468 1297344 99% /home
/dev/sda1 988088 25524 911560 3% /boot
tmpfs 969368 0 969368 0% /dev/shm
c)dfspace
Report how much free disk space is available for each mount you have.
-bash-3.2$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 5.7G 4.4G 1013M 82% /
/dev/sda5 105G 98G 1.3G 99% /home
/dev/sda1 965M 25M 891M 3% /boot
tmpfs 947M 0 947M 0% /dev/shm
d) ulimit
Sets or reports user resource limits.
-bash-3.2$ 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

b) batch
Runs jobs when the system load level permits.
-bash-3.2$batch <<!
longjob
!
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.
-bash-3.2$ ps
PID TTY TIME CMD
3090 pts/24 00:00:00 bash
16449 pts/24 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.
-bash-3.2$ kill -9 3090
c) nice
Invokes a command with an altered scheduling priority
-bash-3.2$ nice -n 5 who
root :0 2013-12-12 12:05
11bmca15 pts/1 2013-12-12 14:42 (192.168.101.66)
11bmca27 pts/2 2013-12-12 14:42 (192.168.101.82)
11bmca21 pts/3 2013-12-12 14:43 (192.168.101.65)
11bmca02 pts/4 2013-12-12 14:43 (192.168.101.79)
11bmca18 pts/5 2013-12-12 14:43 (192.168.101.63)
11bmca29 pts/6 2013-12-12 14:43 (192.168.101.83)
11bmca19 pts/7 2013-12-12 14:58 (192.168.101.162)
11bmca04 pts/8 2013-12-12 14:45 (192.168.101.77)
11bmca28 pts/9 2013-12-12 14:49 (192.168.101.84)
11bmca26 pts/10 2013-12-12 14:45 (192.168.101.85)
d) bg
Continues a stopped job in the background. This function is not available on all Unix
shell's.
-bash-3.2$ bg
-bash: bg: current: no such job
e) who
Displays who is on the system
-bash-3.2$ who
root :0 2013-12-12 12:05
11bmca15 pts/1 2013-12-12 14:42 (192.168.101.66)
11bmca27 pts/2 2013-12-12 15:01 (192.168.101.82)
11bmca21 pts/3 2013-12-12 14:43 (192.168.101.65)
11bmca02 pts/4 2013-12-12 14:43 (192.168.101.79)
11bmca18 pts/5 2013-12-12 14:43 (192.168.101.63)
11bmca19 pts/7 2013-12-12 14:58 (192.168.101.162)
11bmca04 pts/8 2013-12-12 14:45 (192.168.101.77)
11bmca28 pts/9 2013-12-12 14:49 (192.168.101.84)
11bmca26 pts/10 2013-12-12 14:45 (192.168.101.85)
11bmca03 pts/11 2013-12-12 14:45 (192.168.101.78)
11bmca16 pts/12 2013-12-12 14:45 (192.168.101.67)
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.
-bash-3.2$ 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.
-bash-3.2$ top
top - 15:24:24 up 3:36, 27 users, load average: 3.44, 3.55, 4.25
Tasks: 320 total, 2 running, 304 sleeping, 14 stopped, 0 zombie
Cpu(s): 17.1%us, 37.9%sy, 0.0%ni, 44.4%id, 0.1%wa, 0.1%hi, 0.4%si, 0.0%st
Mem: 1938736k total, 1646908k used, 291828k free, 315208k buffers
Swap: 2048276k total, 0k used, 2048276k free, 1037988k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND


31320 11bmca01 25 0 4496 1136 1004 S 3.0 0.1 2:06.16 bash
21258 nobody 15 0 17824 5704 3584 S 2.3 0.3 0:06.96 smbd
8092 11bmca01 25 0 4488 1004 888 S 1.7 0.1 1:22.38 bash
22007 root 15 0 18120 6256 3792 S 1.0 0.3 0:05.96 smbd
919 11bmca17 15 0 2448 1156 800 R 0.7 0.1 0:00.12 top
2864 root 15 0 9464 1352 872 S 0.3 0.1 0:12.61 nmbd
4933 11bmca01 25 0 4216 796 692 R 0.3 0.0 0:00.01 ps
6991 12amca30 15 0 18012 6156 3728 S 0.3 0.3 0:08.01 smbd
25214 11bmca15 15 0 4672 1516 1236 S 0.3 0.1 0:00.06 bash
31792 12amca05 15 0 17956 5908 3568 S 0.3 0.3 0:29.89 smbd
1 root 15 0 2072 616 532 S 0.0 0.0 0:01.07 init
2 root RT -5 0 0 0 S 0.0 0.0 0:01.46 migration/0
3 root 34 19 0 0 0 S 0.0 0.0 0:01.42 ksoftirqd/0
4 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/0
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.
-bash-3.2$ exec
Printing commands:-
a) lpr
Submits print requests.
-bash-3.2$ lpr a
lpr: Error - no default destination available.
b) lpq
Lists the status of all the available printers.
-bash-3.2$ 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.
-bash-3.2$ wc -l newfile
1 newfile
-bash-3.2$ wc -c newfile
6 newfile
-bash-3.2$ wc -w newfile
1 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

-bash-3.2$ sort newfile


achu
aswathy
hello
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.
-bash-3.2$ cat f2
JUAN 14.25
GEORGE 21.11
ANNA 16.77
BEN 21.77
TUAN 8.77
-bash-3.2$ cut -d " " -f 2-3 f2
14.25
21.11
16.77
21.77
8.77
d) paste
Merge corresponding or subsequent lines of files.
-bash-3.2$ paste f2 > f3
-bash-3.2$ cat f3
JUAN 14.25
GEORGE 21.11
ANNA 16.77
BEN 21.77
TUAN 8.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.
-bash-3.2$ cat test1
1 india
2 us
3 uk
-bash-3.2$ cat test2
1 newdelhi
2 washington
3 london
-bash-3.2$ join test1 test2
1 india newdelhi
2 us washington
3 uk london
g) uniq
Report or filter out repeated lines in a file
-bash-3.2$ cat test
aa
aa
bb
cc
cc
-bash-3.2$ uniq test
aa
bb
cc
h) read
echo "enter a number"
read a
Mathematical commands
a) expr
Evaluate arguments as an expression
-bash-3.2$ a=10
-bash-3.2$ b=20
-bash-3.2$ c=`expr $a + $b`
-bash-3.2$ 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.
-bash-3.2$ x=10
-bash-3.2$ y=x
-bash-3.2$ echo '$'$y
$x
-bash-3.2$ eval echo '$'$y
10
c) bc
Calculator.
-bash-3.2$ echo $a + $b |bc
30
d) factor
Factors a number
-bash-3.2$ factor 21
21: 3 7
e) let
-bash-3.2$ let c=1*2
-bash-3.2$ echo $c
2
f) test
Checks file types and compares values.
-bash-3.2$ test 100 -lt 90 $$ echo "yes" || echo "no"
no
Filter commands
a) pr
Formats a file to make it look better when printed
-bash-3.2$ ls -a | pr -n -h "Files in $(pwd)"
2013-12-30 14:12 Files in /home/11bmca17/linexpgms Page 1
1 .
2 ..
3 a
4 a1
5 a2
6 a3
7 a4
8 armlimit.sh
9 arm.sh
10 armstrong.sh
11 b
12 bigno
13 .bigno.swp
14 checking2.sh
15 .checking2.sh.swp
16 checking.cs
17 checking.sh
18 combination.sh
19 comb.sh
20 dir1
21 evenfile.sh
b) head
Displays the first ten lines of a file, unless otherwise stated
-bash-3.2$ 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.
-bash-3.2$ tail -3 /etc/passwd
exam29:x:1002:1002::/home/exam29:/bin/bash
exam30:x:1003:1003::/home/exam30:/bin/bash
exam31:x:1004:1004::/home/exam31:/bin/bash
d) tr
Translate characters.
-bash-3.2$ 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.
-bash-3.2$ more -3 Ch6SIFI
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
-bash-3.2$ less -3 Ch6SIFI
1425 JUAN 14.25
4321 GEORGE 21.11
6781 ANNA 16.77
1451 BEN 21.77
2277 TUAN 8.77
Ch6SIFI (END)
Filter using regular expression
a) grep
Finds text within a file.
-bash-3.2$ grep hello
hai
hello
hello
b) egrep
Search a file for a pattern using full regular expressions.
-bash-3.2$ vi new_file
mca
ucc
semester4
-bash-3.2$ egrep "mca" new_file
mca
c) fgrep
Search a file for a fixed-character string
-bash-3.2$ fgrep "u" new_file
ucc
d)sed
Sort for Stream Editor sed allows you to use pre-recorded commands to make
changes to text.
-bash-3.2$ sed 's/mca/computer/g' new_file >n1
-bash-3.2$ 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
-bash-3.2$ mesg
is y
b) talk
Talk with other logged-in users.
-bash-3.2$ talk 11bmca16
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
-bash-3.2$ write 11bmca16
hai h ru?
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).
-bash-3.2$ wall good evng
-bash-3.2$
Broadcast message from 11bmca17 (pts/13) (Thu Dec 12 18:24:32 2013):

good evng
e) finger
Lists information about the user.
-bash-3.2$ finger 11bmca17
Login: 11bmca17 Name: (null)
Directory: /home/11bmca17 Shell: /bin/bash
On since Thu Dec 12 16:48 (IST) on pts/13 from 192.168.101.34
Mail last read Thu Dec 12 15:01 2013 (IST)
No Plan.
f) Ping
Sends ICMP ECHO_REQUEST packets to network hosts.
-bash-3.2$ ping 192.168.101.84
PING 192.168.101.84 (192.168.101.84) 56(84) bytes of data.
64 bytes from 192.168.101.84: icmp_seq=1 ttl=128 time=0.300 ms
64 bytes from 192.168.101.84: icmp_seq=2 ttl=128 time=0.276 ms
64 bytes from 192.168.101.84: icmp_seq=3 ttl=128 time=0.191 ms
64 bytes from 192.168.101.84: icmp_seq=4 ttl=128 time=0.355 ms
64 bytes from 192.168.101.84: icmp_seq=5 ttl=128 time=0.267 ms
h) whoami
Print effective userid.
-bash-3.2$ whoami
11bmca17
i)hostname
Set or print name of current host system. Additional information about the term hostname
can be found on our hostname definition.
-bash-3.2$ hostname
mcalab.domain
j) uname
Print name of current system.
-bash-3.2$ uname
Linux
k) umask
Get or set the file mode creation mask.
-bash-3.2$ umask
0002
l) chfn
chfn is used to change a user's finger information.
-bash-3.2$ chfn
Changing finger information for 11bmca17.
Password:
Name []: aswathy
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 don’t 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 leaving
the system console

debby:~> cat .bash_logout


# ~/.bash_logout

Clear

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.
-bash-3.2$ 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=11bmca17
LS_COLORS=no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01
1:or=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.co
tm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31:*
*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.
.bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35
5:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35:
KDEDIR=/usr
MAIL=/var/spool/mail/11bmca17
PATH=/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/bin:/bin
LOGIN=11bmca17
INPUTRC=/etc/inputrc
PWD=/home/11bmca17
LANG=en_US.UTF-8
KDE_IS_PRELINKED=1
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
KRB5CCNAME=FILE:/tmp/krb5cc_p6680
SHLVL=1
HOME=/home/11bmca17
LOGNAME=11bmca17
QTLIB=/usr/lib/qt-3.3/lib
CVS_RSH=ssh
LESSOPEN=|/usr/bin/lesspipe.sh %s
G_BROKEN_FILENAMES=1
_=/usr/bin/env
OLDPWD=/home/11bmca17/linexpgms
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.
-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.
-bash-3.2$ export 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.
[11bmca17@mcalab]$ chmod o+w 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
[11bmca17@mcalab]$ cat /etc/passwd
5amca29:x:750:750::/home/5amca29:/bin/bash
5amca30:x:751:751::/home/5amca30:/bin/bash
tanya:x:752:752::/home/tanya:/bin/bash
sini:x:753:753::/home/sini:/bin/bash
satheesh:x:754:754:satheesh:/home/satheesh:/bin/bash
alwaysnag:x:755:755::/home/alwaysnag:/bin/bash
reshma:x:756:756::/home/reshma:/bin/bash
lee:x:757:757::/home/lee:/bin/bash
11bmca01:x:759:759:akhil:/home/11bmca01:/bin/bash
11bmca02:x:760:760:Anish,APV,+918089529210,+918089529210:/home/11bmca02:/
bin/bash
11bmca03:x:761:761:Bitto,Mca:/home/11bmca03:/bin/bash
11bmca04:x:762:762:Eldhose,forest,00000000,999999999:/home/11bmca04:/bin/bash
11bmca05:x:763:763:Justin,UCC
MCA,+91-9961913723,+91-9961913723:/home/11bmca05:
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 you’ve defined, and when there is an incoming
request to a particular port that it is listening to, it starts the corresponding service.
[11bmca17@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
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, apt-get,
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 5.2-11 installed
GConf2.i386 2.14.0-9.el5 installed
GConf2-devel.i386 2.14.0-9.el5 installed
ImageMagick.i386 6.2.8.0-4.el5_1.1 installed
MAKEDEV.i386 3.23-1.2 installed
NetworkManager.i386 1:0.7.0-9.el5 installed
NetworkManager-glib.i386 1:0.7.0-9.el5 installed
NetworkManager-gnome.i386 1:0.7.0-9.el5 installed
ORBit2.i386 2.14.3-5.el5 installed
ORBit2-devel.i386 2.14.3-5.el5 installed
OpenIPMI.i386 2.0.16-5.el5 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
SDL.i386 1.2.10-8.el5 installed
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 host’s 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, you’re 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 you’re
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 you’re creating. These records become accessible
to everyone on the Internet.
• Private DNS server zone ⎯ So each computer on the private network doesn’t 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 it’s 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 server’s 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. Here’s 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).
Here’s 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, that’s 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 don’t 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.

-bash-3.2$ vi pgm1.sh

echo "enter a string"

read s

echo "the inputed string is" $s

-bash-3.2$ bash pgm1.sh

enter a string

mca 2013

the inputed string is mca 2013


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.

-bash-3.2$ vi oddeven.sh

echo "enter a number"

read no

val=`expr $no % 2`

if [ $val -eq 0 ]

then

echo "the given number is even"

else

echo "the given number is odd"

fi

OUTPUT

-bash-3.2$ bash oddeven.sh

enter a number

12

the given number is even


PROGRAM NO: 03

DATE: 17/10/13

AIM:Write a shell script to find the factorial of a number.

-bash-3.2$ vi fact.sh

s=1

echo "enter a number"

read n

while [ $n -gt 0 ]

do

(( s= $s * $n ))

(( n= $n - 1 ))

done

echo "the factorial of the given number is $s"

OUTPUT

-bash-3.2$ bash fact.sh

enter a number

the factorial of the given number is 120


PROGRAM NO: 04

DATE: 19/10/13

AIM:Write a shell script to print the sum of digits of a given number.

-bash-3.2$ vi sumdigit.sh

echo "enter a number"

read n

sum=0

while [ $n -gt 0 ]

do

a=`expr $n % 10`

sum=`expr $sum + $a`

n=`expr $n / 10`

done

echo "sum of digit is $sum"

OUTPUT

-bash-3.2$ bash sumdigit.sh

enter a number

123

sum of digit is 6
PROGRAM NO: 05

DATE: 28/10/13

AIM:Write a shell script to check whether a given year is leap year or not.

-bash-3.2$ vi leap.sh

echo "enter a year"

read year

if (( (( $year % 4 ==0 )) && (( $year %100 !=0 )) )) || (( $year % 400 ==0 ))

then

echo "the given year is a leap year"

else

echo "the given year is not a leap year"

fi

OUTPUT

-bash-3.2$ bash leap.sh

enter a year

2000

the given year is 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.

-bash-3.2$ vi stringpal.sh

echo "Enter a string to be entered:"


read str
echo
len=`echo $str | wc -c`
len=`expr $len - 1`
i=1
j=`expr $len / 2`
while test $i -le $j
do
k=`echo $str | cut -c $i`
l=`echo $str | cut -c $len`
if test $k != $l
then
echo "String is not palindrome"
exit
fi
i=`expr $i + 1`
len=`expr $len - 1`
done
echo "String is palindrome"

OUTPUT

-bash-3.2$ bash stringpal.sh

Enter a string to be entered:


malayalam
String is 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.

-bash-3.2$ vi lineextract.sh

echo "specify the line nomber from which you want to print"

read lo

echo "specify the endind line number"

read up

cat $1

(( mid= $up - $lo +1 ))

echo "........the lines are.........."

read -n $up $1 | tail -n $mid > testfile

cat testfile

OUTPUT

-bash-3.2$ bash lineextract.sh f1

specify the line nomber from which you want to print

specify the endind line number

c++

java

linux
unix

python

vb

php

android

........the lines are..........

c++

java

linux

unix

python

vb
PROGRAM NO: 08

DATE: 30/10/13

AIM: Write shell script using for loop to print the following patterns on screen

a) *
* *
* * *
* * * *

-bash-3.2$ vi pattern.sh

for (( i=1; i<=4; i=i+1 ))

do

for (( j=1; j<=i; j=j+1 ))

do

echo -n " * "

done

echo ""

done

output

-bash-3.2$ bash pattern.sh

* *

* * *

* * * *
PROGRAM NO: 09

DATE: 2/11/13

AIM: Write a shell script to print nos as 5,4,3,2,1 using while loop.

-bash-3.2$ vi number_rev.sh

n=5

while [ $n -gt 0 ]

do

echo "$n"

(( n= $n - 1 ))

Done

output

-bash-3.2$ bash number_rev.sh

1
PROGRAM NO: 10

DATE: 5-11-13

AIM: Write a shell script, using case statement to perform basic math operation .

-bash-3.2$ vi mathop.sh

echo "Enter num1"


read num1
echo "Enter num2"
read num2
echo "1.Add"
echo "2.Subtract"
echo "3.Divide"
echo "4.Multiply"
while true
do
echo "Enter your ch"
read ch
case $ch in

1)
#c=` expr $num1 + $num2 `
echo "Sum"
echo "$num1 + $num2" | bc ;;
2)
echo "Difference"
echo "$num1 - $num2 " | bc ;;
3)
echo "quotient"
echo "$num1 / $num2" | bc ;;
4)
echo "Product"
echo "$num1 * $num2" |bc ;;
*)
echo "Wrong choice"
break;;
esac
done
OUTPUT

-bash-3.2$ bash mathop.sh

Enter num1--

1-

Enter num2--

1.Add--

2.Subtract--

3.DivideT --

4.Multiply--

Enter your ch
1
Sum
3
Enter your ch
2
Difference
-1
Enter your ch
3
quotient
0
Enter your ch
4
Product

Enter your ch

Wrong choice
PROGRAM NO :11

DATE :6-11-13

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

echo "prime numbers with in a range of 1 and 300 are"

for (( i=1; i<=300; i++ ))

do

count=0

for (( j=1; j<=$i; j++ ))

do

cal=`expr $i % $j`

if [ $cal -eq 0 ]

then

count=`expr $count + 1`

fi

done

if [ $count -le 2 ]

then

echo -n " $i"

fi

done

OUTPUT

prime numbers with in a range of 1 and 300 are

1 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 :6-11-13

AIM : Write a program to generate all combinations of 1, 2 and 3 using for loops.

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++

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.

echo "contents of exsisting file"

cat $1

grep -v "unix" $1 > f

cp f $1

echo "contents in new file"

cat $1

cat f

OUTPUT

[11bmca17@mcalab linexpgms]$ bash pgm4.sh file1

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


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.

ls -l|grep "^-rwx"|tr -s " "|cut -d " " -f9

[11bmca17@mcalab linexpgms]$ bash permission.sh

combination.sh

prime.sh

sumdigit.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 doesn’t 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.

echo "Enter number"


read no
r=0
for((i=$no; i!=0; i=i/10))
do
no=` expr $i % 10 `
r=` expr $r \* 10 + $no `
done
echo $r

OUTPUT

Enter number
155
551
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’

[11bmca17@mcalab ~]$ ls -l [p]* > FILE1


[11bmca17@mcalab ~]$ cat FILE1
-rw-rw-r-- 1 11bmca17 11bmca17 0 Dec 11 14:20 p1
-rw-rw-r-- 1 11bmca17 11bmca17 325 Dec 11 14:08 p19.sh
-rw-rw-r-- 1 11bmca17 11bmca17 0 Dec 11 14:20 p2
-rw-rw-r-- 1 11bmca17 11bmca17 457 Dec 11 14:24 p22.sh
-rw-rw-r-- 1 11bmca17 11bmca17 0 Dec 11 14:20 p3
-rw-rw-r-- 1 11bmca17 11bmca17 293 Dec 10 17:12 pfile
-rw-rw-r-- 1 11bmca17 11bmca17 190 Dec 10 17:17 printf.sh
b) List all files beginning with the character ‘P’ on the screen twice in succession.
[11bmca17@mcalab ~]$ ls -l [p]* | tee b|tee /dev/pts/4
-rw-rw-r-- 1 11bmca17 11bmca17 0 Dec 11 14:20 p1
-rw-rw-r-- 1 11bmca17 11bmca17 325 Dec 11 14:08 p19.sh
-rw-rw-r-- 1 11bmca17 11bmca17 0 Dec 11 14:20 p2
-rw-rw-r-- 1 11bmca17 11bmca17 457 Dec 11 14:24 p22.sh
-rw-rw-r-- 1 11bmca17 11bmca17 0 Dec 11 14:20 p3
-rw-rw-r-- 1 11bmca17 11bmca17 173 Dec 12 15:05 p6.sh
-rw-rw-r-- 1 11bmca17 11bmca17 293 Dec 12 15:21 pfile
-rw-rw-r-- 1 11bmca17 11bmca17 0 Dec 12 15:21 pfinrf
-rw-rw-r-- 1 11bmca17 11bmca17 190 Dec 12 15:24 printf.sh
-rw-rw-r-- 1 11bmca17 11bmca17 165 Dec 12 14:47 profile
-rw-rw-r-- 1 11bmca17 11bmca17 0 Dec 11 14:20 p1
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’.
11bmca17@mcalab ~]$ who | sort -d | tee file2 | wc -l
19
[11bmca17@mcalab ~]$ cat file2
11bmca02 pts/18 2013-12-12 16:53 (192.168.101.49)
11bmca03 pts/14 2013-12-12 16:48 (192.168.101.140)
11bmca04 pts/7 2013-12-12 16:45 (192.168.101.42)
11bmca10 pts/11 2013-12-12 16:48 (192.168.101.41)
11bmca12 pts/27 2013-12-12 14:55 (192.168.101.69)
11bmca12 pts/4 2013-12-12 16:44 (192.168.101.39)
11bmca14 pts/17 2013-12-12 16:53 (192.168.101.38)
11bmca16 pts/12 2013-12-12 16:48 (192.168.101.37)
11bmca17 pts/13 2013-12-12 16:48 (192.168.101.34)
11bmca18 pts/3 2013-12-12 16:42 (192.168.101.33)
11bmca20 pts/1 2013-12-12 16:41 (192.168.101.31)
11bmca22 pts/9 2013-12-12 16:45 (192.168.101.59)
11bmca23 pts/15 2013-12-12 16:51 (192.168.101.45)
11bmca24 pts/8 2013-12-12 16:44 (192.168.101.46)
11bmca26 pts/6 2013-12-12 16:43 (192.168.101.55)
11bmca27 pts/5 2013-12-12 16:43 (192.168.101.52)
11bmca28 pts/10 2013-12-12 16:47 (192.168.101.54)
11bmca29 pts/2 2013-12-12 16:41 (192.168.101.53)
root :0 2013-12-12 12:05
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.

[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