SlideShare a Scribd company logo
Chapter 3
Using Unix Commands
Meenal K Jabde
Modern College of Arts, Science & Commerce
Ganeshkhind, Pune 16
Contents
1. What is Command.
2. Meaning of Internal and external commands.
3. The type command: knowing the type of a command and locating it.
4. The man command knowing more about Unix commands and using Unix
online manual pages. The man with keyword option and whatis.
5. Knowing the user terminal, displaying its characteristics and setting
characteristics.
6. The root login. Becoming the super user: su command. The /etc/passwd
and /etc/shadow files.
7. Commands to add, modify and delete users.
What is command?
 In computing, a command is a
directive to a computer program to
perform a specific task.
 A command is a word or phrase that,
when typed or spoken, causes the
computer to perform a certain
operation.
Internal and
External
Commands
 The UNIX system is command-based i.e things happen because of the
commands that you key in. All UNIX commands are seldom more than
four characters long.
 They are grouped into two categories:
 Internal Commands : Commands which are built into the shell. For all the
shell built-in commands, execution of the same is fast in the sense that the
shell doesn’t have to search the given path for them in the PATH variable,
and also no process needs to be spawned for executing it.
Examples: source, cd, fg, etc.
 External Commands : Commands which aren’t built into the shell. When
an external command has to be executed, the shell looks for its path given
in the PATH variable, and also a new process has to be spawned and the
command gets executed. They are usually located in /bin or /usr/bin. For
example, when you execute the “cat” command, which usually is at
/usr/bin, the executable /usr/bin/cat gets executed.
Examples: ls, cat etc.
How to find out whether a command is internal or
external?
 whether it is internal or external with the help of type command :
 $type cat
 cat is /bin/cat
 //specifying that cat is
 external type//
 $type cd
 cd is a shell builtin
 //specifying that cd is
 internal type//
man
command
 man, command in Linux is used to display the user
manual of any command that we can run on the
terminal.
 It provides a detailed view of the command which
includes NAME, SYNOPSIS, DESCRIPTION,
OPTIONS, EXIT STATUS, RETURN VALUES,
ERRORS, FILES, VERSIONS, EXAMPLES,
AUTHORS
 $man [OPTION]... [COMMAND NAME]...
 1. No Option: It displays the whole manual of the
command.
 $ man printf
 2. Section-num: Since a manual is divided
into multiple sections so this option is used
to display only a specific section of a
manual.
 Syntax :
 $ man [SECTION-NUM] [COMMAND
NAME]
 $ man 2 intro
 In this example, the manual pages of
command ‘intro‘ are returned which lies in
the section 2.
 3. -f option: One may not be able to
remember the sections in which a
command is present. So this option
gives the section in which the given
command is present.
 Syntax:
 $ man -f [COMMAND NAME]
 Example:
 $ man -f ls
 In this example, the command ‘ls‘ is
returned with its section number.
 4. -a option: This option helps us to display all
the available intro manual pages in succession.
 Syntax:
 $ man -a [COMMAND NAME]
 Example:
 $ man -a intro
 In this example you can move through the
manual pages(sections) i.e either reading(by
pressing Enter) or skipping(by pressing ctrl+D)
or exiting(by pressing ctrl+C).
 5. -k option: This option searches the
given command as a regular
expression in all the manuals and it
returns the manual pages with the
section number in which it is found.
 Syntax:
 $ man -k [COMMAND NAME]
 Example:
 $ man -k cd
 The command ‘cd‘ is searched in all
the manual pages by considering it as
a regular expression.
 6. -w option: This option returns the location in which
the manual page of a given command is present.
 Syntax:
 $ man -w [COMMAND NAME]
 Example:
 $ man -w ls
 The location of command ‘ls‘ is returned.
 7. -I option: It considers the
command as case sensitive.
 Syntax:
 $ man -I [COMMAND NAME]
 Example:
 $ man -I printf
 The command ‘printf‘ is taken as
case-sensitive i.e ‘printf‘ returns the
manual pages but ‘Printf‘ gives error.
whatis command
 whatis command in Linux is used to get a one-line manual page descriptions. In Linux, each
manual page has some sort of description within it. So this command search for the manual pages
names and show the manual page description of the specified filename or argument.
 Syntax:
 whatis [-dlv?V] [-r|-w] [-s list] [-m system[, …]] [-M path] [-L locale] [-C file] name …
 whatis command with help option: The whatis command throws an error if no options, filename or
