Linux Final
Linux Final
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:
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:
- 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
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
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
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
/dev/sda3
/dev/sda5
/dev/sda1
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.
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
12amca19 pts/3
12amca22 pts/4
12amca25 pts/5
12amca10 pts/6
12amca02 pts/7
12amca05 pts/8
12amca08 pts/9
12amca27 pts/10
12amca26 pts/11
12amca15 pts/12
12amca24 pts/13
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
1 root
2 root
RT -5
3 root
39 19
4 root
RT -5
5 root
RT -5
6 root
39 19
7 root
RT -5
8 root
RT -5
9 root
34 19
10 root
RT -5
11 root
RT -5
12 root
34 19
13 root
RT -5
14 root
10 -5
15 root
10 -5
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
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
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
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
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
Export variables
Terminal types
# =============================================================== #
b.
c.
d.
e.
f.
g.
h.
i.
j.
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
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
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 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
-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
bzip2 linux command is used to compress the file. Each file is replaced by a compressed
version of itself with .bz2 extension.
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
b) chown
Command for system V that changes the owner of a file.
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.
b) /etc/inittab file
inittab - format of the inittab file used by the sysv-compatible init process
c) chkconfig
Chkconfig command is used to setup, view, or change services that are configured to start
automatically during the system startup.
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.
shutdown -h 20:00
i) startx
Initializes an X session.
j) lilo
lilo - install boot loader
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
cdrecord-2.01-10.7.el5
b) dpkg
dpkg queries, installs, removes, and maintains Debian software packages and their
dependencies.
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.
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
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
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.
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
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.
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.
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.
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
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
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
PROGRAM NO: 08
DATE: 30/10/13
AIM: Write shell script using for loop to print the following patterns on screen
a)
*
*
*
*
*
*
*
*
*
echo ""
done
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)
2)
3)
4)
5)
echo "exit"
i=5
;;
esac
done
PROGRAM NO :11
DATE
:6-11-13
AIM
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 ""
PROGRAM NO :12
DATE
AIM
loops.
:6-11-13
: Write a program to generate all combinations of 1, 2 and 3 using for
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
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
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
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
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
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
PROGRAM NO :21
DATE
:17-11-13
AIM
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
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
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
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.
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
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