Linux Final
Linux Final
UBUNTU INSTALLATION
COMPONENTS REQUIRED
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.
- 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...
-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
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
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.
unmask 022
MAIL=/usr/mail/$LOGNAME
PATH=/usr/bin:/usr/sbin:/etc::
TERM=lft
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
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.
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
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
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.
Assign eth0 with the above values for IP, netmask and broadcast address.
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
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
-bash-3.2$ vi pgm1.sh
read s
enter a string
mca 2013
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
read no
val=`expr $no % 2`
if [ $val -eq 0 ]
then
else
fi
OUTPUT
enter a number
12
DATE: 17/10/13
-bash-3.2$ vi fact.sh
s=1
read n
while [ $n -gt 0 ]
do
(( s= $s * $n ))
(( n= $n - 1 ))
done
OUTPUT
enter a number
DATE: 19/10/13
-bash-3.2$ vi sumdigit.sh
read n
sum=0
while [ $n -gt 0 ]
do
a=`expr $n % 10`
n=`expr $n / 10`
done
OUTPUT
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
read year
then
else
fi
OUTPUT
enter a year
2000
DATE: 28/10/13
-bash-3.2$ vi stringpal.sh
OUTPUT
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
read up
cat $1
cat testfile
OUTPUT
c++
java
linux
unix
python
vb
php
android
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
do
do
done
echo ""
done
output
* *
* * *
* * * *
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
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
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
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
do
count=0
do
cal=`expr $i % $j`
if [ $cal -eq 0 ]
then
count=`expr $count + 1`
fi
done
if [ $count -le 2 ]
then
fi
done
OUTPUT
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.
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.
do
count=0
do
if [ $arg = $j ]
then
((count=$count+1))
fi
done
done
OUTPUT
vb
c++
java
linux
python
java
c++
python
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.
cat $1
cp f $1
cat $1
cat f
OUTPUT
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
if [ -s temp ]
then
break
fi
done
OUTPUT
fi2
fi1
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
cat a1
cat a2
cat a3
cat a4
else
fi
OUTPUT
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.
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
fi
((i=i+1))
Done
OUTPUT
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
elif [ -d "mydir" ]
then
f=1
cd mydir
if [ -f $arg ]
then
else
touch $arg
fi
else
mkdir mydir
cd mydir
touch $arg
fi
done
if [ $f -eq 1 ]
then
ls > t
wc -l t
fi
OUTPUT
mca is a file
uc is a file
3t
PROGRAM NO :20
DATE :15-11-13
OUTPUT
Enter number
155
551
PROGRAM NO :21
DATE :17-11-13
a) List all files beginning with the character ‘P’ on the screen and also store them in a file
called ‘file1’
DATE :18-11-13
aswathy
6000
Name :a
Basic Salary :6000
DA :660.00
HRA :240.00
Gross Salary :6900.00