arguments are passed. So, when we use the -h option, it gives the general syntax along with the
various options that can be used.
1) whatis -d: This option prints the debugging information.
Example:
whatis -d ls
2) whatis -v: This option will prints verbose warning messages.
Example:
whatis -v ls
3) whatis -r : This option interprets each of the name as a regular expression. If any of
the names match any part of a page name, a match will be made. This option causes
the whatis command to be somewhat slower due to the nature of database searches.
Example:
whatis -r ls
4) whatis -w : This option interprets each name as a pattern containing shell style
wildcards. For a match about to make, an expanded name needs to match the entire
page name. This option causes the whatis command to be somewhat slower due to the
nature of database searches.
Example:
whatis -w ls
5) whatis -l: This option does not trim output to the terminal width. Normally, the
output will be truncated to the terminal width just to avoid ugly results from poorly-
written NAME sections.
Example:
whatis -l cat
6) whatis -s: This option will going to search only the given manual sections. The list
is a colon or a comma-separated list of sections. If an entry in list is just a simple
section, for example, “3”, then all the displayed list of descriptions will include pages
in sections “3”, “3perl”, “3x”, and so on; while if any of the entry in list has an
extension, for example “3perl”, then only the list will include pages in that exact part
of the manual section.
Example:
whatis -s 3 cat
Knowing the user terminal
 1. Get the running processes of logged-in user using w
 w command is used to show logged-in usernames and what they are doing. The
information will be read from /var/run/utmp file. The output of the w command
contains the following columns:
 Name of the user
 User’s machine number or tty number
 Remote machine address
 User’s Login time
 Idle time (not usable time)
 Time used by all processes attached to the tty (JCPU time)
 Time used by the current process (PCPU time)
 Command currently getting executed by the users
 Following options can be used for the w command:
 -h Ignore the header information
 -u Display the load average (uptime output)
 -s Remove the JCPU, PCPU, and login time.
$ w
 23:04:27 up 29 days, 7:51, 3 users, load average: 0.04, 0.06, 0.02
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
ramesh pts/0 dev-db-server 22:57 8.00s 0.05s 0.01s sshd: ramesh
[priv]
jason pts/1 dev-db-server 23:01 2:53 0.01s 0.01s -bash
john pts/2 dev-db-server 23:04 0.00s 0.00s 0.00s w
$ w -h
ramesh pts/0 dev-db-server 22:57 17:43 2.52s 0.01s sshd: ramesh
[priv]
jason pts/1 dev-db-server 23:01 20:28 0.01s 0.01s -bash
john pts/2 dev-db-server 23:04 0.00s 0.03s 0.00s w -h
 $ w -u
 23:22:06 up 29 days, 8:08, 3 users, load average: 0.00, 0.00, 0.00
 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
 ramesh pts/0 dev-db-server 22:57 17:47 2.52s 2.49s top
 jason pts/1 dev-db-server 23:01 20:32 0.01s 0.01s -bash
 john pts/2 dev-db-server 23:04 0.00s 0.03s 0.00s w -u
 $ w -s
 23:22:10 up 29 days, 8:08, 3 users, load average: 0.00, 0.00, 0.00
 USER TTY FROM IDLE WHAT
 ramesh pts/0 dev-db-server 17:51 sshd: ramesh [priv]
 jason pts/1 dev-db-server 20:36 -bash
 john pts/2 dev-db-server 1.00s w -s
2. Get the username and process of logged in user using who and
users command
who command is used to get the list of the usernames who are
currently logged in. Output of the who command contains the
following columns: user name, tty number, date and time,
machine address.
$ who
ramesh pts/0 2009-03-28 22:57 (dev-db-server)
jason pts/1 2009-03-28 23:01 (dev-db-server)
john pts/2 2009-03-28 23:04 (dev-db-server)
 To get a list of all usernames that are currently logged in, use the
following:
 $ who | cut -d' ' -f1 | sort | uniq
 john
 jason
 Ramesh
 Users Command
 users command is used to print the user name who are all currently logged
in the current host. It is one of the command don’t have any option other
than help and version. If the user using, ‘n’ number of terminals, the user
name will shown in ‘n’ number of time in the output.
 $ users
 john jason ramesh
3. Get the username you are currently logged in using
whoami
 whoami command is used to print the loggedin user name.
 $ whoami
 john

 whoami command gives the same output as id -un as shown below:
 $ id -un
 john
4. Get the user login history at any time
 last command will give login history
for a specific username. If we don’t
give any argument for this command,
it will list login history for all users.
By default this information will read
from /var/log/wtmp file. The output
of this command contains the
following columns:
 User name
 Tty device number
 Login date and time
 Logout time
 Total working time
