SlideShare a Scribd company logo
Unix programming
MODULE -1 INTRODUCTION
The POSIX Environment
Dennis Ritchie’s decision to rewrite UNIX in C didn't quite make UNIX very portable.
UNIX fragmentation and absence of a single conforming standard adversely affected the development of
portable applications.
First ,AT &T created the System V Interface Definition(SVID). Later, X/Guide(XPG). Products conforming to this
specification were branded UNIX95, UNIX98 or UNIX03 depending on the version of the specification.
Yet another group of standards, the portable operating system interface for computer environments(POSIX), were
developed at the behest of the Institution of Electrical and Electronics Engineers(IEEE).
POSIX refers to operating systems in general, but was based on UNIX.
Two of the most cited standards from the POSIX family are known as POSIX.1 and POSIX.2.
POSIX.1 specifies the C application program interface the system calls.
POSIX.2 deals with the shell and utilities
In 2001, a joint initiative of X/Open and IEEE resulted in the unification of the two standards.
This is the single UNIX Specification, version 3(SUSV3). The “write once, adopt everywhere” approach to
this development means that once software has been developed on any POSIX compliant UNIX
system, it can be easily ported to another POSIX- compliant UNIX machine with minimum
modifications. We make reference to POSIX throughout this text, but these references should be interpreted to mean
the SUSV3 as well.
Accessing Unix:
There are three methods for accessing the unix
User ID
Passwords
Interactive session
When you first connect to a UNIX system, you usually see a prompt such as the following
To log in:
1. Have your userid (user identification) and password ready. Contact your system administrator if you don't have these yet.
2. Type your userid at the login prompt, then press ENTER. Your userid is case-sensitive, so be sure
you type it exactly as your system administrator instructed.
3. Type your password at the password prompt, then press ENTER. Your password is also case sensitive.
4. If you provided correct userid and password then you would be allowed to enter into the system.
Read the informat and messages that come up on the screen something as below.
login : amrood
amrood's password:
Last login: Sun Jun 14 09:32:32 2009 from 62.61.164.73
You would be provided with a command prompt ( sometime called $ prompt ) where you would type
your all the commands
Interactive session
contains three steps
 login ,
 Interaction and
 logout
Login
The details of Login process varies from system to system. There is a general pattern to the steps listed
below.
a. you must make contact with the system.
If you are working on a local network, always connected to remote server starting the login process is
simple as selecting option in a menu.
If you are making the connection from a remote location such as from home to work then you need o
use special software for connection such as Telnet.
b. wait for the system login prompt.
login:
c. Type UserId
user id:
d. Type Password.
Password:
Interaction
Once you connect to server you can enter commands that allow you to work with the computer.Typical
commands allow you to work with the files-edit copy, sort, process data and print files; send and receive
mails etc..
Logout:
Its important to logout when you are done with your work .There are several reasons.
First it frees system resources for others who may need to use them.
Second it is a security concern.
Typical User Session:
login:gilberg
password:***********
$ ls
File1 file 2…….
$logout
Change Password:
All Unix systems require passwords to help ensure that your files and data remain your own and that
the system itself is secure from hackers and crackers. Here are the steps to change your password:
1.To start, type passwd at command prompt as shown below.
2.Enter your old password the one you're currently using.
3. Type in your new password. Always keep your password complex enough so that no body can guess
it. But make sure, you remember it.
4. You would need to verify the password by typing it again.
$ passwd
Changing password for amrood
(current) Unix password:******
New UNIX password:*******
Retype new UNIX password:*******
passwd: all authentication tokens updated successfully
$
GENERAL FEATURES OF UNIX COMMANDS/ COMMAND STRUCTURE
Commands are entered at shell prompt. The components of the command line are:
the verb;
any options required by the command
the command's arguments (if required).
For example, the general form of a UNIX command is:
$verb [-option(s)] [argument(s)]
Verb: is the command name. The command indicates what action is to be taken. This action
concept gives us the name verb for action .
option: modifies how the action is applied.
argument: provides additional information to the command.
Note: Options MUST come after the command and before any command arguments. Options
SHOULD NOT appear after the main argument(s). However, some options can have their own
arguments
if options are enclosed within the [] then options are not mandatory else it is compulsory
if arguments are enclosed within the [] then options are not mandatory else it is compulsory
UNDERSTANDING OF SOME BASIC COMMANDS SUCH AS echo, printf, ls, who,
date, passwd, cal
date: displays the system date and time. If the system is local that is one in your own area-it is the current time. If
the system is remote, such as across the country the reply will contain the time where the system is physically
located.
The input for the date is the system itself. The date is actually maintained in the computer as a part of OS. The date
command sends its response to monitor.
date command sends its response to monitor.
$date
$date -u
cal: The CALENDAR COMMAND
A single parameter specifies the 4 digit year (1 - 9999) to be displayed.
Two parameters denote the Month (1 - 12) and Year (1 - 9999). If arguments are not specified, the
current month is displayed. A year starts on 01 Jan.
To display current month's calendar
$ cal
Output
:
April 2016
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
To display feb 2015 calendar
$ cal 2 2015
Output :
February 2015
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
To display complete year calendar.
$ cal -y
who: THE Who is online Command
The who command prints information about all users who are currently logged in.
who [ OPTION ]... [ FILE ] [ am i ]
-u –Idle time: Print the idle time for each user, and the process ID.
-H – HEADING : Print a line of column headings.
$who
Displays the username, terminal, and time and date of all currently logged-in sessions
$who am i
Displays the same information, but only for the terminal session where the command was issued, for
example:
$
$who –u
Indicates how long it has been since there was any activity on the line. This is known as
Idle time. It also returns the process id for the user.
$who –uH
Displays "all" information, and headers above each column of data, for example:
passwd command.: The change Password(PASSWD) COMMAND
The passwd command is used to change the password of a user account. A normal user can run passwd
to change their own password, and a system administrator (the superuser) can use passwd to change
another user's password, or define how that account's password can be used or changed
passwd syntax
passwd [OPTION] [USER]
$passwd
Running passwd with no options will change the password of the account running the command. You
will first be prompted to enter the account's current password:
(current) UNIX password:
If it is correct, you will then be asked to enter a new password:
Enter new UNIX password:
...and to enter the same password again, to verify it:
Retype new UNIX password:
If the passwords match, the password will be changed.
The passwd command changes passwords for user accounts. A normal user can only change the
password for their own account, but the superuser can change the password for any account. Passwd
can also change or reset the account's validity period — how much time can pass before the password
expires and must be changed.
Before a normal user can change their own password, they must first enter their current password for
verification. (The superuser can bypass this step when changing another user's password.)
After the current password has been verified, passwd checks to see if the user is allowed to change
their password at this time. If not, passwd refuses to continue, and exits.
Otherwise, the user is then prompted twice for a replacement password. Both entries must match for passwd
to continue.
Rules for giving passwords
a) must be >=6 characters long,
b) must contain 2 out of 3 of
upper-case letters,
lower-case letters,
non-letters (digits, punct)
c) may not be a dictionary word or too similar to your name
echo: Print message command
The echo command used to display a message.
To display the diagnostic messages on the terminal or to issue prompts for taking user
input
To evaluate shell variable.
$ echo [SHORT-OPTION]... [STRING]...
Options
-n Do not output a trailing newline.
-e Enable interpretation of backslash escape sequences (see below for a list of these).
-E Disable interpretation of backslash escape sequences (this is the default).
--help Display a help message and exit.
version Output version information and exit.
If you specify the -e option, the following escape sequences are recognized:
 A literal backslash character ("").