$ last jason
jason pts/0 dev-db-server Fri Mar 27 22:57 still
logged in
jason pts/0 dev-db-server Fri Mar 27 22:09 - 22:54
(00:45)
jason pts/0 dev-db-server Wed Mar 25 19:58 -
22:26 (02:28)
jason pts/1 dev-db-server Mon Mar 16 20:10 -
21:44 (01:33)
jason pts/0 192.168.201.11 Fri Mar 13 08:35 - 16:46
(08:11)
jason pts/1 192.168.201.12 Thu Mar 12 09:03 -
09:19 (00:15)
jason pts/0 dev-db-server Wed Mar 11 20:11 -
20:50 (00:39
displaying its characteristics and setting
characteristics.
 stty command in Linux is used to change and print terminal
line settings. Basically, this command shows or changes
terminal characteristics.
 Syntax:
 stty [-F DEVICE | --file=DEVICE] [SETTING]...
 stty [-F DEVICE | --file=DEVICE] [-a|--all]
 stty [-F DEVICE | --file=DEVICE] [-g|--save]
 Example: It will display the characteristics of the terminal
stty –all: This option print all
current settings in human-
readable form.
stty --all
 stty -g: This option will print all current settings in a stty-readable form.
 stty –g
 stty -F : This option will open and
use the specified DEVICE instead of
stdin.
 Example:
 stty -F D/
 stty –help : This option will display
this help and exit.
 stty –help
 stty –version: This option will show the version information and
exit.
 stty --version
 Terminal Characteristics
 You can specify your terminal type to Unix if the default is not
suitable. To do so in the C shell, enter the command:
 set term= (termtype)
 where termtype is the name of a terminal type supported on the
system. VT100 and VT220 are acceptable terminal types for
example. If you always use the same kind of terminal, you may want
to put this command in your .login.
Root login & su command
 root is the username or account that by default has access to all commands and files on a
Linux or other Unix-like operating system. It is also referred to as the root account, root
user and the superuser
su command
The su command is use to change user ID or become super-user
during a login session i.e. it allows you to become a super user or
substitute user, spoof user, set user or switch user.
Note: su only works if you know the target or root user’s password.
su command syntax
The syntax is:
su - {user-name}
 If invoked without a user-name, su defaults to becoming the super
user. The user will be prompted for a password, if appropriate.
 To log in as root user type the following command (you need to
supply root user account password when prompted):
 $ su –
 su Command Options
 To display a list of commands, enter the following:
 su –h
 Here are some common options to use with the su command:
 Username – Replace username with the actual username you want to log in
with. This can be any user, not just root.
 –c or –command [command] – Runs a specific command as the specified
user.
 – or –l or –login [username] – Runs a login script to change to a specific
username. You’ll need to enter a password for that user.
 –s or –shell [shell] – Allows you to specify a different shell environment to
run in.
 –h or –help – Show the help file for the su command.
 –p or ––preserve–environment – Preserve the shell environment (HOME,
SHELL, USER, LOGNAME).
 Switch to a Different User
 To switch the logged-in user in this terminal window, enter the following:
 su –l [other_user]
 You’ll be asked for a password. Enter it, and the login will change to that
user.
 If you omit a username, it will default to the root account. Now, the
logged-in user can run all system commands. This will also change the
home directory and path to executable files.
 Use the whoami command to verify you switched to a different user.
The
/etc/passwd
and
/etc/shadow
files.
 Users are accounts that can be used to login into a system.
 Each user is identified by a unique identification number or UID by the
system.
 All the information of users in a system are stored in /etc/passwd file.
 The hashed passwords for users are stored in /etc/shadow file.
 When a new user is created, by default system takes following actions:
1. Assigns UID to the user.
2.Creates a home directory /home/.
3.Sets the default shell of the user to be /bin/sh.
4.Creates a private user group, named after the username itself.
5.Contents of /etc/skel are copied to the home directory of the new user.
6..bashrc, .bash_profile and .bash_logout are copied to the home directory of
new user.These files provide environment variables for this user’s session.
contents of
/etc/passwd
File
 This file is readable by any user but only root as read and write
permissions for it. This file consists of the following colon separated
information about users in a system:
 Username field
 Password field
 An `x` in this field denotes that the encrypted password is stored in the
/etc/shadow file.
 The user ID number (UID)
 User’s group ID number (GID)
 Additional information field such as the full name of the user or comment
(GECOS)
 Absolute path of user’s home directory
 Login shell of the user
 [username]:[password]:[UID]:[GID]:[GECOS]:[home_dir]:[shell_path]
contents of
the
/etc/shadow
File
 This file is readable and writable by only by root user. This file
consists of the following colon separated information about
password of users in a system:
 User name field
 Password field
 Contains an encrypted password.
 A blank entry, {:: }, indicates that a password is not required to
login into that user’s account.
 An asterisk, {:*:}, indicates the account has been disabled.
 Last Password Change
 This field denotes the number of days since the date of last
password change counted since UNIX time (1-Jan-1970).
 The minimum number of days after which the user can change his
password.
 Password validity
 Denotes the number of days after which the password will expire.
 Warning period
 Denotes the number of days before the password expiry date, from which the user
will start receiving warning notification for password change.
 Account validity
 Denotes the number of days after which the account will be disabled, once the
password is expired.
 Account disability
 This field denotes the number of days since which the account had been disabled
counted from UNIX time (1-Jan-1970).
 Syntax:
 [username]:[enc_pwd]:[last_pwd_change]:[pwd_validity]:[warn_date]:[acc_validi
ty]:[acc_disablity]
Commands to
add, modify
and delete
users
 Add a user
 To add users, run the useradd command, like so:
 sudo useradd -m <name of the user>
 sudo useradd -m john
 By default, useradd creates a user without creating a
home directory. So, to make useradd create a home
folder, we’ve used the -m switch.
 Change Password of a User
 Previously, when we created a new user, we’ve used the passwd
command to assign a password to the new user. You can also use
this to change passwords. If you want to change your own password,
simply run:
 Passwd
 When you change your own password, it’ll ask you for your current
password. Once you enter it correctly, you will be asked to enter
your new password twice.
 You can also use it to change a different by providing the username,
although you need to be root to change passwords for others. The
syntax for changing another user’s password is:
 sudo passwd <username>
 When you are the root user, passwd doesn’t ask you for your current
password — it’ll just ask you for the new password.
 Delete a User in Linux
 To delete a user in Linux, you can use userdel command, like so:
 sudo userdel <username>
 By default, this command preserves the home directory and some
other special files, such as the user’s list of cron jobs. If you want to
delete these files as well, you should use the --remove-all-files flag.
 For example, if you want to delete the user john along with the
home directory of john, use the following command:
 sudo userdel -r john
References
1) https://www.d.umn.edu/~gshute/unix/unix.html
2) https://www.tutorialspoint.com/unix_commands/refer.htm
3) https://www.guru99.com/must-know-linux-commands.html
4) http://mally.stanford.edu/~sr/computing/basic-unix.html
5) https://www.unixtutorial.org/basic-unix-commands
Thank You

More Related Content

PDF
Chapter1 Formal Language and Automata Theory
PDF
Linux Basic Commands
PDF
COMPILER DESIGN.pdf
PDF
DBMS 1 | Introduction to DBMS
PPTX
Filepermissions in linux
PDF
Complete Guide for Linux shell programming
PPTX
greedy algorithm Fractional Knapsack
PDF
Chapter1 Formal Language and Automata Theory
Linux Basic Commands
COMPILER DESIGN.pdf
DBMS 1 | Introduction to DBMS
Filepermissions in linux
Complete Guide for Linux shell programming
greedy algorithm Fractional Knapsack

What's hot (20)

PDF
Linux systems - Linux Commands and Shell Scripting
PPTX
Basics of shell programming
PPTX
Lecture optimal binary search tree
PDF
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all started
PDF
Syntax analysis
PPTX
Disk and File System Management in Linux
PPTX
Users and groups
PPTX
Strassen's matrix multiplication
PPTX
IBM Spectrum Scale Authentication for File Access - Deep Dive
PPTX
Top down parsing
PPTX
PPTX
Basic commands of linux
PPTX
User management
PPTX
Linux commands
PDF
Basic linux commands
PPTX
LR(1) and SLR(1) parsing
PPTX
Merge sort analysis and its real time applications
Linux systems - Linux Commands and Shell Scripting
Basics of shell programming
Lecture optimal binary search tree
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all started
Syntax analysis
Disk and File System Management in Linux
Users and groups
Strassen's matrix multiplication
IBM Spectrum Scale Authentication for File Access - Deep Dive
Top down parsing
Basic commands of linux
User management
Linux commands
Basic linux commands
LR(1) and SLR(1) parsing
Merge sort analysis and its real time applications
Ad

Similar to Chapter 3 Using Unix Commands (20)