a An alert (The BELL character).
b Backspace.
c Produce no further output after this.
e The escape character; equivalent to pressing the escape key.
f A form feed.
n A newline.
r A carriage return.
t A horizontal tab.
v A vertical tab.
$x=10
$echo “The value of x is $x”
Entering these two commands will output the following text:
Output :The value of x is 10.
Ex 3:
$echo -e “Herebthebspacesbarebbackspaced”
Outputs the following text:
Output :Herthspacearbackspaced //one character before backslash is deleted.
Ex 4:
$echo –e “Unix n is n a n os”
Output :$Unix
is
a
Os //prints in a new line
Ex 1: $echo Hello world
Output :Hello world
printf command-alternative to echo command
$printf “No file entered”
Output :No file entered
$printf My current shell is %sn” $SHELL
Output :My current shell is /bin/bash //Here %s act as a placeholder for the value $SHELL
%s-String
%f-Floating point number
%d-Decimal integer
%x-Hexadecimal integer
%o-octal integer
MEANING OF INTERNAL AND EXTERNAL COMMANDS
UNIX commands are classified into two types
Internal Commands - Ex: echo
External Commands - Ex: ls, cat
Internal Command:
Internal commands are something which is built into the shell. For the shell built in commands, the
execution speed is really high. It is because no process needs to be spawned for executing it.
For example, when using the "cd" command, no process is created. The current directory simply
gets changed on executing it.
External Command:
External commands are not built into the shell. These are executable present in a separate file. When
an external command has to be executed, a new process has to be spawned and the command gets executed.
For example, when you execute the "cat" command, which usually is at /usr/bin, the executable /usr/bin/cat
gets executed.
How to find out whether a command is internal or external?
type command:
$ type cd
cd is a shell built in
$ type cat
cat is /bin/cat
For the internal commands, the type command will clearly say its shell built-in, however for the
external commands, it gives the path of the command from where it is executed
THE TYPE COMMAND
knowing the type of a command and locating it.
type - Display information about command type
The type command is a shell built-in that displays the kind of command the shell will execute, given
a particular command name. It works like this: type command
where “command” is the name of the command you want to examine. Here are some examples:
$type type
Output: type is a shell built-in
$type ls
Output: ls is aliased to ‘ls –color=tty’
$type cp
Output: cp is /bin/cp
Here we see the results for three different commands. Notice that the one for ls (taken from a Fedora
system) and how the ls command is actually an alias for the ls command with the “-- color=tty” option
added. Now we know why the output from ls is displayed in color!
FLEXIBILITY OF COMMAND USAGE COMBINING COMMANDS
UNIX allows you to specify more than one command in the command line. Each command has to be separated from the
other by a ; (semicolon).
Example
$wc note; ls -l note
The above command first it displays the line count, word cont and byte or character count along with this it also display the
details of note file. When you learn to redirect the output of these commands you may even like to group them together
within parentheses .
Example :
$(wc note ; ls -l note) > newlist
The combined output of the two commands is now sent to the file newlist. Whitespace is provided here only for better
readability. You might reduce a few keystrokes like this
$wc note;ls -l note)>newlist
When a command line contains a semicolon, the shell understands that the command on each side of it needs to be
processed separately. The ; here is known as a metacharacter, and you'll come across several meta charaters that have
special meaning to the shell.
A command line can overflow or be split into multiple lines
A command is often keyed in. though the terminal width is restricted to 80 characters, that doesn't
THE MAN COMMAND:BROWSING THE MANUAL PAGES ON-LINE
The man command knowing more about Unix commands and using Unix online manual pages
man is the system's manual viewer; it can be used to display manual pages, scroll up and down, search for occurrences of
specific text, and other useful functions. Each argument given to man is normally the name of a program, utility or function.
The manual page associated with each of these arguments is then found and displayed. A section number, if provided, will
direct man to look only in that section of the manual. The default action is to search in all of the available sections, following
a pre-defined order and to show only the first page found, even if page exists in several sections.
A man page is divided into a number of compulsory optional sections. Every command doesn’t have all sections, but the first
three(NAME,SYNOPSIS and DESCRIPTION) are seen in all man pages.
NAME presents the online introduction to the command
SYNOPSIS shows the syntax used by the command
DESCRIPTION provides a detailed information.
man syntax
$man [option] command name
Options
K,--Search for text in all manual pages. This is a brute-force search, and is likely to take some time; if
Global
you can, you should specify a section to reduce the number of pages that need to be searched.
apropos
Search terms may be simple strings (the default), or regular expressions if the --regex option is used.
Section Numbers
The section numbers of the manual are listed below. While reading documentation, if you see a command name
followed by a number in parentheses, the number refers to one of these sections. For example, man is the
documentation of man found in section number 1. Some commands may have documentation in more than one
section, so the numbers after the command name may direct you to the correct section to find a specific type of
information.
The section numbers, and the topics they cover, are as follows:
Section number Description
1 Executable programs or shell commands
2 System calls (functions provided by the kernel)
3 Library calls (functions within program libraries)
4 Special files (usually found in /dev)
5 File formats and conventions eg /etc/passwd
6 Games
7 Miscellaneous (including macro packages and conventions), e.g. man, groff
8 System administration commands (usually only for root)
9 Kernel routines [Non standard]
Man Examples
$man man
View the manual page for the man command.
$man –s4 passwd
This displays the documentation for a configuration file from the section 4. Even this information is
whatis command: displays short manual page descriptions.
Each manual page has a short description available within it. whatis searches the manual page names and
displays the manual page descriptions of any name matched.
$whatis who
Display a description of what who is.
$whatis cal
apropos
command :
searches the manual pages for a keyword or regular expression. Each manual page has a short description
included with it. apropos searches these descriptions for instances of keyword.
$apropos find
aa_find_mountpoint (2) - find where the apparmor interface filesystem is mounted
chkdupexe (1) - find duplicate executables
ffs (3) - find first bit set in a word
ls COMMAND
The ls command lists all files in the directory that match the name. If name is left blank, it will list all
of the files in the directory.
Syntax
The syntax for the ls command is:
ls [options] [names]
Option Description
-a Displays all files.
-b Displays nonprinting characters in octal.
-c Displays files by file timestamp.
-C Displays files in a columnar format (default)
-d Displays only directories.
-f Interprets each name as a directory, not a file.
-F Flags filenames.
-g Displays the long format listing, but exclude the owner name.
-i Displays the inode for each file.
-l Displays the long format listing.
-L Displays the file or directory referenced by a symbolic link.
-m Displays the names as a comma-separated list.
-n Displays the long format listing, with GID and UID numbers.
-o Displays the long format listing, but excludes group name.
-p Displays directories with /
-q Displays all nonprinting characters as ?
-r Displays files in reverse order.
-R Displays subdirectories as well.
-t Displays newest files first. (based on timestamp)
-u Displays files by the file access time.
To show long listing information about the file/directory.
$ls –l
x Displays files as rows across the screen.
-1 Displays each entry on a line.
a.Field 1:
1st Character – File Type: First character specifies the type of the file. In the example above the hyphen (-) in the 1st
character indicates that this is a normal file. Following are the possible file type options in the 1st character of the ls -l
output.
Field Explanation
– normal file
d directory
s socket file
l link file
2nd to 9th character -- File Permissions: Next 9 character specifies the files permission. Each 3 characters refers to the
read, write, execute permissions for owner, group and other.
b.Field 2 – Number of links: Second field specifies the number of links for that file. In this example, 1 indicates only one
link to this file ecos.c and 2 links to directory named fedora
c.Field 3 – Owner: Third field specifies owner of the file. In this example, ecos.c file is owned by username ‘vizion’.
d. Field 4 – Group: Fourth field specifies the group of the file. In this example, the file ecos.c belongs to ”vizion’ group.
e. Field 5 – Size: Fifth field specifies the size of file. In this example, ‘1129’ indicates the ecos.c file size.
f. Field 6 – Last modified date & time: Sixth field specifies the date and time of the last modification
of the file.
g.Field 7 – File name: The last field is the name of the file.
Display Directory Information Using ls -ld
When you use “ls -l” you will get the details of directories content. But if you want the details of directory then you
can use -d option as., For example, if you use ls -l /etc will display all the files under etc
directory. But, if you want to display the information about the /etc/ directory, use -ld option as shown
below.
$
$ ls -l /etc
total 3344
-rw-r--r-- 1 root root 15276 Oct 5 2004 a2ps.cfg
-rw-r--r-- 1 root root 2562 Oct 5 2004 a2ps-site.cfg
drwxr-xr-x 4 root root 4096 Feb 2 2007 acpi
-rw-r--r-- 1 root root 48 Feb 8 2008 adjtime
drwxr-xr-x 4 root root 4096 Feb 2 2007 alchemist
$ ls -ld /etc
drwxr-xr-x 21 root root 4096 Jun 15 07:02 /etc
THE TYPE COMMAND: knowing the type of a command and locating it.
type - Display information about command type.
The type command is a shell built-in that displays the kind of command the shell will execute, given
a particular command name. It works like this: type command
where “command” is the name of the command you want to examine. Here are some examples:
$type type
Output: type is a shell built-in
$type ls
Output: ls is aliased to ‘ls –color=tty’
$type cp
Output: cp is /bin/cp
Here we see the results for three different commands. Notice that the one for ls (taken from a Fedora
system) and how the ls command is actually an alias for the ls command with the “-- color=tty” option
added. Now we know why the output from ls is displayed in color!
THE MORE COMMAND
The more command and using it with other commands
The more command displays the file called name in the screen. The RETURN key displays the next
line of the file. The spacebar displays the next screen of the file.
Syntax
The syntax for the more command is:
more [options] [files]
-- more –(39%) prompt is seen at bottom left corner of the screen. At this prompt you can press a key to
perform navigation.
KNOWING THE USER TERMINAL
For knowing the user terminal have one command called tty (teletype) command.
This command is simple and needs no arguments
$tty
output is /dev/pts/10
The terminal filename is 10 resident in the pts directory. This directory in turns is under the /dev
directory.
You can use tty in a shell script to control the behavior of the script depending on the terminal it
is invoked from.
Displaying its characteristics and setting characteristics
For displaying and setting characteristics in unix uses the command called stty
Set terminal without option or arguments.
$stty
Output: Speed 900 baud;
Line =1;intr =’A’; …….
It shows the current common settings of your terminal
Set terminal with options
only
Set terminal can be used with two options – (-a and –g)
-a displays the current terminal option settings
-g displays the selected settings in a format that can be used as an argument to another set terminal command.
Set terminal with arguments
Set erase and kill(ek): The ek argument sets the default erase(Delete key –Ctrl+h)and kill (ctrl+c) to their defaults.
Set erase key(erase):By default the Erase key is Ctrl+h on the terminal. It deleted the previous
harcter typed.We can reconfigure the keyboard to use another key as the delete key with the erase argument as shown below
$stty erase ^e
Set terminal to general configuration(sane):
$stty sane
Sane argument sets the terminal configuration to reasonable settings.
Set kill(kill)
$stty kill 9
The kill deletes a whole line.
Set Interrupt key(intr)
$stty intr 9
The interrupt key suspends or interrupts a command.
Other useful commands:
SCRIPT COMMAND- record session
Syntax
script options arguments
Used to record an interactive session ,when you want to start recording key the command as
script . $script
To stop recording, key the command as exit. $exit
To view the recorded script
$gedit filename
$gedit typescript
clear Command: clears the screen
$clear
Clears the screen and puts the cursor at top.
uname command
$uname options arguments
Options:
-a :all
-n:name of the system
-s:name of the OS
-r:software release
$uname
or
$uname –s
Output: Linux
$uname –n
Output: localhost. localdomain
$uname –r
Output:2.6.23.1-42.fc8
$uname –a
Output: Linux localhost.localdomain2.6.23.1-42.fc8
MANAGING THE NON UNIFORM BEHAVIOR OF TERMINALS AND KEYBOARDS
Terminals and keyboards have no uniform behavioral pattern. Terminal settings directly impact keyboard operation.
Backspacing Doesn’t Work: consider that you misspelled passwd as password, and when you pressed
the backspace key to erase the last three characters, you saw this
$password^H^H^H.
Backspacing is not working here; that’s why you see the symbol ^H every time you press the key.
Killing a Line: if the command line contains many mistakes, you could prefer to kill the line altogether without executing
it. In that case, use [Ctrl-u].
The line-kill character erases everything in the line and returns the cursor to the beginning of the line.
Interrupting a Command: sometimes, a program goes on running for an hour and doesnot seem to complete. You can
interrupt the program and bring back the prompt by using either of the two sequence
[Ctrl-c] or [Delete]
unix class 2 old scheme vtu syllabus old data
unix class 2 old scheme vtu syllabus old data
unix class 2 old scheme vtu syllabus old data
THE ROOT LOGIN
Root: the system administrator’s login. The unix system provides a special login name for the exclusive use of the
administrator, it is called root. This account doesn’t need to be separately created but comes with every system.
Its password is generally set at the time of installation of the system and has to be used on logging in
Login: root
Password: ******
The prompt of the root is # other users(non privileged user) either $ or % Once you login as root, you are place
in root’s home directory. Depending on the system, this could be
/ or /root
BECOMING THE SUPER USER: SU COMMAND
Any user can acquire super user status with the su command if she knows the root
password.
Example, the user GMIT becomes a super user in this way
$su
Password:******
#pwd
/home/GMIT
Though the current directory does not change the # prompt indicates the GMIT now has
powers of a
super user. To be in root’s home directory on superuser login, use su –l.
Creating a user’s Environment: users often rush to the administrator with the complaint that a program
has stopped running. The administrator first tries running it in a simulated environment.
su, when used with a -, recreates the user’s environment without taking the login password route:
$su – GMIT
This sequences executes GMIT’s .profile and temporarily creates GMIT’s environment. Su runs a separate sub
shell, so this mode is terminated by hitting [Ctrl-d] or using exit.
THE /ETC/PASSWD AND /ETC/SHADOW FILES
All user information except the password encryption is now stored in /etc/passwd. This file contained
the password once, the reason why it continues to be known by that name. the encryption itself is
stored in /etc/shadow. This is now the control file used by passwd to ascertain the legitimacy of a
user’s password.
There are seven fields here and their significance is noted below(in order they appear in /etc/passwd)
user name : the name you use to log on to a UNIX system(GMIT)
Password : No longer stores the password encryption but contains an X or *
UID : The user’s numerical identification. No two users should have the same UID.
GID : The user’s numerical group identification. This number is also the third field in /etc/group.
Comment or GCOS : User details e.g. her name, address and so forth.
Home directory : The directory where the user ends up logging in. the login program reads
this field to set the variable HOME.
Login shell : The first program executed after logging in.
USER MANAGEMENT
Commands to add modify and delete users
The term user in UNIX is not meant to be only a person; it can represent a project or an application as well. A group of
users performing similar functions may use the same username to use the system. It’s thus quite common to have
usernames like marketing, accounts, and so forth, for the creation and maintenance of user accounts, UNIX provides three
commands
useradd,
usermod and
userdel.
When opening a user account, you have to associate the user with a group. A group usually has more than one
member with a different set of privileges. People working on a common project should be able to read one
another’s files, which is possible only if they belong to same group.
Creating a user involves defining the following parameters
A user identification number(UID) and username.
A group identification number (GID) and group name.
The home directory
The login shell
The mailbox in /var/mail
The password
Most of these parameters are found in a single line identification the user in /etc/passwd. We will now
create a group for a user and then add that user to the system
Groupadd: adding a group
The groupadd command creates a new group account using the values specified on the command
line plus the default values from the system. The new group will be entered into the system files as needed.
groupadd syntax
groupadd [options] group
-g,
--gid GI
D
The numerical value of the group's ID. This value must be unique, unless the -o option is used. The value must be non-
negative. The default is to use the smallest ID value greater than or equal to GID_MIN and greater than every other group.
See also the -r option and the GID_MAX description
Note: For this command to work you must have superuser rights or be logged in as root.
#groupadd gmit
The above example would create a new group called "GMIT". This new group could then have users
added to it using the useradd command.
#groupadd –g 241 gmit
The above example creates a new group, gmit with a GID of 241.
The command places this entry in /etc/group. Once an entry for the group has been made, you are now
ready to add a user of tis group to the system.
Useradd: Adding a User:
The useradd command adds new user to the system.
useradd syntax
useradd [options] LOGIN
here useradd is a command
option
-g, --gid GRO
UP
The group name or number of the user's initial login group. The group name must exist. A group number must
refer to an already existing group
Note: For these commands to work you must have superuser rights or be logged in as root.
useradd newperson
Creates newperson as a new user. Once the new user has been added, you would need to use
the passwd command to assign a password to the account.mOnce a user has been created, you can
modify any of the user settings, such as the user's home directory, using the usermod command
$useradd –u 210 –g gmit –s /bin/bash –m kumar
From the above example it creates the kumar user under the gmit group with 210 UID number with
bash shell as working shell environment.
Usermod and userdel: modifying and removing users
Usermod is used for modifying some of the parameters set with useradd. Users sometimes need to change their
login shell, and the following command line sets bash as the login shell for the user.
$usermod –s /bin/ksh kumar
From the above command user changed their kernel from bash to ksh. Users are removed from the system with
userdel. The following command removes the user kumar from the system.
$userdel kumar