PPTX
Introduction to linux day1
PPTX
Chapter 2 unix system commands
PPTX
2. UNIX OS System Architecture easy.pptx
PDF
Unix _linux_fundamentals_for_hpc-_b
PPT
Linux day 1
PPTX
Unix Trainning Doc.pptx
PPSX
Unix environment [autosaved]
DOCX
lec1.docx
PPT
Basic Linux day 1
PPT
Linux commands
PPTX
Using Unix Commands.pptx
PPTX
Using Unix Commands.pptx
PPTX
Red hat linux essentials
PPTX
various shell commands in unix operating system.pptx
PPTX
Basic Linux Administration - 3.pptxon server
PPTX
PDF
Unit2 help
PDF
Linux Basic commands for beginners-@OneMento
PDF
Shell intro
ODP
Linux commands
Introduction to linux day1
Chapter 2 unix system commands
2. UNIX OS System Architecture easy.pptx
Unix _linux_fundamentals_for_hpc-_b
Linux day 1
Unix Trainning Doc.pptx
Unix environment [autosaved]
lec1.docx
Basic Linux day 1
Linux commands
Using Unix Commands.pptx
Using Unix Commands.pptx
Red hat linux essentials
various shell commands in unix operating system.pptx
Basic Linux Administration - 3.pptxon server
Unit2 help
Linux Basic commands for beginners-@OneMento
Shell intro
Linux commands
Ad

Recently uploaded (20)

PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
RMMM.pdf make it easy to upload and study
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Pre independence Education in Inndia.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Cell Types and Its function , kingdom of life
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Basic Mud Logging Guide for educational purpose
PDF
Complications of Minimal Access Surgery at WLH
PDF
Insiders guide to clinical Medicine.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
Week 4 Term 3 Study Techniques revisited.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
RMMM.pdf make it easy to upload and study
PPH.pptx obstetrics and gynecology in nursing
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Module 4: Burden of Disease Tutorial Slides S2 2025
STATICS OF THE RIGID BODIES Hibbelers.pdf
Pre independence Education in Inndia.pdf
VCE English Exam - Section C Student Revision Booklet
Final Presentation General Medicine 03-08-2024.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
O7-L3 Supply Chain Operations - ICLT Program
Cell Types and Its function , kingdom of life
Renaissance Architecture: A Journey from Faith to Humanism
Basic Mud Logging Guide for educational purpose
Complications of Minimal Access Surgery at WLH
Insiders guide to clinical Medicine.pdf
Pharma ospi slides which help in ospi learning
Abdominal Access Techniques with Prof. Dr. R K Mishra