More Related Content

PPTX
Chapter 3 Using Unix Commands
PDF
Unix cook-book
DOCX
Unix lab manual
PPTX
Unix
DOC
C notes for exam preparation
DOCX
lec4.docx
PDF
Activity 5
PPTX
Introduction to Assembly Language Programming
Chapter 3 Using Unix Commands
Unix cook-book
Unix lab manual
Unix
C notes for exam preparation
lec4.docx
Activity 5
Introduction to Assembly Language Programming

Similar to unix class 2 old scheme vtu syllabus old data (20)

PPTX
MODULE-1_Operating System Services - ppt
PPT
UNIX.ppt
PDF
Linux for beginners
PDF
marlenis del carmen duarte gonzalez tegnologioa
PPTX
Introduction To Unix.pptx
PDF
ODP
Linuxs1
PDF
N_Asm Assembly system calls (sol)
PPTX
UNIX 1 Intro to UNIX OS.pptx
PPT
LINUX Device Drivers
DOCX
Os notes
ODP
Nithi
PDF
ArduinoWorkshop2.pdf
PPTX
C programming language tutorial
PPTX
Chapter 2.4
PDF
2600 v03 n07 (july 1986)
RTF
A basic unix overview(2)
PPTX
Notes on assignment in r
PPT
ch2_OS Structures.ppt To discuss the various ways of structuring an operatin...
DOC
Unix Quick Learn
MODULE-1_Operating System Services - ppt
UNIX.ppt
Linux for beginners
marlenis del carmen duarte gonzalez tegnologioa
Introduction To Unix.pptx
Linuxs1
N_Asm Assembly system calls (sol)
UNIX 1 Intro to UNIX OS.pptx
LINUX Device Drivers
Os notes
Nithi
ArduinoWorkshop2.pdf
C programming language tutorial
Chapter 2.4
2600 v03 n07 (july 1986)
A basic unix overview(2)
Notes on assignment in r
ch2_OS Structures.ppt To discuss the various ways of structuring an operatin...
Unix Quick Learn
Ad