Chapter 3 Using Unix Commands

  • 1. Chapter 3 Using Unix Commands Meenal K Jabde Modern College of Arts, Science & Commerce Ganeshkhind, Pune 16
  • 2. Contents 1. What is Command. 2. Meaning of Internal and external commands. 3. The type command: knowing the type of a command and locating it. 4. The man command knowing more about Unix commands and using Unix online manual pages. The man with keyword option and whatis. 5. Knowing the user terminal, displaying its characteristics and setting characteristics. 6. The root login. Becoming the super user: su command. The /etc/passwd and /etc/shadow files. 7. Commands to add, modify and delete users.
  • 3. What is command?  In computing, a command is a directive to a computer program to perform a specific task.  A command is a word or phrase that, when typed or spoken, causes the computer to perform a certain operation.
  • 4. Internal and External Commands  The UNIX system is command-based i.e things happen because of the commands that you key in. All UNIX commands are seldom more than four characters long.  They are grouped into two categories:  Internal Commands : Commands which are built into the shell. For all the shell built-in commands, execution of the same is fast in the sense that the shell doesn’t have to search the given path for them in the PATH variable, and also no process needs to be spawned for executing it. Examples: source, cd, fg, etc.  External Commands : Commands which aren’t built into the shell. When an external command has to be executed, the shell looks for its path given in the PATH variable, and also a new process has to be spawned and the command gets executed. They are usually located in /bin or /usr/bin. For example, when you execute the “cat” command, which usually is at /usr/bin, the executable /usr/bin/cat gets executed. Examples: ls, cat etc.
  • 5. How to find out whether a command is internal or external?  whether it is internal or external with the help of type command :  $type cat  cat is /bin/cat  //specifying that cat is  external type//  $type cd  cd is a shell builtin  //specifying that cd is  internal type//
  • 6. man command  man, command in Linux is used to display the user manual of any command that we can run on the terminal.  It provides a detailed view of the command which includes NAME, SYNOPSIS, DESCRIPTION, OPTIONS, EXIT STATUS, RETURN VALUES, ERRORS, FILES, VERSIONS, EXAMPLES, AUTHORS  $man [OPTION]... [COMMAND NAME]...  1. No Option: It displays the whole manual of the command.
  • 7.  $ man printf
  • 8.  2. Section-num: Since a manual is divided into multiple sections so this option is used to display only a specific section of a manual.  Syntax :  $ man [SECTION-NUM] [COMMAND NAME]  $ man 2 intro  In this example, the manual pages of command ‘intro‘ are returned which lies in the section 2.
  • 9.  3. -f option: One may not be able to remember the sections in which a command is present. So this option gives the section in which the given command is present.  Syntax:  $ man -f [COMMAND NAME]  Example:  $ man -f ls  In this example, the command ‘ls‘ is returned with its section number.
  • 10.  4. -a option: This option helps us to display all the available intro manual pages in succession.  Syntax:  $ man -a [COMMAND NAME]  Example:  $ man -a intro  In this example you can move through the manual pages(sections) i.e either reading(by pressing Enter) or skipping(by pressing ctrl+D) or exiting(by pressing ctrl+C).
  • 11.  5. -k option: This option searches the given command as a regular expression in all the manuals and it returns the manual pages with the section number in which it is found.  Syntax:  $ man -k [COMMAND NAME]  Example:  $ man -k cd  The command ‘cd‘ is searched in all the manual pages by considering it as a regular expression.
  • 12.  6. -w option: This option returns the location in which the manual page of a given command is present.  Syntax:  $ man -w [COMMAND NAME]  Example:  $ man -w ls  The location of command ‘ls‘ is returned.
  • 13.  7. -I option: It considers the command as case sensitive.  Syntax:  $ man -I [COMMAND NAME]  Example:  $ man -I printf  The command ‘printf‘ is taken as case-sensitive i.e ‘printf‘ returns the manual pages but ‘Printf‘ gives error.
  • 14. whatis command  whatis command in Linux is used to get a one-line manual page descriptions. In Linux, each manual page has some sort of description within it. So this command search for the manual pages names and show the manual page description of the specified filename or argument.  Syntax:  whatis [-dlv?V] [-r|-w] [-s list] [-m system[, …]] [-M path] [-L locale] [-C file] name …  whatis command with help option: The whatis command throws an error if no options, filename or arguments are passed. So, when we use the -h option, it gives the general syntax along with the various options that can be used.
  • 15. 1) whatis -d: This option prints the debugging information. Example: whatis -d ls 2) whatis -v: This option will prints verbose warning messages. Example: whatis -v ls 3) whatis -r : This option interprets each of the name as a regular expression. If any of the names match any part of a page name, a match will be made. This option causes the whatis command to be somewhat slower due to the nature of database searches. Example: whatis -r ls
  • 16. 4) whatis -w : This option interprets each name as a pattern containing shell style wildcards. For a match about to make, an expanded name needs to match the entire page name. This option causes the whatis command to be somewhat slower due to the nature of database searches. Example: whatis -w ls 5) whatis -l: This option does not trim output to the terminal width. Normally, the output will be truncated to the terminal width just to avoid ugly results from poorly- written NAME sections. Example: whatis -l cat 6) whatis -s: This option will going to search only the given manual sections. The list is a colon or a comma-separated list of sections. If an entry in list is just a simple section, for example, “3”, then all the displayed list of descriptions will include pages in sections “3”, “3perl”, “3x”, and so on; while if any of the entry in list has an extension, for example “3perl”, then only the list will include pages in that exact part of the manual section. Example: whatis -s 3 cat
  • 17. Knowing the user terminal  1. Get the running processes of logged-in user using w  w command is used to show logged-in usernames and what they are doing. The information will be read from /var/run/utmp file. The output of the w command contains the following columns:  Name of the user  User’s machine number or tty number  Remote machine address  User’s Login time  Idle time (not usable time)  Time used by all processes attached to the tty (JCPU time)  Time used by the current process (PCPU time)  Command currently getting executed by the users
  • 18.  Following options can be used for the w command:  -h Ignore the header information  -u Display the load average (uptime output)  -s Remove the JCPU, PCPU, and login time.
  • 19. $ w  23:04:27 up 29 days, 7:51, 3 users, load average: 0.04, 0.06, 0.02 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT ramesh pts/0 dev-db-server 22:57 8.00s 0.05s 0.01s sshd: ramesh [priv] jason pts/1 dev-db-server 23:01 2:53 0.01s 0.01s -bash john pts/2 dev-db-server 23:04 0.00s 0.00s 0.00s w $ w -h ramesh pts/0 dev-db-server 22:57 17:43 2.52s 0.01s sshd: ramesh [priv] jason pts/1 dev-db-server 23:01 20:28 0.01s 0.01s -bash john pts/2 dev-db-server 23:04 0.00s 0.03s 0.00s w -h
  • 20.  $ w -u  23:22:06 up 29 days, 8:08, 3 users, load average: 0.00, 0.00, 0.00  USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT  ramesh pts/0 dev-db-server 22:57 17:47 2.52s 2.49s top  jason pts/1 dev-db-server 23:01 20:32 0.01s 0.01s -bash  john pts/2 dev-db-server 23:04 0.00s 0.03s 0.00s w -u  $ w -s  23:22:10 up 29 days, 8:08, 3 users, load average: 0.00, 0.00, 0.00  USER TTY FROM IDLE WHAT  ramesh pts/0 dev-db-server 17:51 sshd: ramesh [priv]  jason pts/1 dev-db-server 20:36 -bash  john pts/2 dev-db-server 1.00s w -s
  • 21. 2. Get the username and process of logged in user using who and users command who command is used to get the list of the usernames who are currently logged in. Output of the who command contains the following columns: user name, tty number, date and time, machine address. $ who ramesh pts/0 2009-03-28 22:57 (dev-db-server) jason pts/1 2009-03-28 23:01 (dev-db-server) john pts/2 2009-03-28 23:04 (dev-db-server)
  • 22.  To get a list of all usernames that are currently logged in, use the following:  $ who | cut -d' ' -f1 | sort | uniq  john  jason  Ramesh  Users Command  users command is used to print the user name who are all currently logged in the current host. It is one of the command don’t have any option other than help and version. If the user using, ‘n’ number of terminals, the user name will shown in ‘n’ number of time in the output.  $ users  john jason ramesh
  • 23. 3. Get the username you are currently logged in using whoami  whoami command is used to print the loggedin user name.  $ whoami  john   whoami command gives the same output as id -un as shown below:  $ id -un  john
  • 24. 4. Get the user login history at any time  last command will give login history for a specific username. If we don’t give any argument for this command, it will list login history for all users. By default this information will read from /var/log/wtmp file. The output of this command contains the following columns:  User name  Tty device number  Login date and time  Logout time  Total working time $ last jason jason pts/0 dev-db-server Fri Mar 27 22:57 still logged in jason pts/0 dev-db-server Fri Mar 27 22:09 - 22:54 (00:45) jason pts/0 dev-db-server Wed Mar 25 19:58 - 22:26 (02:28) jason pts/1 dev-db-server Mon Mar 16 20:10 - 21:44 (01:33) jason pts/0 192.168.201.11 Fri Mar 13 08:35 - 16:46 (08:11) jason pts/1 192.168.201.12 Thu Mar 12 09:03 - 09:19 (00:15) jason pts/0 dev-db-server Wed Mar 11 20:11 - 20:50 (00:39
  • 25. displaying its characteristics and setting characteristics.  stty command in Linux is used to change and print terminal line settings. Basically, this command shows or changes terminal characteristics.  Syntax:  stty [-F DEVICE | --file=DEVICE] [SETTING]...  stty [-F DEVICE | --file=DEVICE] [-a|--all]  stty [-F DEVICE | --file=DEVICE] [-g|--save]  Example: It will display the characteristics of the terminal
  • 26. stty –all: This option print all current settings in human- readable form. stty --all
  • 27.  stty -g: This option will print all current settings in a stty-readable form.  stty –g
  • 28.  stty -F : This option will open and use the specified DEVICE instead of stdin.  Example:  stty -F D/  stty –help : This option will display this help and exit.  stty –help
  • 29.  stty –version: This option will show the version information and exit.  stty --version
  • 30.  Terminal Characteristics  You can specify your terminal type to Unix if the default is not suitable. To do so in the C shell, enter the command:  set term= (termtype)  where termtype is the name of a terminal type supported on the system. VT100 and VT220 are acceptable terminal types for example. If you always use the same kind of terminal, you may want to put this command in your .login.
  • 31. Root login & su command  root is the username or account that by default has access to all commands and files on a Linux or other Unix-like operating system. It is also referred to as the root account, root user and the superuser su command The su command is use to change user ID or become super-user during a login session i.e. it allows you to become a super user or substitute user, spoof user, set user or switch user. Note: su only works if you know the target or root user’s password. su command syntax The syntax is: su - {user-name}
  • 32.  If invoked without a user-name, su defaults to becoming the super user. The user will be prompted for a password, if appropriate.  To log in as root user type the following command (you need to supply root user account password when prompted):  $ su –  su Command Options  To display a list of commands, enter the following:  su –h
  • 33.  Here are some common options to use with the su command:  Username – Replace username with the actual username you want to log in with. This can be any user, not just root.  –c or –command [command] – Runs a specific command as the specified user.  – or –l or –login [username] – Runs a login script to change to a specific username. You’ll need to enter a password for that user.  –s or –shell [shell] – Allows you to specify a different shell environment to run in.  –h or –help – Show the help file for the su command.  –p or ––preserve–environment – Preserve the shell environment (HOME, SHELL, USER, LOGNAME).
  • 34.  Switch to a Different User  To switch the logged-in user in this terminal window, enter the following:  su –l [other_user]  You’ll be asked for a password. Enter it, and the login will change to that user.  If you omit a username, it will default to the root account. Now, the logged-in user can run all system commands. This will also change the home directory and path to executable files.  Use the whoami command to verify you switched to a different user.
  • 35. The /etc/passwd and /etc/shadow files.  Users are accounts that can be used to login into a system.  Each user is identified by a unique identification number or UID by the system.  All the information of users in a system are stored in /etc/passwd file.  The hashed passwords for users are stored in /etc/shadow file.  When a new user is created, by default system takes following actions: 1. Assigns UID to the user. 2.Creates a home directory /home/. 3.Sets the default shell of the user to be /bin/sh. 4.Creates a private user group, named after the username itself. 5.Contents of /etc/skel are copied to the home directory of the new user. 6..bashrc, .bash_profile and .bash_logout are copied to the home directory of new user.These files provide environment variables for this user’s session.
  • 36. contents of /etc/passwd File  This file is readable by any user but only root as read and write permissions for it. This file consists of the following colon separated information about users in a system:  Username field  Password field  An `x` in this field denotes that the encrypted password is stored in the /etc/shadow file.  The user ID number (UID)  User’s group ID number (GID)  Additional information field such as the full name of the user or comment (GECOS)  Absolute path of user’s home directory  Login shell of the user
  • 38. contents of the /etc/shadow File  This file is readable and writable by only by root user. This file consists of the following colon separated information about password of users in a system:  User name field  Password field  Contains an encrypted password.  A blank entry, {:: }, indicates that a password is not required to login into that user’s account.  An asterisk, {:*:}, indicates the account has been disabled.  Last Password Change  This field denotes the number of days since the date of last password change counted since UNIX time (1-Jan-1970).  The minimum number of days after which the user can change his password.  Password validity
  • 39.  Denotes the number of days after which the password will expire.  Warning period  Denotes the number of days before the password expiry date, from which the user will start receiving warning notification for password change.  Account validity  Denotes the number of days after which the account will be disabled, once the password is expired.  Account disability  This field denotes the number of days since which the account had been disabled counted from UNIX time (1-Jan-1970).
  • 41. Commands to add, modify and delete users  Add a user  To add users, run the useradd command, like so:  sudo useradd -m <name of the user>  sudo useradd -m john  By default, useradd creates a user without creating a home directory. So, to make useradd create a home folder, we’ve used the -m switch.
  • 42.  Change Password of a User  Previously, when we created a new user, we’ve used the passwd command to assign a password to the new user. You can also use this to change passwords. If you want to change your own password, simply run:  Passwd  When you change your own password, it’ll ask you for your current password. Once you enter it correctly, you will be asked to enter your new password twice.
  • 43.  You can also use it to change a different by providing the username, although you need to be root to change passwords for others. The syntax for changing another user’s password is:  sudo passwd <username>  When you are the root user, passwd doesn’t ask you for your current password — it’ll just ask you for the new password.
  • 44.  Delete a User in Linux  To delete a user in Linux, you can use userdel command, like so:  sudo userdel <username>  By default, this command preserves the home directory and some other special files, such as the user’s list of cron jobs. If you want to delete these files as well, you should use the --remove-all-files flag.  For example, if you want to delete the user john along with the home directory of john, use the following command:  sudo userdel -r john
  • 45. References 1) https://www.d.umn.edu/~gshute/unix/unix.html 2) https://www.tutorialspoint.com/unix_commands/refer.htm 3) https://www.guru99.com/must-know-linux-commands.html 4) http://mally.stanford.edu/~sr/computing/basic-unix.html 5) https://www.unixtutorial.org/basic-unix-commands