Recently uploaded (20)

PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
RMMM.pdf make it easy to upload and study
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
master seminar digital applications in india
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
Updated Idioms and Phrasal Verbs in English subject
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
Trump Administration's workforce development strategy
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Cell Structure & Organelles in detailed.
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
LDMMIA Reiki Yoga Finals Review Spring Summer
UNIT III MENTAL HEALTH NURSING ASSESSMENT
Paper A Mock Exam 9_ Attempt review.pdf.
RMMM.pdf make it easy to upload and study
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
master seminar digital applications in india
Microbial disease of the cardiovascular and lymphatic systems
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Weekly quiz Compilation Jan -July 25.pdf
Updated Idioms and Phrasal Verbs in English subject
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
A systematic review of self-coping strategies used by university students to ...
Trump Administration's workforce development strategy
Final Presentation General Medicine 03-08-2024.pptx
Cell Structure & Organelles in detailed.
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Ad

unix class 2 old scheme vtu syllabus old data

  • 2. The POSIX Environment Dennis Ritchie’s decision to rewrite UNIX in C didn't quite make UNIX very portable. UNIX fragmentation and absence of a single conforming standard adversely affected the development of portable applications. First ,AT &T created the System V Interface Definition(SVID). Later, X/Guide(XPG). Products conforming to this specification were branded UNIX95, UNIX98 or UNIX03 depending on the version of the specification. Yet another group of standards, the portable operating system interface for computer environments(POSIX), were developed at the behest of the Institution of Electrical and Electronics Engineers(IEEE). POSIX refers to operating systems in general, but was based on UNIX. Two of the most cited standards from the POSIX family are known as POSIX.1 and POSIX.2. POSIX.1 specifies the C application program interface the system calls. POSIX.2 deals with the shell and utilities In 2001, a joint initiative of X/Open and IEEE resulted in the unification of the two standards. This is the single UNIX Specification, version 3(SUSV3). The “write once, adopt everywhere” approach to this development means that once software has been developed on any POSIX compliant UNIX system, it can be easily ported to another POSIX- compliant UNIX machine with minimum modifications. We make reference to POSIX throughout this text, but these references should be interpreted to mean the SUSV3 as well.
  • 3. Accessing Unix: There are three methods for accessing the unix User ID Passwords Interactive session When you first connect to a UNIX system, you usually see a prompt such as the following To log in: 1. Have your userid (user identification) and password ready. Contact your system administrator if you don't have these yet. 2. Type your userid at the login prompt, then press ENTER. Your userid is case-sensitive, so be sure you type it exactly as your system administrator instructed. 3. Type your password at the password prompt, then press ENTER. Your password is also case sensitive. 4. If you provided correct userid and password then you would be allowed to enter into the system. Read the informat and messages that come up on the screen something as below. login : amrood amrood's password: Last login: Sun Jun 14 09:32:32 2009 from 62.61.164.73 You would be provided with a command prompt ( sometime called $ prompt ) where you would type your all the commands
  • 4. Interactive session contains three steps  login ,  Interaction and  logout
  • 5. Login The details of Login process varies from system to system. There is a general pattern to the steps listed below. a. you must make contact with the system. If you are working on a local network, always connected to remote server starting the login process is simple as selecting option in a menu. If you are making the connection from a remote location such as from home to work then you need o use special software for connection such as Telnet. b. wait for the system login prompt. login: c. Type UserId user id: d. Type Password. Password:
  • 6. Interaction Once you connect to server you can enter commands that allow you to work with the computer.Typical commands allow you to work with the files-edit copy, sort, process data and print files; send and receive mails etc.. Logout: Its important to logout when you are done with your work .There are several reasons. First it frees system resources for others who may need to use them. Second it is a security concern. Typical User Session: login:gilberg password:*********** $ ls File1 file 2……. $logout
  • 7. Change Password: All Unix systems require passwords to help ensure that your files and data remain your own and that the system itself is secure from hackers and crackers. Here are the steps to change your password: 1.To start, type passwd at command prompt as shown below. 2.Enter your old password the one you're currently using. 3. Type in your new password. Always keep your password complex enough so that no body can guess it. But make sure, you remember it. 4. You would need to verify the password by typing it again. $ passwd Changing password for amrood (current) Unix password:****** New UNIX password:******* Retype new UNIX password:******* passwd: all authentication tokens updated successfully $
  • 8. GENERAL FEATURES OF UNIX COMMANDS/ COMMAND STRUCTURE Commands are entered at shell prompt. The components of the command line are: the verb; any options required by the command the command's arguments (if required). For example, the general form of a UNIX command is: $verb [-option(s)] [argument(s)]
  • 9. Verb: is the command name. The command indicates what action is to be taken. This action concept gives us the name verb for action . option: modifies how the action is applied. argument: provides additional information to the command. Note: Options MUST come after the command and before any command arguments. Options SHOULD NOT appear after the main argument(s). However, some options can have their own arguments if options are enclosed within the [] then options are not mandatory else it is compulsory if arguments are enclosed within the [] then options are not mandatory else it is compulsory
  • 10. UNDERSTANDING OF SOME BASIC COMMANDS SUCH AS echo, printf, ls, who, date, passwd, cal date: displays the system date and time. If the system is local that is one in your own area-it is the current time. If the system is remote, such as across the country the reply will contain the time where the system is physically located. The input for the date is the system itself. The date is actually maintained in the computer as a part of OS. The date command sends its response to monitor.
  • 11. date command sends its response to monitor. $date $date -u
  • 12. cal: The CALENDAR COMMAND A single parameter specifies the 4 digit year (1 - 9999) to be displayed. Two parameters denote the Month (1 - 12) and Year (1 - 9999). If arguments are not specified, the current month is displayed. A year starts on 01 Jan. To display current month's calendar $ cal Output : April 2016 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
  • 13. To display feb 2015 calendar $ cal 2 2015 Output : February 2015 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 To display complete year calendar. $ cal -y
  • 14. who: THE Who is online Command The who command prints information about all users who are currently logged in. who [ OPTION ]... [ FILE ] [ am i ] -u –Idle time: Print the idle time for each user, and the process ID. -H – HEADING : Print a line of column headings. $who Displays the username, terminal, and time and date of all currently logged-in sessions
  • 15. $who am i Displays the same information, but only for the terminal session where the command was issued, for example: $ $who –u Indicates how long it has been since there was any activity on the line. This is known as Idle time. It also returns the process id for the user.
  • 16. $who –uH Displays "all" information, and headers above each column of data, for example:
  • 17. passwd command.: The change Password(PASSWD) COMMAND The passwd command is used to change the password of a user account. A normal user can run passwd to change their own password, and a system administrator (the superuser) can use passwd to change another user's password, or define how that account's password can be used or changed
  • 18. passwd syntax passwd [OPTION] [USER] $passwd Running passwd with no options will change the password of the account running the command. You will first be prompted to enter the account's current password: (current) UNIX password: If it is correct, you will then be asked to enter a new password: Enter new UNIX password: ...and to enter the same password again, to verify it: Retype new UNIX password: If the passwords match, the password will be changed. The passwd command changes passwords for user accounts. A normal user can only change the password for their own account, but the superuser can change the password for any account. Passwd can also change or reset the account's validity period — how much time can pass before the password expires and must be changed.
  • 19. Before a normal user can change their own password, they must first enter their current password for verification. (The superuser can bypass this step when changing another user's password.) After the current password has been verified, passwd checks to see if the user is allowed to change their password at this time. If not, passwd refuses to continue, and exits. Otherwise, the user is then prompted twice for a replacement password. Both entries must match for passwd to continue. Rules for giving passwords a) must be >=6 characters long, b) must contain 2 out of 3 of upper-case letters, lower-case letters, non-letters (digits, punct) c) may not be a dictionary word or too similar to your name
  • 20. echo: Print message command The echo command used to display a message. To display the diagnostic messages on the terminal or to issue prompts for taking user input To evaluate shell variable.
  • 21. $ echo [SHORT-OPTION]... [STRING]... Options -n Do not output a trailing newline. -e Enable interpretation of backslash escape sequences (see below for a list of these). -E Disable interpretation of backslash escape sequences (this is the default). --help Display a help message and exit. version Output version information and exit. If you specify the -e option, the following escape sequences are recognized: A literal backslash character (""). a An alert (The BELL character). b Backspace. c Produce no further output after this. e The escape character; equivalent to pressing the escape key. f A form feed. n A newline. r A carriage return. t A horizontal tab. v A vertical tab.
  • 22. $x=10 $echo “The value of x is $x” Entering these two commands will output the following text: Output :The value of x is 10. Ex 3: $echo -e “Herebthebspacesbarebbackspaced” Outputs the following text: Output :Herthspacearbackspaced //one character before backslash is deleted. Ex 4: $echo –e “Unix n is n a n os” Output :$Unix is a Os //prints in a new line Ex 1: $echo Hello world Output :Hello world
  • 23. printf command-alternative to echo command $printf “No file entered” Output :No file entered $printf My current shell is %sn” $SHELL Output :My current shell is /bin/bash //Here %s act as a placeholder for the value $SHELL %s-String %f-Floating point number %d-Decimal integer %x-Hexadecimal integer %o-octal integer
  • 24. MEANING OF INTERNAL AND EXTERNAL COMMANDS UNIX commands are classified into two types Internal Commands - Ex: echo External Commands - Ex: ls, cat Internal Command: Internal commands are something which is built into the shell. For the shell built in commands, the execution speed is really high. It is because no process needs to be spawned for executing it. For example, when using the "cd" command, no process is created. The current directory simply gets changed on executing it. External Command: External commands are not built into the shell. These are executable present in a separate file. When an external command has to be executed, a new process has to be spawned and the command gets executed. For example, when you execute the "cat" command, which usually is at /usr/bin, the executable /usr/bin/cat gets executed.
  • 25. How to find out whether a command is internal or external? type command: $ type cd cd is a shell built in $ type cat cat is /bin/cat For the internal commands, the type command will clearly say its shell built-in, however for the external commands, it gives the path of the command from where it is executed
  • 26. THE TYPE COMMAND knowing the type of a command and locating it. type - Display information about command type The type command is a shell built-in that displays the kind of command the shell will execute, given a particular command name. It works like this: type command where “command” is the name of the command you want to examine. Here are some examples: $type type Output: type is a shell built-in $type ls Output: ls is aliased to ‘ls –color=tty’ $type cp Output: cp is /bin/cp Here we see the results for three different commands. Notice that the one for ls (taken from a Fedora system) and how the ls command is actually an alias for the ls command with the “-- color=tty” option added. Now we know why the output from ls is displayed in color!
  • 27. FLEXIBILITY OF COMMAND USAGE COMBINING COMMANDS UNIX allows you to specify more than one command in the command line. Each command has to be separated from the other by a ; (semicolon). Example $wc note; ls -l note The above command first it displays the line count, word cont and byte or character count along with this it also display the details of note file. When you learn to redirect the output of these commands you may even like to group them together within parentheses . Example : $(wc note ; ls -l note) > newlist The combined output of the two commands is now sent to the file newlist. Whitespace is provided here only for better readability. You might reduce a few keystrokes like this $wc note;ls -l note)>newlist When a command line contains a semicolon, the shell understands that the command on each side of it needs to be processed separately. The ; here is known as a metacharacter, and you'll come across several meta charaters that have special meaning to the shell. A command line can overflow or be split into multiple lines A command is often keyed in. though the terminal width is restricted to 80 characters, that doesn't
  • 28. THE MAN COMMAND:BROWSING THE MANUAL PAGES ON-LINE The man command knowing more about Unix commands and using Unix online manual pages man is the system's manual viewer; it can be used to display manual pages, scroll up and down, search for occurrences of specific text, and other useful functions. Each argument given to man is normally the name of a program, utility or function. The manual page associated with each of these arguments is then found and displayed. A section number, if provided, will direct man to look only in that section of the manual. The default action is to search in all of the available sections, following a pre-defined order and to show only the first page found, even if page exists in several sections. A man page is divided into a number of compulsory optional sections. Every command doesn’t have all sections, but the first three(NAME,SYNOPSIS and DESCRIPTION) are seen in all man pages. NAME presents the online introduction to the command SYNOPSIS shows the syntax used by the command DESCRIPTION provides a detailed information. man syntax $man [option] command name
  • 29. Options K,--Search for text in all manual pages. This is a brute-force search, and is likely to take some time; if Global you can, you should specify a section to reduce the number of pages that need to be searched. apropos Search terms may be simple strings (the default), or regular expressions if the --regex option is used.
  • 30. Section Numbers The section numbers of the manual are listed below. While reading documentation, if you see a command name followed by a number in parentheses, the number refers to one of these sections. For example, man is the documentation of man found in section number 1. Some commands may have documentation in more than one section, so the numbers after the command name may direct you to the correct section to find a specific type of information. The section numbers, and the topics they cover, are as follows: Section number Description 1 Executable programs or shell commands 2 System calls (functions provided by the kernel) 3 Library calls (functions within program libraries) 4 Special files (usually found in /dev) 5 File formats and conventions eg /etc/passwd 6 Games 7 Miscellaneous (including macro packages and conventions), e.g. man, groff 8 System administration commands (usually only for root) 9 Kernel routines [Non standard] Man Examples $man man View the manual page for the man command. $man –s4 passwd This displays the documentation for a configuration file from the section 4. Even this information is
  • 31. whatis command: displays short manual page descriptions. Each manual page has a short description available within it. whatis searches the manual page names and displays the manual page descriptions of any name matched. $whatis who Display a description of what who is.
  • 32. $whatis cal apropos command : searches the manual pages for a keyword or regular expression. Each manual page has a short description included with it. apropos searches these descriptions for instances of keyword. $apropos find aa_find_mountpoint (2) - find where the apparmor interface filesystem is mounted chkdupexe (1) - find duplicate executables ffs (3) - find first bit set in a word
  • 33. ls COMMAND The ls command lists all files in the directory that match the name. If name is left blank, it will list all of the files in the directory. Syntax The syntax for the ls command is: ls [options] [names]
  • 34. Option Description -a Displays all files. -b Displays nonprinting characters in octal. -c Displays files by file timestamp. -C Displays files in a columnar format (default) -d Displays only directories. -f Interprets each name as a directory, not a file. -F Flags filenames. -g Displays the long format listing, but exclude the owner name. -i Displays the inode for each file. -l Displays the long format listing. -L Displays the file or directory referenced by a symbolic link. -m Displays the names as a comma-separated list. -n Displays the long format listing, with GID and UID numbers. -o Displays the long format listing, but excludes group name. -p Displays directories with / -q Displays all nonprinting characters as ? -r Displays files in reverse order. -R Displays subdirectories as well. -t Displays newest files first. (based on timestamp) -u Displays files by the file access time.
  • 35. To show long listing information about the file/directory. $ls –l x Displays files as rows across the screen. -1 Displays each entry on a line.
  • 36. a.Field 1: 1st Character – File Type: First character specifies the type of the file. In the example above the hyphen (-) in the 1st character indicates that this is a normal file. Following are the possible file type options in the 1st character of the ls -l output. Field Explanation – normal file d directory s socket file l link file 2nd to 9th character -- File Permissions: Next 9 character specifies the files permission. Each 3 characters refers to the read, write, execute permissions for owner, group and other. b.Field 2 – Number of links: Second field specifies the number of links for that file. In this example, 1 indicates only one link to this file ecos.c and 2 links to directory named fedora c.Field 3 – Owner: Third field specifies owner of the file. In this example, ecos.c file is owned by username ‘vizion’. d. Field 4 – Group: Fourth field specifies the group of the file. In this example, the file ecos.c belongs to ”vizion’ group. e. Field 5 – Size: Fifth field specifies the size of file. In this example, ‘1129’ indicates the ecos.c file size. f. Field 6 – Last modified date & time: Sixth field specifies the date and time of the last modification of the file.
  • 37. g.Field 7 – File name: The last field is the name of the file. Display Directory Information Using ls -ld When you use “ls -l” you will get the details of directories content. But if you want the details of directory then you can use -d option as., For example, if you use ls -l /etc will display all the files under etc directory. But, if you want to display the information about the /etc/ directory, use -ld option as shown below. $ $ ls -l /etc total 3344 -rw-r--r-- 1 root root 15276 Oct 5 2004 a2ps.cfg -rw-r--r-- 1 root root 2562 Oct 5 2004 a2ps-site.cfg drwxr-xr-x 4 root root 4096 Feb 2 2007 acpi -rw-r--r-- 1 root root 48 Feb 8 2008 adjtime drwxr-xr-x 4 root root 4096 Feb 2 2007 alchemist $ ls -ld /etc drwxr-xr-x 21 root root 4096 Jun 15 07:02 /etc
  • 38. THE TYPE COMMAND: knowing the type of a command and locating it. type - Display information about command type. The type command is a shell built-in that displays the kind of command the shell will execute, given a particular command name. It works like this: type command where “command” is the name of the command you want to examine. Here are some examples: $type type Output: type is a shell built-in $type ls Output: ls is aliased to ‘ls –color=tty’ $type cp Output: cp is /bin/cp Here we see the results for three different commands. Notice that the one for ls (taken from a Fedora system) and how the ls command is actually an alias for the ls command with the “-- color=tty” option added. Now we know why the output from ls is displayed in color!
  • 39. THE MORE COMMAND The more command and using it with other commands The more command displays the file called name in the screen. The RETURN key displays the next line of the file. The spacebar displays the next screen of the file. Syntax The syntax for the more command is: more [options] [files]
  • 40. -- more –(39%) prompt is seen at bottom left corner of the screen. At this prompt you can press a key to perform navigation.
  • 41. KNOWING THE USER TERMINAL For knowing the user terminal have one command called tty (teletype) command. This command is simple and needs no arguments $tty output is /dev/pts/10 The terminal filename is 10 resident in the pts directory. This directory in turns is under the /dev directory. You can use tty in a shell script to control the behavior of the script depending on the terminal it is invoked from.
  • 42. Displaying its characteristics and setting characteristics For displaying and setting characteristics in unix uses the command called stty Set terminal without option or arguments. $stty Output: Speed 900 baud; Line =1;intr =’A’; ……. It shows the current common settings of your terminal
  • 43. Set terminal with options only Set terminal can be used with two options – (-a and –g) -a displays the current terminal option settings -g displays the selected settings in a format that can be used as an argument to another set terminal command. Set terminal with arguments Set erase and kill(ek): The ek argument sets the default erase(Delete key –Ctrl+h)and kill (ctrl+c) to their defaults. Set erase key(erase):By default the Erase key is Ctrl+h on the terminal. It deleted the previous harcter typed.We can reconfigure the keyboard to use another key as the delete key with the erase argument as shown below $stty erase ^e Set terminal to general configuration(sane): $stty sane Sane argument sets the terminal configuration to reasonable settings. Set kill(kill) $stty kill 9 The kill deletes a whole line. Set Interrupt key(intr) $stty intr 9 The interrupt key suspends or interrupts a command.
  • 44. Other useful commands: SCRIPT COMMAND- record session Syntax script options arguments Used to record an interactive session ,when you want to start recording key the command as script . $script To stop recording, key the command as exit. $exit
  • 45. To view the recorded script $gedit filename $gedit typescript
  • 46. clear Command: clears the screen $clear Clears the screen and puts the cursor at top. uname command $uname options arguments Options: -a :all -n:name of the system -s:name of the OS -r:software release $uname or $uname –s Output: Linux $uname –n Output: localhost. localdomain
  • 47. $uname –r Output:2.6.23.1-42.fc8 $uname –a Output: Linux localhost.localdomain2.6.23.1-42.fc8
  • 48. MANAGING THE NON UNIFORM BEHAVIOR OF TERMINALS AND KEYBOARDS Terminals and keyboards have no uniform behavioral pattern. Terminal settings directly impact keyboard operation. Backspacing Doesn’t Work: consider that you misspelled passwd as password, and when you pressed the backspace key to erase the last three characters, you saw this $password^H^H^H. Backspacing is not working here; that’s why you see the symbol ^H every time you press the key. Killing a Line: if the command line contains many mistakes, you could prefer to kill the line altogether without executing it. In that case, use [Ctrl-u]. The line-kill character erases everything in the line and returns the cursor to the beginning of the line. Interrupting a Command: sometimes, a program goes on running for an hour and doesnot seem to complete. You can interrupt the program and bring back the prompt by using either of the two sequence [Ctrl-c] or [Delete]
  • 52. THE ROOT LOGIN Root: the system administrator’s login. The unix system provides a special login name for the exclusive use of the administrator, it is called root. This account doesn’t need to be separately created but comes with every system. Its password is generally set at the time of installation of the system and has to be used on logging in Login: root Password: ****** The prompt of the root is # other users(non privileged user) either $ or % Once you login as root, you are place in root’s home directory. Depending on the system, this could be / or /root
  • 53. BECOMING THE SUPER USER: SU COMMAND Any user can acquire super user status with the su command if she knows the root password. Example, the user GMIT becomes a super user in this way $su Password:****** #pwd /home/GMIT Though the current directory does not change the # prompt indicates the GMIT now has powers of a super user. To be in root’s home directory on superuser login, use su –l.
  • 54. Creating a user’s Environment: users often rush to the administrator with the complaint that a program has stopped running. The administrator first tries running it in a simulated environment. su, when used with a -, recreates the user’s environment without taking the login password route: $su – GMIT This sequences executes GMIT’s .profile and temporarily creates GMIT’s environment. Su runs a separate sub shell, so this mode is terminated by hitting [Ctrl-d] or using exit.
  • 55. THE /ETC/PASSWD AND /ETC/SHADOW FILES All user information except the password encryption is now stored in /etc/passwd. This file contained the password once, the reason why it continues to be known by that name. the encryption itself is stored in /etc/shadow. This is now the control file used by passwd to ascertain the legitimacy of a user’s password. There are seven fields here and their significance is noted below(in order they appear in /etc/passwd) user name : the name you use to log on to a UNIX system(GMIT) Password : No longer stores the password encryption but contains an X or * UID : The user’s numerical identification. No two users should have the same UID. GID : The user’s numerical group identification. This number is also the third field in /etc/group. Comment or GCOS : User details e.g. her name, address and so forth. Home directory : The directory where the user ends up logging in. the login program reads this field to set the variable HOME. Login shell : The first program executed after logging in.
  • 56. USER MANAGEMENT Commands to add modify and delete users The term user in UNIX is not meant to be only a person; it can represent a project or an application as well. A group of users performing similar functions may use the same username to use the system. It’s thus quite common to have usernames like marketing, accounts, and so forth, for the creation and maintenance of user accounts, UNIX provides three commands useradd, usermod and userdel.
  • 57. When opening a user account, you have to associate the user with a group. A group usually has more than one member with a different set of privileges. People working on a common project should be able to read one another’s files, which is possible only if they belong to same group. Creating a user involves defining the following parameters A user identification number(UID) and username. A group identification number (GID) and group name. The home directory The login shell The mailbox in /var/mail The password Most of these parameters are found in a single line identification the user in /etc/passwd. We will now create a group for a user and then add that user to the system
  • 58. Groupadd: adding a group The groupadd command creates a new group account using the values specified on the command line plus the default values from the system. The new group will be entered into the system files as needed. groupadd syntax groupadd [options] group -g, --gid GI D The numerical value of the group's ID. This value must be unique, unless the -o option is used. The value must be non- negative. The default is to use the smallest ID value greater than or equal to GID_MIN and greater than every other group. See also the -r option and the GID_MAX description
  • 59. Note: For this command to work you must have superuser rights or be logged in as root. #groupadd gmit The above example would create a new group called "GMIT". This new group could then have users added to it using the useradd command. #groupadd –g 241 gmit The above example creates a new group, gmit with a GID of 241. The command places this entry in /etc/group. Once an entry for the group has been made, you are now ready to add a user of tis group to the system.
  • 60. Useradd: Adding a User: The useradd command adds new user to the system. useradd syntax useradd [options] LOGIN here useradd is a command option -g, --gid GRO UP The group name or number of the user's initial login group. The group name must exist. A group number must refer to an already existing group Note: For these commands to work you must have superuser rights or be logged in as root. useradd newperson
  • 61. Creates newperson as a new user. Once the new user has been added, you would need to use the passwd command to assign a password to the account.mOnce a user has been created, you can modify any of the user settings, such as the user's home directory, using the usermod command $useradd –u 210 –g gmit –s /bin/bash –m kumar From the above example it creates the kumar user under the gmit group with 210 UID number with bash shell as working shell environment.
  • 62. Usermod and userdel: modifying and removing users Usermod is used for modifying some of the parameters set with useradd. Users sometimes need to change their login shell, and the following command line sets bash as the login shell for the user. $usermod –s /bin/ksh kumar From the above command user changed their kernel from bash to ksh. Users are removed from the system with userdel. The following command removes the user kumar from the system. $userdel kumar